QB64 Gold Wave
#1
And what do we find at the end of rainbows after graphing Shamrocks all week?

Compare _MAPTRIANGLE Method to fill a triangle to old fashioned Line Filled Method:
(Of course, I am last person to be doing a demo of_MAPTRIANGLE.)

Code:
_TITLE "Gold Wave bplus 2018-03-13"
'translated from SmallBASIC: Goldwave by johnno copied and mod by bplus 2018-01-28

'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
CONST xmax = 600
CONST ymax = 480
SCREEN _NEWIMAGE(xmax, ymax, 32)
_SCREENMOVE 360, 60
DIM ccc AS _UNSIGNED LONG


'                  compare fill triangle subs:  one uses very simple  _MAPTRIANGLE opt = 1
'                                               2nd uses primative line graphic0s  opt <> 1


opt = 1 ' << opt 1 uses _MAPTRIANGLE to fill triangles, any other uses line filled triangles
WHILE 1
   FOR t = 1 TO 60 STEP .1 '< changed
       CLS 'changed
       FOR y1 = 0 TO 24
           FOR x1 = 0 TO 24
               x = (12 * (24 - x1)) + (12 * y1)
               y = (-6 * (24 - x1)) + (6 * y1) + 300
               d = ((10 - x1) ^ 2 + (10 - y1) ^ 2) ^ .5
               h = 60 * SIN(x1 / 4 + t) + 65
               IF t > 10 AND t < 20 THEN h = 60 * SIN(y1 / 4 + t) + 65
               IF t > 20 AND t < 30 THEN h = 60 * SIN((x1 - y1) / 4 + t) + 65
               IF t > 30 AND t < 40 THEN h = 30 * SIN(x1 / 2 + t) + 30 * SIN(y1 / 2 + t) + 65
               IF t > 40 AND t < 50 THEN h = 60 * SIN((x1 + y1) / 4 + t) + 65
               IF t > 50 AND t < 60 THEN h = 60 * SIN(d * .3 + t) + 65
               IF opt = 1 THEN
                   'TOP
                   ccc = _RGB32(242 + .1 * h, 242 + .1 * h, h)
                   filltri x, y - h, x + 10, y + 5 - h, x + 20, y - h, ccc
                   filltri x, y - h, x + 10, y - 5 - h, x + 20, y - h, ccc
                   'FRONT-LEFT
                   ccc = _RGB(255, 80, 0)
                   filltri x, y - h, x + 10, y + 5 - h, x + 10, y, ccc
                   filltri x, y - h, x, y - 5, x + 10, y, ccc
                   'FRONT-RIGHT
                   ccc = _RGB32(255, 150, 0)
                   filltri x + 10, y + 5 - h, x + 10, y, x + 20, y - 5, ccc
                   filltri x + 10, y + 5 - h, x + 20, y - h, x + 20, y - 5, ccc
               ELSE
                   COLOR _RGB32(242 + .1 * h, 242 + .1 * h, h)
                   filltri2 x, y - h, x + 10, y + 5 - h, x + 20, y - h
                   filltri2 x, y - h, x + 10, y - 5 - h, x + 20, y - h
                   'FRONT-LEFT
                   COLOR _RGB32(255, 80, 0)
                   filltri2 x, y - h, x + 10, y + 5 - h, x + 10, y
                   filltri2 x, y - h, x, y - 5, x + 10, y
                   COLOR _RGB32(255, 150, 0)
                   filltri2 x + 10, y + 5 - h, x + 10, y, x + 20, y - 5
                   filltri2 x + 10, y + 5 - h, x + 20, y - h, x + 20, y - 5
               END IF

               IF INKEY$ = CHR$(27) THEN END
           NEXT
       NEXT
       _DISPLAY
       _LIMIT 200
   NEXT
WEND

'Andy Amaya's modified FillTriangle
SUB filltri2 (xx1, yy1, xx2, yy2, xx3, yy3)
   'make copies before swapping
   x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2: x3 = xx3: y3 = yy3
   'thanks Andy Amaya!
   'triangle coordinates must be ordered: where x1 < x2 < x3
   IF x2 < x1 THEN SWAP x1, x2: SWAP y1, y2
   IF x3 < x1 THEN SWAP x1, x3: SWAP y1, y3
   IF x3 < x2 THEN SWAP x2, x3: SWAP y2, y3
   IF x1 <> x3 THEN slope1 = (y3 - y1) / (x3 - x1)

   'draw the first half of the triangle
   length = x2 - x1
   IF length <> 0 THEN
       slope2 = (y2 - y1) / (x2 - x1)
       FOR x = 0 TO length
           LINE (INT(x + x1), INT(x * slope1 + y1))-(INT(x + x1), INT(x * slope2 + y1))
           'lastx2% = lastx%
           lastx% = INT(x + x1)
       NEXT
   END IF

   'draw the second half of the triangle
   y = length * slope1 + y1: length = x3 - x2
   IF length <> 0 THEN
       slope3 = (y3 - y2) / (x3 - x2)
       FOR x = 0 TO length
           'IF INT(x + x2) <> lastx% AND INT(x + x2) <> lastx2% THEN  'works! but need 2nd? check
           IF INT(x + x2) <> lastx% THEN
               LINE (INT(x + x2), INT(x * slope1 + y))-(INT(x + x2), INT(x * slope3 + y2))
           END IF
       NEXT
   END IF
END SUB

' found at QB64.net:    http://www.qb64.net/forum/index.php?topic=14425.0
SUB filltri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
   a = _NEWIMAGE(1, 1, 32)
   _DEST a
   PSET (0, 0), K
   _DEST 0
   _MAPTRIANGLE (0, 0)-(0, 0)-(0, 0), a TO(x1, y1)-(x2, y2)-(x3, y3)
   _FREEIMAGE a '<<< this is important!
END SUB


Attached Files Thumbnail(s)

B += x
Reply