Welcome, Guest |
You have to register before you can post on our site.
|
Latest Threads |
лучшие песни медляки слуш...
Forum: Petr
Last Post: WillieTop
Yesterday, 02:21 AM
» Replies: 0
» Views: 18
|
пинк слушать онлайн беспл...
Forum: SMcNeill
Last Post: WillieTop
Yesterday, 02:20 AM
» Replies: 0
» Views: 16
|
скачать музыку российскую...
Forum: madscijr
Last Post: WillieTop
Yesterday, 02:18 AM
» Replies: 0
» Views: 15
|
нежная музыка mp3 скачать
Forum: Keybone
Last Post: WillieTop
Yesterday, 02:17 AM
» Replies: 0
» Views: 14
|
лучшая песня слушать онла...
Forum: bplus
Last Post: WillieTop
Yesterday, 02:16 AM
» Replies: 0
» Views: 16
|
пикник слушать онлайн луч...
Forum: Spriggsy
Last Post: WillieTop
Yesterday, 02:15 AM
» Replies: 0
» Views: 16
|
какая сейчас популярная м...
Forum: RhoSigma
Last Post: WillieTop
Yesterday, 02:14 AM
» Replies: 0
» Views: 15
|
хит лета 2019 музыка на т...
Forum: Christmas Code
Last Post: WillieTop
Yesterday, 02:12 AM
» Replies: 0
» Views: 19
|
бесплатная музыка mp3 рег...
Forum: Works in Progress
Last Post: WillieTop
Yesterday, 02:11 AM
» Replies: 0
» Views: 15
|
лучшие хиты музыка 2018 2...
Forum: Utilities
Last Post: WillieTop
Yesterday, 02:10 AM
» Replies: 0
» Views: 16
|
|
|
Keyword of the Day 45: _PIXELSIZE |
Posted by: SMcNeill - 01-03-2023, 01:37 PM - Forum: Keyword of the Day!
- Replies (1)
|
 |
_PIXELSIZE... A truly useful word for the people who might want to make various library routines, but not so much so, for everyone else.
What is it?: _Pixelsize is a simple little function which tells us how many bytes a pixel takes up in memory.
How do we use it?: We simply just call it like any other function. Something as simple as PS = _PixelSize will work just fine.
An example for people:
Code: (Select All) Screen 0
Print _PixelSize 'should print 0
Sleep
Screen 12
Print _PixelSize 'should print 1
Sleep
Screen _NewImage(640, 480, 32)
Print _PixelSize 'should print 4
Sleep
System
Run the code above and give it a try. You'll see that we start out in a text only screen, so _PixelSize reports 0 back to us -- there's no pixels in a text only screen! There's only columns and rows!
Hit any key and then we swap over to a SCREEN 12 screen. At this point, _PixelSize will report a value of 1 back to us. Each pixel on the screen takes up one byte of memory.
Hit another key and we swap over to a 32-bit screen. Now _PixelSize reports a value of 4 back to us. This is what everyone should expect as 32-bit screens are, by definition, 32-bits -- or 4-bytes -- in size. Each pixel has a single byte dedicated for Alpha, Red, Green, Blue color values, in a 32-bit screen.
... Which is all well and good, but not really all that useful in a single program. If you create your screens, you'll probably know what they are to begin with, and there's no need to use _PixelSize to get that value for you...
... Which is why I mentioned this is a gem of a command for anyone who works on making library style code. You never know when, who, or where your library routine might end up being called, and as such, you'll want to write it to work across various screen modes. (Or to at least trouble shoot and error check against certain screen modes.)
For example, let's say I write a PerfectBox routine which draws a lovely graphical box, puts a texture on the background for it, and a label, and it interacts with the mouse, and plays music when it's on the screen and highlighted, and does your taxes for you, and convinces your significant other to look the other way while you make out with the sexy neighbor down the hall or across the road...
If I wrote such an amazing piece of code, I'd probably want to write it up as a library function and save it for use in all my programs. Right? Heck, I'd probably even want to share it with all you guys so I could brag to the world (well, the world of QB64PE anyway) about what I'd accomplished, and let all of you bask in its glory as well!
And then old @Pete comes along and starts griping... "None of my programs work now, thanks to your stupid PerfectLibrary button!!"
So how do I fix that??
Code: (Select All) Sub PerfectButton (Parameters As HiddenByTrademark)
If _PixelSize = 0 Then
Print "Pete, this doesn't work in Screen 0! It's a graphical button!"
DeletePetesHardDrive
LaughAtPete
System
End If
....
'Rest of my PerfectButton Sub goes below here.
End Sub
Now, as you can see, we've error trapped for anyone using Screen 0 with our perfect button. Pete can now insert our PerfectButton routine into all his code, and not get generic error messages about invalid syntax and such when he attempts to run his code...
... Let's just hope nobody except Pete happens to try and use our PerfectButton routine on a text Screen... Our error handler may be a little more intense than most people approve of, in the example above...
|
|
|
while: wend |
Posted by: fistfullofnails - 01-03-2023, 06:09 AM - Forum: General Discussion
- Replies (24)
|
 |
