QB Recursive fill
#1
Code:
RANDOMIZE TIMER
CONST xmax = 700
CONST ymax = 600
COMMON SHARED mixer
SCREEN _NEWIMAGE(xmax, ymax, 32)
_TITLE "RECURSIVE FILL TESTER by bplus"

xoff = (xmax - 512) / 2: yoff = (ymax - 512) / 2 + 20
seedSpacer = 16
WHILE 1
   seedColor& = _RGB(RND * 100 + 155, RND * 100 + 155, RND * 100 + 155)
   WHILE 1
       IF k$ = " " THEN
           EXIT WHILE
       ELSEIF k$ = "h" THEN
           seedSpacer = seedSpacer \ 2
           IF seedSpacer = 1 THEN seedSpacer = 2
       ELSEIF k$ = "d" THEN
           seedSpacer = seedSpacer * 2
           IF seedSpacer = 512 THEN seedSpacer = 256
       END IF
       CLS
       PRINT "            seed spacer:"; seedSpacer; "  seed color: "; seedColor&; "  Rnd mixer: "; mixer
       FOR y = 0 TO 512 STEP seedSpacer
           FOR x = 0 TO 512 STEP seedSpacer
               PSET (x + xoff, y + yoff), seedColor&
           NEXT
       NEXT
       mixer = RND * 10
       rfill 0 + xoff, 0 + yoff, 512 + xoff, 512 + yoff
       _DISPLAY
       LOCATE 3, 1
       INPUT " Seed spacer: h=half, d=double   seed color: spacebar to change,  enter next screen > ", k$
   WEND
WEND
SUB rfill (l, t, r, b)
   IF l < r - 2 AND t < b - 2 THEN
       mx = INT((r - l) / 2) + l: my = INT((b - t) / 2) + t
       pc& = INT((POINT(l, t) + POINT(r, t) + POINT(l, b) + POINT(r, b)) * mixer)
       IF _RED32(pc& / 255 < .25 THEN
           r% = 0
       ELSEIF _RED32(pc& / 255 < .5 THEN
           r% = 128
       ELSEIF _RED(pc& / 255 < .75 THEN
           r% = 192
       ELSE
           r% = 255
       END IF
       IF _GREEN32(pc& / 255 < .25 THEN
           g% = 0
       ELSEIF _GREEN32(pc& / 255 < .5 THEN
           g% = 128
       ELSEIF _GREEN32(pc& / 255 < .75 THEN
           g% = 192
       ELSE
           g% = 255
       END IF
       IF _BLUE32(pc& / 255 < .5 THEN
           b% = 0
       ELSEIF _BLUE32(pc& / 255 < .5 THEN
           b% = 128
       ELSEIF _BLUE32(pc& / 255 < .75 THEN
           b% = 192
       ELSE
           b% = 255
       END IF
       LINE (mx - 1, my - 1)-(mx + 1, my + 1), _RGB(r%, g%, b%), BF
       rfill l, t, mx, my
       rfill mx, t, r, my
       rfill l, my, mx, b
       rfill mx, my, r, b
   ELSE
       EXIT SUB
   END IF
END SUB

Took me awhile to figure out how to brighten up look. I really had to fiddle with color.


Attached Files Thumbnail(s)

B += x
Reply
#2
And some more screen shots...


Attached Files Thumbnail(s)

B += x
Reply
#3
Couple of 'typos' but easily fixed... '_RED(' missing the 32 and a few of the pc& were missing a ")"...

Other than that, the program ran really well... Very colourful indeed...

J
May your journey be free of incident.

Live long and prosper.
Reply
#4
PERSIAN CARPETS ON SALE NOW FOR $99.00 (US)!

NO TWO CARPETS THE SAME!

Get your unique Persian carpet while they last! Don't miss that perfect pattern!
Dedicated to empowering computer programming hobbyists, tinkerers, amateurs, and enthusiasts.
profile for Walter Whitman at Stack Overflow, Q&A for professional and enthusiast programmers


Reply
#5
(09-27-2017, 05:16 PM)johnno56 Wrote: Couple of 'typos' but easily fixed... '_RED(' missing the 32 and a few of the pc& were missing a ")"...

Other than that, the program ran really well... Very colourful indeed...

J

Like Persian carpets, this is a recursive quartering of squares unlike Persian carpets this draws a small box instead of a cross.


As far as typos go, yes the _RED is different from _RED32 but is there a difference between them?


The missing )'s is all on the editor here. QB64 wouldn't run the code if they were actually missing.
B += x
Reply
#6
Quote:As far as typos go, yes the _RED is different from _RED32 but is there a difference between them?

There's one real difference in the two:  RED32 *always* returns a color value from a 32-bit color value, whereas RED returns a color value based on the current screen _DEST (or _SOURCE, whichever it's based on...)

For example, give this a run:

SCREEN 0
PRINT _RED(4)
PRINT _RED32(4)

Result?

170
0

In Screen 0, 4 is red.  For a 32-bit color, 4 is &H00000004...  no alpha, no red, no green, and 4 blue...  It's almost completely transparent black!



So WHY do we have two different RED commands?

_RED is flexible and returns red values for EVERY screen mode --- but that makes it relatively slooow.
_RED32 *only* works for 32-bit color values --- but it's much, much, much faster!

As long as you're in a 32-bit screen, you should *ALWAYS* use _RGB32, _RED32, _GREEN32, _BLUE32, _ALPHA32.  It'll speed up your program considerably.

If you're in SCREEN 0, 12, 13, or a _NEWIMAGE(x, y, 256), then use _RGB, _RED, _GREEN, _BLUE, _ALPHA.  Otherwise, you're not going to get the results you want.  It's slower than _command32, but it tells the program to use the existing color palette with the color value you specify and only then return the proper result back to you.
Reply
#7
Thanks Steve!
B += x
Reply
#8
Cool... I leaned something new! Thank you, Steve. Big Grin

J
May your journey be free of incident.

Live long and prosper.
Reply