DAY 015: PRESET
#1
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
Reply


Messages In This Thread
DAY 015: PRESET - by SMcNeill - 11-20-2022, 03:42 PM
RE: DAY 015: PRESET - by bplus - 11-20-2022, 05:54 PM
RE: DAY 015: PRESET - by mnrvovrfc - 11-20-2022, 08:45 PM
RE: DAY 015: PRESET - by PhilOfPerth - 11-20-2022, 10:51 PM



Users browsing this thread: 1 Guest(s)