_TITLE "BodyTree Rework 2020-08" 'b+ 2020-08-14 'BodyTree recur fill.bas for SmallBASIC [B+=MGA] 2016-06-20
'copied and translated from body tree by PeterMaria
'2016-06-20 even more color mods including using triangle fills
' 2020-08-11 trans to QB64
' 2020-08-14 rework the recursive sub so can flex the body tree
CONST xmax
= 1200, ymax
= 700
limit = 14
ra
= _PI / -4 '45 degrees is standard angle for roof
'sky
'the hill for tree
ax0 = xmax / 2 - ymax / 10
ay0 = ymax - 40
bx0 = xmax / 2 + ymax / 10
level = 0
'hill
EllipseFill xmax
/ 2, ay0
, r
, .15 * r
, _RGB32(0, r
/ 5, 0) 'circle , .1, rgb(0, r / 5, 0) filled
'tree
BodyTree ax0, ay0, bx0, ay0, level
SUB BodyTree
(x1
, y1
, x2
, y2
, level
) 'dim shared ra = roof angle 0 to PI/4
pa
= _ATAN2(y2
- y1
, x2
- x1
) - _PI / 2 'perpendicular angle to base line 'build roof to square
mx = (x3 + x4) / 2
my = (y3 + y4) / 2
adj
= _HYPOT(x3
- mx
, y3
- my
) x5
= mx
+ raise
* COS(pa
) y5
= my
+ raise
* SIN(pa
)
'now that we have our drawing points draw our house
'LINE (x2, y2)-(x1, y1), &HFFFFFFFF 'house base
'LINE (x1, y1)-(x3, y3), &HFFFFFFFF ' left wall
'LINE (x3, y3)-(x5, y5), &HFFFFFFFF 'left peak
'LINE (x5, y5)-(x4, y4), &HFFFFFFFF ' right peak
'LINE (x4, y4)-(x2, y2), &HFFFFFFFF ' right wall completes house
k
= _RGB32((15 - level
) * 8, 64 + level
* 8, .25 * (15 - level
) * 12, 255 - level
* 18) ftri x1, y1, x2, y2, x3, y3, k
ftri x2, y2, x3, y3, x4, y4, k
ftri x3, y3, x4, y4, x5, y5, k
BodyTree x3, y3, x5, y5, level + 1
BodyTree x5, y5, x4, y4, level + 1
_BLEND a&
'<<<< new 2019-12-16 fix
' CX = center x coordinate
' CY = center y coordinate
' a = semimajor axis
' b = semiminor axis
' C = fill color
w2 = a * a
h2 = b * b
h2w2 = h2 * w2
LINE (CX
- a
, CY
)-(CX
+ a
, CY
), C
, BF
y = y + 1
x
= SQR((h2w2
- y
* y
* w2
) \ h2
) LINE (CX
- x
, CY
+ y
)-(CX
+ x
, CY
+ y
), C
, BF
LINE (CX
- x
, CY
- y
)-(CX
+ x
, CY
- y
), C
, BF