-- title: fireworks test -- author: pixelbath -- desc: description -- script: lua t=0 color_fuse = {12,4} colors = { {3,2,1}, {7,6,5}, {11,10,9}, {15,14,13}, } seeds = {} -- 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() local delete_seeds = {} 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.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) -- 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(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 function TIC() 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() t=t+1 end -- -- 000:00000000ffffffff00000000ffffffff -- 001:0123456789abcdeffedcba9876543210 -- 002:0123456789abcdef0123456789abcdef -- -- -- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000 -- -- -- 000:1a1c2c610018da3038fa484ceec2612cce50108540083c2404366f042c79045dda1085fff4f4f42c0038690071a508b2 --