On Terry Ritchie's function/subroutine part of the QB64 tutorial, line 15 of subs.base, we have:
Code: (Select All) WHILE _MOUSEINPUT: WEND
The only way I've seen "WHILE" and "WEND" used is at the start and end of a loop, with some instructions in between, which then ends with 'WEND".
I'm confused on what is exactly going on here. Can anyone explain like I'm a five year old?
Code: (Select All) DO
_LIMIT 60
WHILE _MOUSEINPUT: WEND
IF _MOUSEBUTTON(1) THEN DrawStar _MOUSEX, _MOUSEY
IF _MOUSEBUTTON(2) THEN Directions
_DISPLAY
LOOP UNTIL _KEYDOWN(27)
|
|
|
Red/Green/Blue/GrayScale images |
Posted by: SMcNeill - 01-02-2023, 08:18 PM - Forum: SMcNeill
- Replies (3)
|
 |
![[Image: Pandora.jpg]](https://i.ibb.co/2qWt97y/Pandora.jpg)
Code: (Select All) pic = _LoadImage("Pandora.jpg", 32)
Screen pic
Sleep
pic256 = Grayscale256(pic)
Screen pic256
Sleep
red256 = RedScale256(pic)
Screen red256
Sleep
green256 = GreenScale256(pic)
Screen green256
Sleep
blue256 = BlueScale256(pic)
Screen blue256
Sleep
Function Grayscale256 (image As Long)
Dim As Long d, s, temp, r, g, b
Dim As _MEM m(1): Dim As _Offset o(1), l
d = _Dest: s = _Source
m(0) = _MemImage(image): o(0) = m(0).OFFSET
temp = _NewImage(_Width(image), _Height(image), 256)
m(1) = _MemImage(temp): o(1) = m(1).OFFSET
_Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(i): Next: _Dest d
Do
r = _MemGet(m(0), o(0) + 1, _Unsigned _Byte): g = _MemGet(m(0), o(0) + 2, _Unsigned _Byte): b = _MemGet(m(0), o(0) + 3, _Unsigned _Byte)
_MemPut m(1), o(1), _RGB(r, g, b, temp) As _UNSIGNED _BYTE
o(0) = o(0) + 4: o(1) = o(1) + 1
Loop Until o(0) >= (m(0).OFFSET + m(0).SIZE)
Grayscale256 = temp
_MemFree m()
End Function
Function RedScale256 (image As Long)
Dim As Long d, s, temp: d = _Dest: temp = Grayscale256(image)
_Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(i, 0, 0): Next: _Dest d
RedScale256 = temp
End Function
Function GreenScale256 (image As Long)
Dim As Long d, s, temp: d = _Dest: temp = Grayscale256(image)
_Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(0, i, 0): Next: _Dest d
GreenScale256 = temp
End Function
Function BlueScale256 (image As Long)
Dim As Long d, s, temp: d = _Dest: temp = Grayscale256(image)
_Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(0, 0, i): Next: _Dest d
BlueScale256 = temp
End Function
|
|
|
Bilateral Kaleidoscope |
Posted by: bplus - 01-02-2023, 07:08 PM - Forum: Programs
- Replies (4)
|
 |
Looking at this: https://staging.qb64phoenix.com/showthread.php?tid=1306
I came up with this:
Code: (Select All) _Title "Bilateral Kaleidoscope" ' 2023-01-02 NOT like May 2022 version by b+
Const sh = 600, sw = 800
Screen _NewImage(sw, sh, 32)
'_ScreenMove 200, 100
_FullScreen
Randomize Timer
Do
If lc = 0 Then
dx1 = 0: dx2 = 0: dy1 = 0: dy2 = 0: dr = 0: dg = 0: db = 0
x1 = sw * Rnd: y1 = sh * Rnd: x2 = sw * Rnd: y2 = sh * Rnd: r = Rnd * 255: g = Rnd * 255: b = Rnd * 255
While dx1 = 0: dx1 = Rnd * 6 - 3: Wend
While dx2 = 0: dx2 = Rnd * 6 - 3: Wend
While dy1 = 0: dy1 = Rnd * 6 - 3: Wend
While dy2 = 0: dy2 = Rnd * 6 - 3: Wend
While dr = 0: dr = Rnd * 4 - 2: Wend
While dg = 0: dg = Rnd * 4 - 2: Wend
While db = 0: db = Rnd * 4 - 2: Wend
End If
Line (x1, y1)-(x2, y2), _RGB32(r, g, b, 100)
Line (sw - x1, y1)-(sw - x2, y2), _RGB32(r, g, b, 100)
Line (x1, sh - y1)-(x2, sh - y2), _RGB32(r, g, b, 100)
Line (sw - x1, sh - y1)-(sw - x2, sh - y2), _RGB32(r, g, b, 100)
x1 = Remainder(x1 + dx1, sw)
x2 = Remainder(x2 + dx2, sw)
y1 = Remainder(y1 + dy1, sh)
y2 = Remainder(y2 + dy2, sh)
r = Remainder(r + dr, 255)
g = Remainder(g + dr, 255)
b = Remainder(b + db, 255)
lc = lc + 1
If ((Rnd > .999) And (lc > 300)) Or (lc > 4000) Then Sleep 1: Cls: lc = 0
_Limit 60
Loop Until _KeyDown(27)
Function Remainder (n, d)
If d = 0 Then Exit Function
Remainder = n - (d) * Int(n / (d))
End Function
|
|
|
DAY 044: RESET |
Posted by: SMcNeill - 01-02-2023, 03:21 PM - Forum: Keyword of the Day!
- Replies (3)
|
 |
How many of you guys know this word even exists in our language? The command is RESET, but how many remember exactly WHAT it resets? Or what it's for?
This is one of those very important old keywords, that has basically became lost to time.
Keyword: RESET
Wiki page: https://qb64phoenix.com/qb64wiki/index.php/RESET
What's this do: It basically works as a superpowered CLOSE statement. Back in the day, when folks used floppy disks and such, it was necessary to use RESET to write your current directory info to the drive track. Before you ever exited a program, and pulled your floppy out of the drive, you'd issue a RESET command to close all files and update all drive information to the floppy.
Nowadays? Who owns a floppy drive? Would a modern OS even require this type of command to update that information, IF you happened to have a floppy drive connected?? I dunno!!
All this command does for us now, is basically just work as a CLOSE statement to close all files. It's unused. Obsoleted. Forgotten...
...Maybe I should've saved this keyword for Memorial Day.
RIP poor RESET.
|
|
|
File Menu Feature |
Posted by: eoredson - 01-02-2023, 05:02 AM - Forum: Help Me!
- Replies (4)
|
 |
I was thinking (again)..
In the Alt-F recent files list could someone add <delete> key to remove a file from the list without deleting the actual .bas program??
That way I don't have to check for broken links..
Erik.
|
|
|
|