|
@@ -14,13 +14,39 @@ colors = {
|
|
|
|
|
|
seeds = {}
|
|
|
|
|
|
-function add_firework_seed(xpos)
|
|
|
- table.insert(seeds, {
|
|
|
- vel_y = -1 + (math.random() * -1),
|
|
|
- startx = math.random(240),
|
|
|
- color = math.random(3)+1,
|
|
|
- x = xpos, y = 136,
|
|
|
- })
|
|
|
+-- basic todo:
|
|
|
+
|
|
|
+-- seed
|
|
|
+-- spark trail
|
|
|
+-- timed fuse
|
|
|
+-- velocity x/y
|
|
|
+-- explosion shape
|
|
|
+-- children (stars):
|
|
|
+-- x, y, vel_x, vel_y, color, has_trails, life,
|
|
|
+
|
|
|
+-- types:
|
|
|
+-- willow - each star trails particles with low inertia
|
|
|
+-- grains of wheat / candles - shooting upward, possibly at angles
|
|
|
+-- rainbow chrysanthemums - red/white/blue spherical burst, ends with trail of sparks
|
|
|
+-- orange peony - similar to mums, but no trail of sparks
|
|
|
+-- peacock feather / dragonfly - lots of blue/orange with long tails
|
|
|
+-- green bees - spherical burst, curving trajectories with long green tails
|
|
|
+-- crossette - multiple large stars that burst into smaller stars with a loud crackling
|
|
|
+-- falling leaves - stars twinkle and flutter down
|
|
|
+
|
|
|
+function create_star(xpos, ypos, xvel, yvel, color)
|
|
|
+ local star_color = color or math.random(3)+1
|
|
|
+ local new_star = {
|
|
|
+ vel_x = xvel,
|
|
|
+ vel_y = yvel,
|
|
|
+ color = star_color,
|
|
|
+ x = xpos, y = ypos,
|
|
|
+ num_children = 0,
|
|
|
+ t = 0, det = 200,
|
|
|
+ shape = nil,
|
|
|
+ is_seed = false,
|
|
|
+ }
|
|
|
+ return new_star
|
|
|
end
|
|
|
|
|
|
function fireworks_update()
|
|
@@ -28,36 +54,61 @@ function fireworks_update()
|
|
|
for i = 1, #seeds do
|
|
|
local this_seed = seeds[i]
|
|
|
|
|
|
+ -- friction and gravity
|
|
|
this_seed.vel_y = this_seed.vel_y + 0.012
|
|
|
- this_seed.y = this_seed.y + this_seed.vel_y
|
|
|
+ this_seed.x = this_seed.x + (this_seed.vel_x * 0.9)
|
|
|
+ this_seed.y = this_seed.y + (this_seed.vel_y * 0.9)
|
|
|
|
|
|
pix(this_seed.x, this_seed.y, this_seed.color)
|
|
|
+ -- print(this_seed.t..','..this_seed.det, this_seed.x + 2, this_seed.y, this_seed.color, false, 1, true)
|
|
|
|
|
|
- -- reaching the apex
|
|
|
- if this_seed.vel_y > -0.1 then
|
|
|
- if math.random() > 10 * math.abs(this_seed.vel_y) then
|
|
|
- spawn_explosion(this_seed.x, this_seed.y, this_seed.color)
|
|
|
+ -- ways to remove particles
|
|
|
+ if this_seed.y > 136 then
|
|
|
+ table.insert(delete_seeds, i)
|
|
|
+ end
|
|
|
+ if this_seed.det > 0 and this_seed.t > this_seed.det then
|
|
|
+ spawn_explosion(this_seed)
|
|
|
+ table.insert(delete_seeds, i)
|
|
|
+ end
|
|
|
+ if this_seed.is_seed then
|
|
|
+ if this_seed.vel_y > -0.1 and math.random() > 10 * math.abs(this_seed.vel_y) then
|
|
|
+ spawn_explosion(this_seed)
|
|
|
table.insert(delete_seeds, i)
|
|
|
end
|
|
|
end
|
|
|
+
|
|
|
+ this_seed.t = this_seed.t + 1
|
|
|
end
|
|
|
for i = #delete_seeds, 1, -1 do
|
|
|
table.remove(seeds, delete_seeds[i])
|
|
|
end
|
|
|
end
|
|
|
|
|
|
-function spawn_explosion(xpos, ypos, color)
|
|
|
-
|
|
|
+function spawn_explosion(star)
|
|
|
+ if star.num_children == 0 then return end
|
|
|
+ if star.shape == nil then star.shape = 'peony' end
|
|
|
+
|
|
|
+ if star.shape == 'peony' then
|
|
|
+ local angle = 2 * math.pi / star.num_children
|
|
|
+ for i = 1, star.num_children do
|
|
|
+ local xvel = math.cos(angle * i) * ((math.random() * 0.5) + 0.3)
|
|
|
+ local yvel = math.sin(angle * i) * ((math.random() * 0.5) + 0.3)
|
|
|
+ local child_star = create_star(star.x, star.y, xvel, yvel, star.color)
|
|
|
+ child_star.det = math.random() * 30 + 50
|
|
|
+ table.insert(seeds, child_star)
|
|
|
+ end
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
-add_firework_seed(50)
|
|
|
-
|
|
|
function TIC()
|
|
|
-
|
|
|
- if btn(0) then y=y-1 end
|
|
|
- if btn(1) then y=y+1 end
|
|
|
- if btn(2) then x=x-1 end
|
|
|
- if btn(3) then x=x+1 end
|
|
|
+ if btnp(4) then
|
|
|
+ local seed_yvel = -1 + (math.random() * -1)
|
|
|
+ local seed = create_star(math.random(240), 136, 0, seed_yvel)
|
|
|
+ seed.shape = 'peony'
|
|
|
+ seed.num_children = 100
|
|
|
+ seed.is_seed = true
|
|
|
+ table.insert(seeds, seed)
|
|
|
+ end
|
|
|
|
|
|
cls(0)
|
|
|
fireworks_update()
|