' 2017-12-29 another redesign of fireworks
' 2017-12-28 redesign fireworks
' now with lake refelction 2017-12-27 forget the bouncing sparks
' combine Welcome Plasma Font with landscape
'_title "Fireworks 3 translation to QB64 2017-12-26 bplus"
'fireworks 3.bas SmallBASIC 0.12.2 [B+=MGA] 2015-05-09
'fireworks 2.bas 2016-05-05 now with Gravity, Newtonian bounce, smoke debris
'fireworks 3.bas try with map variables make bursts around a central point
CONST waterline
= 600 ' 600 = ratio 5 to 1 sky to water ' raise and lower waterline as desired highest about 400?
CONST bluey
= 5 * 256 ^ 2 + 256 * 5 + 5
'prepare message font
mess$ = " Happy New Year 2018"
w
= 8 * LEN(mess$
): h
= 16 p(x, y) = 1
xo = 0: yo = 15: m = 7.2
resetPlasma
'prepare landscape
drawLandscape
'prepare fire works
nFW = 3
initFireWork (i)
'debris feild
DIM debris
(debrisMax
) AS debrisType
'OK start the show
'cls screen with land image
'draw fireworks
IF fw
(f
).age
<= fw
(f
).life
THEN drawfw
(f
) ELSE initFireWork f
'debris
PSET (debris
(i
).x
, debris
(i
).y
), debris
(i
).c
debris
(i
).x
= debris
(i
).x
+ RND * 3 - 1.5 debris
(i
).y
= debris
(i
).y
+ RND * 3.5 - 1.5 IF debris
(i
).x
< 0 OR debris
(i
).y
< 0 OR debris
(i
).x
> xmax
OR debris
(i
).y
> waterline
+ RND * 20 THEN NewDebris
(i
)
'text message in plasma
changePlasma
LINE (xo
+ x
* m
, yo
+ y
* m
)-(xo
+ x
* m
+ m
, yo
+ y
* m
+ m
), , BF
lc = lc + 1
'reflect sky
skyWaterRatio = waterline / (ymax - waterline) - .05
FOR y
= waterline
TO ymax
c&&
= POINT(x
, waterline
- ((y
- waterline
- 1) * skyWaterRatio
) + RND * 5) PSET (x
, y
+ 1), c&&
+ bluey
_LIMIT 200 'no limit needed on my system!
'accumulate debris
IF debrisStack
< debrisMax
THEN NewDebris i + debrisStack
debrisStack = debrisStack + 2
cN = cN + .01
COLOR _RGB(127 + 127 * SIN(pR!
* .3 * cN
), 127 + 127 * SIN(pG!
* .3 * cN
), 127 + 127 * SIN(pB!
* .3 * cN
))
'the sky
midInk 0, 0, 0, 78, 28, 68, i / ymax
'the land
startH = waterline - 80
rr = 10: gg = 20: bb = 15
Xright = 0
y = startH
' upDown = local up / down over range, change along Y
' range = how far up / down, along X
upDown
= (RND * .8 - .35) * (1 / (1 * mountain
)) range = Xright + rand&&(5, 35) * 2.5 / mountain
lastx = Xright - 1
y = y + upDown
LINE (lastx
, y
)-(X
, ymax
), , BF
'just lines weren't filling right lastx = X
Xright = range
rr = rand&&(rr + 5, rr): gg = rand&&(gg + 5, gg): bb = rand&&(bb + 4, bb)
startH = startH + rand&&(1, 10)
'LINE (0, waterline)-(xmax, ymax), _RGB32(0, 0, 0), BF
SUB midInk
(r1
, g1
, b1
, r2
, g2
, b2
, fr
) COLOR _RGB(r1
+ (r2
- r1
) * fr
, g1
+ (g2
- g1
) * fr
, b1
+ (b2
- b1
) * fr
)
rand&&
= INT(RND * (hi&&
- lo&&
+ 1)) + lo&&
'here's how to "save" a bunch of random numbers without data and arrays but tons of redundant calculations
RANDOMIZE USING fw
(i
).seed
'this repeats all random numbers generated by seed in same sequence 'recreate our firework from scratch!
red = rand&&(200, 255)
green = rand&&(200, 255)
blue = rand&&(200, 255)
x = rand&&(1, 4)
red = 0
green = 0
blue = 0
x = rand&&(1, 4)
red = 0: green = 0
green = 0: blue = 0
blue = 0: red = 0
ne = rand&&(80, 300)
embers
(e
, 0) = r
* COS(e
* _PI(2) / 101) embers
(e
, 1) = r
* SIN(e
* _PI(2) / 101) start = fw(i).age - lTail ' don't let tails get longer than lTail const
cx = fw(i).x: cy = fw(i).y: dx = embers(e, 0): dy = embers(e, 1)
cx = cx + dx
cy = cy + dy
'too much like a flower?
midInk 60, 60, 60, red, green, blue, (t - start) / lTail
'midInk 60, 60, 60, 128, 160, 150, (t - start) / lTail
fcirc cx, cy, (t - start) / lTail
dx = dx * .99 'air resitance
dy = dy + .01 'gravity
'COLOR _RGB32(red, green, blue)
cx = cx + dx: cy = cy + dy
fcirc cx, cy, (t - start) / lTail
fw(i).age = fw(i).age + 1
fw(i).x = rand&&(.1 * xmax, .9 * xmax)
fw(i).y = rand&&(.1 * ymax, .5 * ymax)
fw(i).seed = rand&&(0, 32000)
fw(i).age = 0
fw(i).life = rand&&(20, 120)
'Steve McNeil's copied from his forum note: Radius is too common a name
RadiusError = -subRadius
X = subRadius
Y = 0
' Draw the middle span here so we don't draw it twice in the main loop,
' which would be a problem with blending turned on.
LINE (CX
- X
, CY
)-(CX
+ X
, CY
), , BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), , BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), , BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
LINE (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), , BF
LINE (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), , BF