fireworks.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. -- title: fireworks test
  2. -- author: pixelbath
  3. -- desc: description
  4. -- script: lua
  5. t=0
  6. color_fuse = {12,4}
  7. colors = {
  8. {3,2,1},
  9. {7,6,5},
  10. {11,10,9},
  11. {15,14,13},
  12. }
  13. seeds = {}
  14. -- basic todo:
  15. -- seed
  16. -- spark trail
  17. -- timed fuse
  18. -- velocity x/y
  19. -- explosion shape
  20. -- children (stars):
  21. -- x, y, vel_x, vel_y, color, has_trails, life,
  22. -- types:
  23. -- willow - each star trails particles with low inertia
  24. -- grains of wheat / candles - shooting upward, possibly at angles
  25. -- rainbow chrysanthemums - red/white/blue spherical burst, ends with trail of sparks
  26. -- orange peony - similar to mums, but no trail of sparks
  27. -- peacock feather / dragonfly - lots of blue/orange with long tails
  28. -- green bees - spherical burst, curving trajectories with long green tails
  29. -- crossette - multiple large stars that burst into smaller stars with a loud crackling
  30. -- falling leaves - stars twinkle and flutter down
  31. function create_star(xpos, ypos, xvel, yvel, color)
  32. local star_color = color or math.random(3)+1
  33. local new_star = {
  34. vel_x = xvel,
  35. vel_y = yvel,
  36. color = star_color,
  37. x = xpos, y = ypos,
  38. num_children = 0,
  39. t = 0, det = 200,
  40. shape = nil,
  41. is_seed = false,
  42. }
  43. return new_star
  44. end
  45. function fireworks_update()
  46. local delete_seeds = {}
  47. for i = 1, #seeds do
  48. local this_seed = seeds[i]
  49. -- friction and gravity
  50. this_seed.vel_y = this_seed.vel_y + 0.012
  51. this_seed.x = this_seed.x + (this_seed.vel_x * 0.9)
  52. this_seed.y = this_seed.y + (this_seed.vel_y * 0.9)
  53. pix(this_seed.x, this_seed.y, this_seed.color)
  54. -- print(this_seed.t..','..this_seed.det, this_seed.x + 2, this_seed.y, this_seed.color, false, 1, true)
  55. -- ways to remove particles
  56. if this_seed.y > 136 then
  57. table.insert(delete_seeds, i)
  58. end
  59. if this_seed.det > 0 and this_seed.t > this_seed.det then
  60. spawn_explosion(this_seed)
  61. table.insert(delete_seeds, i)
  62. end
  63. if this_seed.is_seed then
  64. if this_seed.vel_y > -0.1 and math.random() > 10 * math.abs(this_seed.vel_y) then
  65. spawn_explosion(this_seed)
  66. table.insert(delete_seeds, i)
  67. end
  68. end
  69. this_seed.t = this_seed.t + 1
  70. end
  71. for i = #delete_seeds, 1, -1 do
  72. table.remove(seeds, delete_seeds[i])
  73. end
  74. end
  75. function spawn_explosion(star)
  76. if star.num_children == 0 then return end
  77. if star.shape == nil then star.shape = 'peony' end
  78. if star.shape == 'peony' then
  79. local angle = 2 * math.pi / star.num_children
  80. for i = 1, star.num_children do
  81. local xvel = math.cos(angle * i) * ((math.random() * 0.5) + 0.3)
  82. local yvel = math.sin(angle * i) * ((math.random() * 0.5) + 0.3)
  83. local child_star = create_star(star.x, star.y, xvel, yvel, star.color)
  84. child_star.det = math.random() * 30 + 50
  85. table.insert(seeds, child_star)
  86. end
  87. end
  88. end
  89. function TIC()
  90. if btnp(4) then
  91. local seed_yvel = -1 + (math.random() * -1)
  92. local seed = create_star(math.random(240), 136, 0, seed_yvel)
  93. seed.shape = 'peony'
  94. seed.num_children = 100
  95. seed.is_seed = true
  96. table.insert(seeds, seed)
  97. end
  98. cls(0)
  99. fireworks_update()
  100. t=t+1
  101. end
  102. -- <WAVES>
  103. -- 000:00000000ffffffff00000000ffffffff
  104. -- 001:0123456789abcdeffedcba9876543210
  105. -- 002:0123456789abcdef0123456789abcdef
  106. -- </WAVES>
  107. -- <SFX>
  108. -- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000
  109. -- </SFX>
  110. -- <PALETTE>
  111. -- 000:1a1c2c610018da3038fa484ceec2612cce50108540083c2404366f042c79045dda1085fff4f4f42c0038690071a508b2
  112. -- </PALETTE>