Post by johnno56 on Aug 13, 2020 19:50:57 GMT -6
Ok. It's not a 'complete' firework. Just the explosion bit. Particles demo...
Use a higher number of particles and observe how each particle 'dies'... Perhaps another attribute can be added to determine the 'lifespan' of each particle. That should produce a more 'natural' formation?
Can you think of any other 'attributes' a firework could have?
Experiment. Have fun. Share your results...
xmax = 640
ymax = 480
title$ = "Single Firework - ESC to Quit"
WindowOpen(1,title$,windowpos_centered,windowpos_centered,xmax,ymax,0)
CanvasOpen(1,xmax,ymax,0,0,xmax,ymax,0)
hidemouse()
randomize(timer)
clearcanvas
' Start position of particles
x = 320
y = 100
' Number of particles and attributes
particles = 128
attributes = 5
'
' Dots array:
' Number of particles
' Attribute 1 - Xpos of particle
' Attribute 2 - Ypos of particle
' Attribute 3 - Cosine angle of particle
' Attribute 4 - Sine angle of particle
' Attribute 5 - Speed of particle
'
Dim dots[particles, attributes]
for i = 0 to particles - 1
' All dots start at position x, y
dots[i, 0] = x
dots[i, 1] = y
' Create a random angle and direction of dot
' to (cos(angle) sin(angle))
angle = rand(360)
dots[i, 2] = cos(angle)
dots[i, 3] = sin(angle)
' Set speed of dot to range 0.5 to 6.0
dots[i, 4] = (50 + rand(570)) / 100
next
wait(500)
while key(k_escape) = 0
clearcanvas
' Randon colours - Matter of choice
setColor(rgb(64 + rand(192), 64 + rand(192), 64 + rand(192)))
' Update and draw dots
for i = 0 to particles - 1
' Dot is only active if its speed is greater than zero
if dots[i, 4] > 0 then
' xpos = xpos + sin(angle) * speed
dots[i, 0] = dots[i, 0] + dots[i, 2] * dots[i, 4]
' ypos = ypos + cos(angle) * speed
dots[i, 1] = dots[i, 1] + dots[i, 3] * dots[i, 4]
' decrease the dot speed (maybe 0.04 to 0.1)
dots[i, 4] = dots[i, 4] - 0.06
' Draw the dots - Pixels, Circles or Squares....
' PSet(int(dots[i, 0]), int(dots[i, 1]))
CircleFill(int(dots[i, 0]), int(dots[i, 1]), 2)
' RectFill(int(dots[i, 0]), int(dots[i, 1]), 2, 2)
' Add a little downward momentum
' ypos = ypos + 3
dots[i, 1] = dots[i, 1] + 3
end if
next
update()
wend
Use a higher number of particles and observe how each particle 'dies'... Perhaps another attribute can be added to determine the 'lifespan' of each particle. That should produce a more 'natural' formation?
Can you think of any other 'attributes' a firework could have?
Experiment. Have fun. Share your results...