QB64 Phoenix Edition
DAY 015: PRESET - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: Official Links (https://qb64phoenix.com/forum/forumdisplay.php?fid=16)
+--- Forum: Learning Resources and Archives (https://qb64phoenix.com/forum/forumdisplay.php?fid=13)
+---- Forum: Keyword of the Day! (https://qb64phoenix.com/forum/forumdisplay.php?fid=49)
+---- Thread: DAY 015: PRESET (/showthread.php?tid=1157)



DAY 015: PRESET - SMcNeill - 11-20-2022

Everyone who knows graphics knows PSET.  Right?

Now, let's be honest -- How many of you guys think that PRESET is just a longhand version of PSET?  Same command, just with more typing!  After all, what's the difference between these two programs:

Code: (Select All)
$Color:32
Screen _NewImage(640, 480, 32)

For y = 0 To _Height
    For x = 0 To _Width
        If x Mod 10 < 5 Then
            If y Mod 10 < 5 Then PSet (x, y), Red Else PSet (x, y), Purple
        Else
            If y Mod 10 < 5 Then PSet (x, y), Gold Else PSet (x, y), Lime
        End If
    Next
Next

Sleep


And code 2:

Code: (Select All)
$Color:32
Screen _NewImage(640, 480, 32)

For y = 0 To _Height
    For x = 0 To _Width
        If x Mod 10 < 5 Then
            If y Mod 10 < 5 Then PReset (x, y), Red Else PReset (x, y), Purple
        Else
            If y Mod 10 < 5 Then PReset (x, y), Gold Else PReset (x, y), Lime
        End If
    Next
Next

Sleep


Stare at both those screens for a while -- try to focus one eye one each of them -- and see how long you can hold out before your brain melts.  That's got to be two of the most annoying tiling patterns possible for the human eyes to have to deal with...  Just looking at them, I somehow find them jarring and annoying.  

Yet, as annoying as those two tiling patterns are, they're exactly the same pattern.



So how the heck did PRESET behave any different at all from PSET?

Quick answer:  It didn't.  And for most folks, with the way they tend to code explicitly nowadays, it never will.



Most folks?  Code nowadays??  WTH is Steve talking about now??

Good question!

Today's modern coding practices have evolved quite a bit from back in the original days of computing.  Variable names are now long and descriptive, whereas in the past they were kept as short as possible to reduce memory usage.  Gotos are no longer in widespread use, as modern convention says to structure your programs better with DO..LOOPs and such.  Line numbers have faded from the wayside of coding practices...

...and so has the practice of writing code that relies implicitly upon previous settings.  For example:

Code: (Select All)
$Color:32
Screen _NewImage(640, 480, 32)

Color Pink

For y = 100 To 200
    For x = 100 To 200
        PSet (x, y)
    Next
Next

Sleep


Most modern programmers would set that PSET to become PSET (x, y), Pink, defining it explicitly in their code.  Old code used to use the style above, just to save a few bytes of memory when possible (not something we're so obsessed over with modern machines running 32GB+ of ram).  Don't specify a color -- just use the default color...

But, now that we have this older style in mind, let's take a look at PRESET:

Code: (Select All)
$Color:32
Screen _NewImage(640, 480, 32)

Cls , White
Color Pink

For y = 100 To 200
    For x = 100 To 200
        PReset (x, y)
    Next
Next

Sleep

If you notice, I cleared the whole screen white.  Specified my color to be Pink...  and somehow I drew a BLACK box??

WTH??  How'd that happen??

PSET, when no color is specified, defaults to your _DEFAULTCOLOR.   PRESET, when no color is specified, defaults to your _BACKGROUNDCOLOR.

Add a simple Print "Hello World" to the last program and see what you get -- pink text on a black background.

Black is the background color, and thus PRESET plots the points specified in black.

And that's the difference in the two commands in a nutshell:  PSET defaults to your primary color; PRESET defaults to your background color.  As long as you specify the color yourself, they both perform exactly the same.  It's only when no color is specified that you'll see the difference in the two commands.  Wink


RE: DAY 015: PRESET - bplus - 11-20-2022

Fun with Day 015 word:
Code: (Select All)
_Title "PSet or PReset" ' b+ 2022-11-20
Screen _NewImage(800, 600, 32)
_ScreenMove 200, 50
Do
    If lc Mod 200 = 0 Then
        lc = 0
        c1~& = _RGB32(Rnd * 200 + 55, Rnd * 255, Rnd * 255)
        Color , _RGB32(255 - _Red32(c1~&), 255 - _Blue32(c1~&), 255 - _Green32(c1~&))
        Cls
    End If
    box Rnd * _Width - 80, Rnd * _Height - 60, Rnd * 160 + 1, Rnd * 120 + 1, c1~&
    _Limit 10
    lc = lc + 1
Loop Until _KeyDown(27)

Sub box (x, y, w, h, c~&)
    For yy = y To y + h
        For xx = x To x + w
            If Point(xx, yy) = c~& Then PReset (xx, yy) Else PSet (xx, yy), c~&
        Next
    Next
End Sub



RE: DAY 015: PRESET - mnrvovrfc - 11-20-2022

This is something I had considered a side-effect but could be put to good use, to reduce the number of "COLOR" statements. When I started using GIMP, I was uncomfortable because "X" key has to be pressed to switch back and forth between "foreground" and "background" color, and I never liked its eraser. Only a few days ago that I used that program, the eraser worked like I think it should have; previously, it just ate all color leaving alpha channel alone.

I would have liked to know if old computers were as forgiving only about setting points in graphics although there was a tiny amount of memory available for it. The Radio Shack TRS-80 Color Computer, "SET" was the counterpart to "PSET" and held three parameters. But "RESET" (like "PRESET" in Q(uick)BASIC/QB64(PE)) was allowed only two parameters and always set dots to black color. No way around it until the Coco3 was devised and color attributes could be changed with "PALETTE". I'm not familiar with the Extended BASIC graphic modes offered on that computer which had a combination of statements to set up a screen. The "high-resolution" graphics of the Coco3 had statements to set and unset points that followed along that line. It had "HCIRCLE", "HLINE" and others that supported color attribute zero for background color, though.


RE: DAY 015: PRESET - PhilOfPerth - 11-20-2022

Thanks Steve, that clarified things for me.
I've never really thought deeply about these two, but got the idea that "pset" meant "set" or "turn on" a pixel, while "preset" meant "reset" or turn off a pixel. I guess this is a safe enough assumption for most cases, but it's good to be aware of what's really going on (or off).