Author Topic: Fireworks  (Read 4429 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Fireworks
« on: August 08, 2019, 06:09:08 pm »
For ages, maybe the 80's, I've played around with making fireworks or other types of graphics shows on BASIC. But today I think I've made my best. You will probably say I made too many variables  but it's no big deal, especially with today's computers. In fact, there's a little over 175 variables. LOL Most of them are used for each spark per explosion. There's 24 sparks per explosion on most of them. I won't give away the ending, but there's some surprises. :) Tell me what you think, thanks. Oh, and I took someone's advice from this forum awhile back when they told me that I only needed 1 RANDOMIZE TIMER, so I put 1 in every set of different kinds of  variables and it works great! Thank you!

The show lasts around 3 minutes total. Or you can press Esc anytime to end.

(Note: One with a welcome screen that says the length of the show and the ability to use Esc, is after this post.)

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.  
  3. 'Start Loop Here
  4. go:
  5. a$ = INKEY$
  6. IF a$ = CHR$(27) THEN END
  7. x2 = INT(RND * 780) + 10
  8. y2 = INT(RND * 580) + 10
  9.  
  10. SOUND 100, .5
  11. SOUND 100, .5
  12. SOUND 100, .5
  13. SOUND 100, .5
  14.  
  15. dxx = (RND * 6) + -3
  16. dyy = (RND * 6) + -3
  17. dxx2 = (RND * 6) + -3
  18. dyy2 = (RND * 6) + -3
  19. dxx3 = (RND * 6) + -3
  20. dyy3 = (RND * 6) + -3
  21. dxx4 = (RND * 6) + -3
  22. dyy4 = (RND * 6) + -3
  23. dxx5 = (RND * 6) + -3
  24. dyy5 = (RND * 6) + -3
  25. dxx6 = (RND * 6) + -3
  26. dyy6 = (RND * 6) + -3
  27. dxx7 = (RND * 6) + -3
  28. dyy7 = (RND * 6) + -3
  29. dxx8 = (RND * 6) + -3
  30. dyy8 = (RND * 6) + -3
  31. dxx9 = (RND * 6) + -3
  32. dyy9 = (RND * 6) + -3
  33. dxx10 = (RND * 6) + -3
  34. dyy10 = (RND * 6) + -3
  35. dxx11 = (RND * 6) + -3
  36. dyy11 = (RND * 6) + -3
  37. dxx12 = (RND * 6) + -3
  38. dyy12 = (RND * 6) + -3
  39. dxx13 = (RND * 6) + -3
  40. dyy13 = (RND * 6) + -3
  41. dxx14 = (RND * 6) + -3
  42. dyy14 = (RND * 6) + -3
  43. dxx15 = (RND * 6) + -3
  44. dyy15 = (RND * 6) + -3
  45. dxx16 = (RND * 6) + -3
  46. dyy16 = (RND * 6) + -3
  47. dxx17 = (RND * 6) + -3
  48. dyy17 = (RND * 6) + -3
  49. dxx18 = (RND * 6) + -3
  50. dyy18 = (RND * 6) + -3
  51. dxx19 = (RND * 6) + -3
  52. dyy19 = (RND * 6) + -3
  53. dxx20 = (RND * 6) + -3
  54. dyy20 = (RND * 6) + -3
  55. dxx21 = (RND * 6) + -3
  56. dyy21 = (RND * 6) + -3
  57. dxx22 = (RND * 6) + -3
  58. dyy22 = (RND * 6) + -3
  59. dxx23 = (RND * 6) + -3
  60. dyy23 = (RND * 6) + -3
  61. dxx24 = (RND * 6) + -3
  62. dyy24 = (RND * 6) + -3
  63.  
  64. c1 = INT(RND * 200) + 55
  65. c2 = INT(RND * 200) + 55
  66. c3 = INT(RND * 200) + 55
  67. c4 = INT(RND * 200) + 55
  68. c5 = INT(RND * 200) + 55
  69. c6 = INT(RND * 200) + 55
  70. c7 = INT(RND * 200) + 55
  71. c8 = INT(RND * 200) + 55
  72. c9 = INT(RND * 200) + 55
  73. c10 = INT(RND * 200) + 55
  74. c11 = INT(RND * 200) + 55
  75. c12 = INT(RND * 200) + 55
  76. c13 = INT(RND * 200) + 55
  77. c14 = INT(RND * 200) + 55
  78. c15 = INT(RND * 200) + 55
  79. c16 = INT(RND * 200) + 55
  80. c17 = INT(RND * 200) + 55
  81. c18 = INT(RND * 200) + 55
  82. c19 = INT(RND * 200) + 55
  83. c20 = INT(RND * 200) + 55
  84. c21 = INT(RND * 200) + 55
  85. c22 = INT(RND * 200) + 55
  86. c23 = INT(RND * 200) + 55
  87. c24 = INT(RND * 200) + 55
  88. c25 = INT(RND * 200) + 55
  89. c26 = INT(RND * 200) + 55
  90. c27 = INT(RND * 200) + 55
  91. c28 = INT(RND * 200) + 55
  92. c29 = INT(RND * 200) + 55
  93. c30 = INT(RND * 200) + 55
  94. c31 = INT(RND * 200) + 55
  95. c32 = INT(RND * 200) + 55
  96. c33 = INT(RND * 200) + 55
  97. c34 = INT(RND * 200) + 55
  98. c35 = INT(RND * 200) + 55
  99. c36 = INT(RND * 200) + 55
  100. c37 = INT(RND * 200) + 55
  101. c38 = INT(RND * 200) + 55
  102. c39 = INT(RND * 200) + 55
  103. c40 = INT(RND * 200) + 55
  104. c41 = INT(RND * 200) + 55
  105. c42 = INT(RND * 200) + 55
  106. c43 = INT(RND * 200) + 55
  107. c44 = INT(RND * 200) + 55
  108. c45 = INT(RND * 200) + 55
  109. c46 = INT(RND * 200) + 55
  110. c47 = INT(RND * 200) + 55
  111. c48 = INT(RND * 200) + 55
  112. c49 = INT(RND * 200) + 55
  113. c50 = INT(RND * 200) + 55
  114. c51 = INT(RND * 200) + 55
  115. c52 = INT(RND * 200) + 55
  116. c53 = INT(RND * 200) + 55
  117. c54 = INT(RND * 200) + 55
  118. c55 = INT(RND * 200) + 55
  119. c56 = INT(RND * 200) + 55
  120. c57 = INT(RND * 200) + 55
  121. c58 = INT(RND * 200) + 55
  122. c59 = INT(RND * 200) + 55
  123. c60 = INT(RND * 200) + 55
  124. c61 = INT(RND * 200) + 55
  125. c62 = INT(RND * 200) + 55
  126. c63 = INT(RND * 200) + 55
  127. c64 = INT(RND * 200) + 55
  128. c65 = INT(RND * 200) + 55
  129. c66 = INT(RND * 200) + 55
  130. c67 = INT(RND * 200) + 55
  131. c68 = INT(RND * 200) + 55
  132. c69 = INT(RND * 200) + 55
  133. c70 = INT(RND * 200) + 55
  134. c71 = INT(RND * 200) + 55
  135. c72 = INT(RND * 200) + 55
  136.  
  137.  
  138.  
  139. explosion:
  140. dd = dd + 1
  141. dxx = dxx + dxx / 4
  142. dxx2 = dxx2 + dxx2 / 4
  143. dxx3 = dxx3 + dxx3 / 4
  144. dxx4 = dxx4 + dxx4 / 4
  145. dxx5 = dxx5 + dxx5 / 4
  146. dxx6 = dxx6 + dxx6 / 4
  147. dyy = dyy + dyy / 4
  148. dyy2 = dyy2 + dyy2 / 4
  149. dyy3 = dyy3 + dyy3 / 4
  150. dyy4 = dyy4 + dyy4 / 4
  151. dyy5 = dyy5 + dyy5 / 4
  152. dyy6 = dyy6 + dyy6 / 4
  153.  
  154. dxx7 = dxx7 + dxx7 / 4
  155. dxx8 = dxx8 + dxx8 / 4
  156. dxx9 = dxx9 + dxx9 / 4
  157. dxx10 = dxx10 + dxx10 / 4
  158. dxx11 = dxx11 + dxx11 / 4
  159. dxx12 = dxx12 + dxx12 / 4
  160. dyy7 = dyy7 + dyy7 / 4
  161. dyy8 = dyy8 + dyy8 / 4
  162. dyy9 = dyy9 + dyy9 / 4
  163. dyy10 = dyy10 + dyy10 / 4
  164. dyy11 = dyy11 + dyy11 / 4
  165. dyy12 = dyy12 + dyy12 / 4
  166.  
  167.  
  168. dxx13 = dxx13 + dxx13 / 4
  169. dxx14 = dxx14 + dxx14 / 4
  170. dxx15 = dxx15 + dxx15 / 4
  171. dxx16 = dxx16 + dxx16 / 4
  172. dxx17 = dxx17 + dxx17 / 4
  173. dxx18 = dxx18 + dxx18 / 4
  174. dyy13 = dyy13 + dyy13 / 4
  175. dyy14 = dyy14 + dyy14 / 4
  176. dyy15 = dyy15 + dyy15 / 4
  177. dyy16 = dyy16 + dyy16 / 4
  178. dyy17 = dyy17 + dyy17 / 4
  179. dyy18 = dyy18 + dyy18 / 4
  180.  
  181. dxx19 = dxx19 + dxx19 / 4
  182. dxx20 = dxx20 + dxx20 / 4
  183. dxx21 = dxx21 + dxx21 / 4
  184. dxx22 = dxx22 + dxx22 / 4
  185. dxx23 = dxx23 + dxx23 / 4
  186. dxx24 = dxx24 + dxx24 / 4
  187. dyy19 = dyy19 + dyy19 / 4
  188. dyy20 = dyy20 + dyy20 / 4
  189. dyy21 = dyy21 + dyy21 / 4
  190. dyy22 = dyy22 + dyy22 / 4
  191. dyy23 = dyy23 + dyy23 / 4
  192. dyy24 = dyy24 + dyy24 / 4
  193.  
  194.  
  195. FOR c = .25 TO 2 STEP .25
  196.     CIRCLE (x2 + dxx, y2 + dyy), c, _RGB32(c1, c2, c3)
  197.     CIRCLE (x2 + dxx2, y2 + dyy2), c, _RGB32(c4, c5, c6)
  198.     CIRCLE (x2 + dxx3, y2 + dyy3), c, _RGB32(c7, c8, c9)
  199.     CIRCLE (x2 + dxx4, y2 + dyy4), c, _RGB32(c10, c11, c12)
  200.  
  201.     CIRCLE (x2 + dxx5, y2 + dyy5), c, _RGB32(c13, c14, c15)
  202.     CIRCLE (x2 + dxx6, y2 + dyy6), c, _RGB32(c16, c17, c18)
  203.     CIRCLE (x2 + dxx7, y2 + dyy7), c, _RGB32(c19, c20, c21)
  204.     CIRCLE (x2 + dxx8, y2 + dyy8), c, _RGB32(c22, c23, c24)
  205.  
  206.     CIRCLE (x2 + dxx9, y2 + dyy9), c, _RGB32(c25, c26, c27)
  207.     CIRCLE (x2 + dxx10, y2 + dyy10), c, _RGB32(c28, c29, c30)
  208.     CIRCLE (x2 + dxx11, y2 + dyy11), c, _RGB32(c31, c32, c33)
  209.     CIRCLE (x2 + dxx12, y2 + dyy12), c, _RGB32(c34, c35, c36)
  210.  
  211.     CIRCLE (x2 + dxx13, y2 + dyy13), c, _RGB32(c37, c38, c39)
  212.     CIRCLE (x2 + dxx14, y2 + dyy14), c, _RGB32(c40, c41, c42)
  213.     CIRCLE (x2 + dxx15, y2 + dyy15), c, _RGB32(c43, c44, c45)
  214.     CIRCLE (x2 + dxx16, y2 + dyy16), c, _RGB32(c46, c47, c48)
  215.  
  216.     CIRCLE (x2 + dxx17, y2 + dyy17), c, _RGB32(c49, c50, c51)
  217.     CIRCLE (x2 + dxx18, y2 + dyy18), c, _RGB32(c52, c53, c54)
  218.     CIRCLE (x2 + dxx19, y2 + dyy19), c, _RGB32(c55, c56, c57)
  219.     CIRCLE (x2 + dxx20, y2 + dyy20), c, _RGB32(c58, c59, c60)
  220.  
  221.     CIRCLE (x2 + dxx21, y2 + dyy21), c, _RGB32(c61, c62, c63)
  222.     CIRCLE (x2 + dxx22, y2 + dyy22), c, _RGB32(c64, c65, c66)
  223.     CIRCLE (x2 + dxx23, y2 + dyy23), c, _RGB32(c67, c68, c69)
  224.     CIRCLE (x2 + dxx24, y2 + dyy24), c, _RGB32(c70, c71, c72)
  225.  
  226. _DELAY .05
  227. FOR cc = .25 TO 2 STEP .25
  228.  
  229.     CIRCLE (x2 + dxx, y2 + dyy), cc, _RGB32(0, 0, 0)
  230.     CIRCLE (x2 + dxx2, y2 + dyy2), cc, _RGB32(0, 0, 0)
  231.     CIRCLE (x2 + dxx3, y2 + dyy3), cc, _RGB32(0, 0, 0)
  232.     CIRCLE (x2 + dxx4, y2 + dyy4), cc, _RGB32(0, 0, 0)
  233.  
  234.     CIRCLE (x2 + dxx5, y2 + dyy5), cc, _RGB32(0, 0, 0)
  235.     CIRCLE (x2 + dxx6, y2 + dyy6), cc, _RGB32(0, 0, 0)
  236.     CIRCLE (x2 + dxx7, y2 + dyy7), cc, _RGB32(0, 0, 0)
  237.     CIRCLE (x2 + dxx8, y2 + dyy8), cc, _RGB32(0, 0, 0)
  238.  
  239.     CIRCLE (x2 + dxx9, y2 + dyy9), cc, _RGB32(0, 0, 0)
  240.     CIRCLE (x2 + dxx10, y2 + dyy10), cc, _RGB32(0, 0, 0)
  241.     CIRCLE (x2 + dxx11, y2 + dyy11), cc, _RGB32(0, 0, 0)
  242.     CIRCLE (x2 + dxx12, y2 + dyy12), cc, _RGB32(0, 0, 0)
  243.  
  244.     CIRCLE (x2 + dxx13, y2 + dyy13), cc, _RGB32(0, 0, 0)
  245.     CIRCLE (x2 + dxx14, y2 + dyy14), cc, _RGB32(0, 0, 0)
  246.     CIRCLE (x2 + dxx15, y2 + dyy15), cc, _RGB32(0, 0, 0)
  247.     CIRCLE (x2 + dxx16, y2 + dyy16), cc, _RGB32(0, 0, 0)
  248.  
  249.     CIRCLE (x2 + dxx17, y2 + dyy17), cc, _RGB32(0, 0, 0)
  250.     CIRCLE (x2 + dxx18, y2 + dyy18), cc, _RGB32(0, 0, 0)
  251.     CIRCLE (x2 + dxx19, y2 + dyy19), cc, _RGB32(0, 0, 0)
  252.     CIRCLE (x2 + dxx20, y2 + dyy20), cc, _RGB32(0, 0, 0)
  253.  
  254.     CIRCLE (x2 + dxx21, y2 + dyy21), cc, _RGB32(0, 0, 0)
  255.     CIRCLE (x2 + dxx22, y2 + dyy22), cc, _RGB32(0, 0, 0)
  256.     CIRCLE (x2 + dxx23, y2 + dyy23), cc, _RGB32(0, 0, 0)
  257.     CIRCLE (x2 + dxx24, y2 + dyy24), cc, _RGB32(0, 0, 0)
  258.  
  259.  
  260. NEXT cc
  261.  
  262. IF dd > 25 THEN GOTO goingback
  263. GOTO explosion:
  264. goingback:
  265. dd = 0
  266. ee = ee + 1
  267. IF ee > 60 THEN GOTO finalboom:
  268. tt = tt + 1
  269. IF tt > 40 THEN tm = 0: GOTO delay:
  270. tm = (RND * 2) + .01
  271. delay:
  272. GOTO go:
  273.  
  274. 'FINAL BOOM!
  275.  
  276. finalboom:
  277. x3 = INT(RND * 600) + 100
  278. y3 = INT(RND * 400) + 100
  279. boom:
  280. ccl1 = INT(RND * 100) + 155
  281. ccl2 = INT(RND * 100) + 155
  282. ccl3 = INT(RND * 100) + 155
  283.  
  284. SOUND 100, .5
  285. SOUND 100, .5
  286. SOUND 100, .5
  287. SOUND 100, .5
  288. FOR sz = 2 TO 30
  289.     aa$ = INKEY$
  290.     IF aa$ = CHR$(27) THEN END
  291.     CIRCLE (x3, y3), sz * 2, _RGB32(ccl1, ccl2, ccl3)
  292.     _DELAY .02
  293. NEXT sz
  294. FOR sz = 2 TO 30
  295.     CIRCLE (x3, y3), sz * 2, _RGB32(0, 0, 0)
  296.     _DELAY .02
  297. NEXT sz
  298. f = f + 1
  299. IF f = 20 THEN GOTO face:
  300. GOTO finalboom:
  301. face:
  302. SCREEN _NEWIMAGE(800, 600, 13)
  303.  
  304. 'Make the face.
  305. CIRCLE (400, 300), 100, 10
  306. CIRCLE (350, 250), 20, 10
  307. CIRCLE (450, 250), 20, 10
  308. CIRCLE (400, 300), 15, 10
  309. CIRCLE (400, 350), 30, 10
  310.  
  311. 'Explode the face!
  312. FOR xt = 249 TO 551
  313.     FOR yt = 149 TO 451
  314.         a2$ = INKEY$
  315.         IF a2$ = CHR$(27) THEN END
  316.         IF POINT(xt, yt) > 0 AND POINT(xt, yt) <> 4 THEN
  317.             _LIMIT 5000
  318.             SOUND 100, .5
  319.             FOR b = 1 TO 40 STEP 2
  320.                 CIRCLE (xt, yt), b, 4
  321.                 _DELAY .002
  322.             NEXT b
  323.             FOR b = 1 TO 40 STEP 2
  324.                 CIRCLE (xt, yt), b, 0
  325.                 _DELAY .002
  326.             NEXT b
  327.         END IF
  328.     NEXT yt
  329. NEXT xt
  330.  
  331.  
  332.  
« Last Edit: August 08, 2019, 07:59:40 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Fireworks
« Reply #1 on: August 08, 2019, 07:58:21 pm »
Here's one with a welcome screen so the user knows it lasts 3 minutes and also has the ability to use the Esc key to end anytime.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. PRINT "                                  FIREWORKS"
  3. PRINT "                                  By  Ken G."
  4. PRINT "                    The show lasts around 3 minutes total."
  5. PRINT "                    Or press Esc to end anytime."
  6. PRINT "                    There's some surprises at the end."
  7. INPUT "                    Press Enter to begin.", bg$
  8. 'Start Loop Here
  9. go:
  10. a$ = INKEY$
  11. IF a$ = CHR$(27) THEN END
  12. x2 = INT(RND * 780) + 10
  13. y2 = INT(RND * 580) + 10
  14.  
  15. SOUND 100, .5
  16. SOUND 100, .5
  17. SOUND 100, .5
  18. SOUND 100, .5
  19.  
  20. dxx = (RND * 6) + -3
  21. dyy = (RND * 6) + -3
  22. dxx2 = (RND * 6) + -3
  23. dyy2 = (RND * 6) + -3
  24. dxx3 = (RND * 6) + -3
  25. dyy3 = (RND * 6) + -3
  26. dxx4 = (RND * 6) + -3
  27. dyy4 = (RND * 6) + -3
  28. dxx5 = (RND * 6) + -3
  29. dyy5 = (RND * 6) + -3
  30. dxx6 = (RND * 6) + -3
  31. dyy6 = (RND * 6) + -3
  32. dxx7 = (RND * 6) + -3
  33. dyy7 = (RND * 6) + -3
  34. dxx8 = (RND * 6) + -3
  35. dyy8 = (RND * 6) + -3
  36. dxx9 = (RND * 6) + -3
  37. dyy9 = (RND * 6) + -3
  38. dxx10 = (RND * 6) + -3
  39. dyy10 = (RND * 6) + -3
  40. dxx11 = (RND * 6) + -3
  41. dyy11 = (RND * 6) + -3
  42. dxx12 = (RND * 6) + -3
  43. dyy12 = (RND * 6) + -3
  44. dxx13 = (RND * 6) + -3
  45. dyy13 = (RND * 6) + -3
  46. dxx14 = (RND * 6) + -3
  47. dyy14 = (RND * 6) + -3
  48. dxx15 = (RND * 6) + -3
  49. dyy15 = (RND * 6) + -3
  50. dxx16 = (RND * 6) + -3
  51. dyy16 = (RND * 6) + -3
  52. dxx17 = (RND * 6) + -3
  53. dyy17 = (RND * 6) + -3
  54. dxx18 = (RND * 6) + -3
  55. dyy18 = (RND * 6) + -3
  56. dxx19 = (RND * 6) + -3
  57. dyy19 = (RND * 6) + -3
  58. dxx20 = (RND * 6) + -3
  59. dyy20 = (RND * 6) + -3
  60. dxx21 = (RND * 6) + -3
  61. dyy21 = (RND * 6) + -3
  62. dxx22 = (RND * 6) + -3
  63. dyy22 = (RND * 6) + -3
  64. dxx23 = (RND * 6) + -3
  65. dyy23 = (RND * 6) + -3
  66. dxx24 = (RND * 6) + -3
  67. dyy24 = (RND * 6) + -3
  68.  
  69. c1 = INT(RND * 200) + 55
  70. c2 = INT(RND * 200) + 55
  71. c3 = INT(RND * 200) + 55
  72. c4 = INT(RND * 200) + 55
  73. c5 = INT(RND * 200) + 55
  74. c6 = INT(RND * 200) + 55
  75. c7 = INT(RND * 200) + 55
  76. c8 = INT(RND * 200) + 55
  77. c9 = INT(RND * 200) + 55
  78. c10 = INT(RND * 200) + 55
  79. c11 = INT(RND * 200) + 55
  80. c12 = INT(RND * 200) + 55
  81. c13 = INT(RND * 200) + 55
  82. c14 = INT(RND * 200) + 55
  83. c15 = INT(RND * 200) + 55
  84. c16 = INT(RND * 200) + 55
  85. c17 = INT(RND * 200) + 55
  86. c18 = INT(RND * 200) + 55
  87. c19 = INT(RND * 200) + 55
  88. c20 = INT(RND * 200) + 55
  89. c21 = INT(RND * 200) + 55
  90. c22 = INT(RND * 200) + 55
  91. c23 = INT(RND * 200) + 55
  92. c24 = INT(RND * 200) + 55
  93. c25 = INT(RND * 200) + 55
  94. c26 = INT(RND * 200) + 55
  95. c27 = INT(RND * 200) + 55
  96. c28 = INT(RND * 200) + 55
  97. c29 = INT(RND * 200) + 55
  98. c30 = INT(RND * 200) + 55
  99. c31 = INT(RND * 200) + 55
  100. c32 = INT(RND * 200) + 55
  101. c33 = INT(RND * 200) + 55
  102. c34 = INT(RND * 200) + 55
  103. c35 = INT(RND * 200) + 55
  104. c36 = INT(RND * 200) + 55
  105. c37 = INT(RND * 200) + 55
  106. c38 = INT(RND * 200) + 55
  107. c39 = INT(RND * 200) + 55
  108. c40 = INT(RND * 200) + 55
  109. c41 = INT(RND * 200) + 55
  110. c42 = INT(RND * 200) + 55
  111. c43 = INT(RND * 200) + 55
  112. c44 = INT(RND * 200) + 55
  113. c45 = INT(RND * 200) + 55
  114. c46 = INT(RND * 200) + 55
  115. c47 = INT(RND * 200) + 55
  116. c48 = INT(RND * 200) + 55
  117. c49 = INT(RND * 200) + 55
  118. c50 = INT(RND * 200) + 55
  119. c51 = INT(RND * 200) + 55
  120. c52 = INT(RND * 200) + 55
  121. c53 = INT(RND * 200) + 55
  122. c54 = INT(RND * 200) + 55
  123. c55 = INT(RND * 200) + 55
  124. c56 = INT(RND * 200) + 55
  125. c57 = INT(RND * 200) + 55
  126. c58 = INT(RND * 200) + 55
  127. c59 = INT(RND * 200) + 55
  128. c60 = INT(RND * 200) + 55
  129. c61 = INT(RND * 200) + 55
  130. c62 = INT(RND * 200) + 55
  131. c63 = INT(RND * 200) + 55
  132. c64 = INT(RND * 200) + 55
  133. c65 = INT(RND * 200) + 55
  134. c66 = INT(RND * 200) + 55
  135. c67 = INT(RND * 200) + 55
  136. c68 = INT(RND * 200) + 55
  137. c69 = INT(RND * 200) + 55
  138. c70 = INT(RND * 200) + 55
  139. c71 = INT(RND * 200) + 55
  140. c72 = INT(RND * 200) + 55
  141.  
  142.  
  143.  
  144. explosion:
  145. dd = dd + 1
  146. dxx = dxx + dxx / 4
  147. dxx2 = dxx2 + dxx2 / 4
  148. dxx3 = dxx3 + dxx3 / 4
  149. dxx4 = dxx4 + dxx4 / 4
  150. dxx5 = dxx5 + dxx5 / 4
  151. dxx6 = dxx6 + dxx6 / 4
  152. dyy = dyy + dyy / 4
  153. dyy2 = dyy2 + dyy2 / 4
  154. dyy3 = dyy3 + dyy3 / 4
  155. dyy4 = dyy4 + dyy4 / 4
  156. dyy5 = dyy5 + dyy5 / 4
  157. dyy6 = dyy6 + dyy6 / 4
  158.  
  159. dxx7 = dxx7 + dxx7 / 4
  160. dxx8 = dxx8 + dxx8 / 4
  161. dxx9 = dxx9 + dxx9 / 4
  162. dxx10 = dxx10 + dxx10 / 4
  163. dxx11 = dxx11 + dxx11 / 4
  164. dxx12 = dxx12 + dxx12 / 4
  165. dyy7 = dyy7 + dyy7 / 4
  166. dyy8 = dyy8 + dyy8 / 4
  167. dyy9 = dyy9 + dyy9 / 4
  168. dyy10 = dyy10 + dyy10 / 4
  169. dyy11 = dyy11 + dyy11 / 4
  170. dyy12 = dyy12 + dyy12 / 4
  171.  
  172.  
  173. dxx13 = dxx13 + dxx13 / 4
  174. dxx14 = dxx14 + dxx14 / 4
  175. dxx15 = dxx15 + dxx15 / 4
  176. dxx16 = dxx16 + dxx16 / 4
  177. dxx17 = dxx17 + dxx17 / 4
  178. dxx18 = dxx18 + dxx18 / 4
  179. dyy13 = dyy13 + dyy13 / 4
  180. dyy14 = dyy14 + dyy14 / 4
  181. dyy15 = dyy15 + dyy15 / 4
  182. dyy16 = dyy16 + dyy16 / 4
  183. dyy17 = dyy17 + dyy17 / 4
  184. dyy18 = dyy18 + dyy18 / 4
  185.  
  186. dxx19 = dxx19 + dxx19 / 4
  187. dxx20 = dxx20 + dxx20 / 4
  188. dxx21 = dxx21 + dxx21 / 4
  189. dxx22 = dxx22 + dxx22 / 4
  190. dxx23 = dxx23 + dxx23 / 4
  191. dxx24 = dxx24 + dxx24 / 4
  192. dyy19 = dyy19 + dyy19 / 4
  193. dyy20 = dyy20 + dyy20 / 4
  194. dyy21 = dyy21 + dyy21 / 4
  195. dyy22 = dyy22 + dyy22 / 4
  196. dyy23 = dyy23 + dyy23 / 4
  197. dyy24 = dyy24 + dyy24 / 4
  198.  
  199.  
  200. FOR c = .25 TO 2 STEP .25
  201.     CIRCLE (x2 + dxx, y2 + dyy), c, _RGB32(c1, c2, c3)
  202.     CIRCLE (x2 + dxx2, y2 + dyy2), c, _RGB32(c4, c5, c6)
  203.     CIRCLE (x2 + dxx3, y2 + dyy3), c, _RGB32(c7, c8, c9)
  204.     CIRCLE (x2 + dxx4, y2 + dyy4), c, _RGB32(c10, c11, c12)
  205.  
  206.     CIRCLE (x2 + dxx5, y2 + dyy5), c, _RGB32(c13, c14, c15)
  207.     CIRCLE (x2 + dxx6, y2 + dyy6), c, _RGB32(c16, c17, c18)
  208.     CIRCLE (x2 + dxx7, y2 + dyy7), c, _RGB32(c19, c20, c21)
  209.     CIRCLE (x2 + dxx8, y2 + dyy8), c, _RGB32(c22, c23, c24)
  210.  
  211.     CIRCLE (x2 + dxx9, y2 + dyy9), c, _RGB32(c25, c26, c27)
  212.     CIRCLE (x2 + dxx10, y2 + dyy10), c, _RGB32(c28, c29, c30)
  213.     CIRCLE (x2 + dxx11, y2 + dyy11), c, _RGB32(c31, c32, c33)
  214.     CIRCLE (x2 + dxx12, y2 + dyy12), c, _RGB32(c34, c35, c36)
  215.  
  216.     CIRCLE (x2 + dxx13, y2 + dyy13), c, _RGB32(c37, c38, c39)
  217.     CIRCLE (x2 + dxx14, y2 + dyy14), c, _RGB32(c40, c41, c42)
  218.     CIRCLE (x2 + dxx15, y2 + dyy15), c, _RGB32(c43, c44, c45)
  219.     CIRCLE (x2 + dxx16, y2 + dyy16), c, _RGB32(c46, c47, c48)
  220.  
  221.     CIRCLE (x2 + dxx17, y2 + dyy17), c, _RGB32(c49, c50, c51)
  222.     CIRCLE (x2 + dxx18, y2 + dyy18), c, _RGB32(c52, c53, c54)
  223.     CIRCLE (x2 + dxx19, y2 + dyy19), c, _RGB32(c55, c56, c57)
  224.     CIRCLE (x2 + dxx20, y2 + dyy20), c, _RGB32(c58, c59, c60)
  225.  
  226.     CIRCLE (x2 + dxx21, y2 + dyy21), c, _RGB32(c61, c62, c63)
  227.     CIRCLE (x2 + dxx22, y2 + dyy22), c, _RGB32(c64, c65, c66)
  228.     CIRCLE (x2 + dxx23, y2 + dyy23), c, _RGB32(c67, c68, c69)
  229.     CIRCLE (x2 + dxx24, y2 + dyy24), c, _RGB32(c70, c71, c72)
  230.  
  231. _DELAY .05
  232. FOR cc = .25 TO 2 STEP .25
  233.  
  234.     CIRCLE (x2 + dxx, y2 + dyy), cc, _RGB32(0, 0, 0)
  235.     CIRCLE (x2 + dxx2, y2 + dyy2), cc, _RGB32(0, 0, 0)
  236.     CIRCLE (x2 + dxx3, y2 + dyy3), cc, _RGB32(0, 0, 0)
  237.     CIRCLE (x2 + dxx4, y2 + dyy4), cc, _RGB32(0, 0, 0)
  238.  
  239.     CIRCLE (x2 + dxx5, y2 + dyy5), cc, _RGB32(0, 0, 0)
  240.     CIRCLE (x2 + dxx6, y2 + dyy6), cc, _RGB32(0, 0, 0)
  241.     CIRCLE (x2 + dxx7, y2 + dyy7), cc, _RGB32(0, 0, 0)
  242.     CIRCLE (x2 + dxx8, y2 + dyy8), cc, _RGB32(0, 0, 0)
  243.  
  244.     CIRCLE (x2 + dxx9, y2 + dyy9), cc, _RGB32(0, 0, 0)
  245.     CIRCLE (x2 + dxx10, y2 + dyy10), cc, _RGB32(0, 0, 0)
  246.     CIRCLE (x2 + dxx11, y2 + dyy11), cc, _RGB32(0, 0, 0)
  247.     CIRCLE (x2 + dxx12, y2 + dyy12), cc, _RGB32(0, 0, 0)
  248.  
  249.     CIRCLE (x2 + dxx13, y2 + dyy13), cc, _RGB32(0, 0, 0)
  250.     CIRCLE (x2 + dxx14, y2 + dyy14), cc, _RGB32(0, 0, 0)
  251.     CIRCLE (x2 + dxx15, y2 + dyy15), cc, _RGB32(0, 0, 0)
  252.     CIRCLE (x2 + dxx16, y2 + dyy16), cc, _RGB32(0, 0, 0)
  253.  
  254.     CIRCLE (x2 + dxx17, y2 + dyy17), cc, _RGB32(0, 0, 0)
  255.     CIRCLE (x2 + dxx18, y2 + dyy18), cc, _RGB32(0, 0, 0)
  256.     CIRCLE (x2 + dxx19, y2 + dyy19), cc, _RGB32(0, 0, 0)
  257.     CIRCLE (x2 + dxx20, y2 + dyy20), cc, _RGB32(0, 0, 0)
  258.  
  259.     CIRCLE (x2 + dxx21, y2 + dyy21), cc, _RGB32(0, 0, 0)
  260.     CIRCLE (x2 + dxx22, y2 + dyy22), cc, _RGB32(0, 0, 0)
  261.     CIRCLE (x2 + dxx23, y2 + dyy23), cc, _RGB32(0, 0, 0)
  262.     CIRCLE (x2 + dxx24, y2 + dyy24), cc, _RGB32(0, 0, 0)
  263.  
  264.  
  265. NEXT cc
  266.  
  267. IF dd > 25 THEN GOTO goingback
  268. GOTO explosion:
  269. goingback:
  270. dd = 0
  271. ee = ee + 1
  272. IF ee > 60 THEN GOTO finalboom:
  273. tt = tt + 1
  274. IF tt > 40 THEN tm = 0: GOTO delay:
  275. tm = (RND * 2) + .01
  276. delay:
  277. GOTO go:
  278.  
  279. 'FINAL BOOM!
  280.  
  281. finalboom:
  282. x3 = INT(RND * 600) + 100
  283. y3 = INT(RND * 400) + 100
  284. boom:
  285. ccl1 = INT(RND * 100) + 155
  286. ccl2 = INT(RND * 100) + 155
  287. ccl3 = INT(RND * 100) + 155
  288.  
  289. SOUND 100, .5
  290. SOUND 100, .5
  291. SOUND 100, .5
  292. SOUND 100, .5
  293. FOR sz = 2 TO 30
  294.     aa$ = INKEY$
  295.     IF aa$ = CHR$(27) THEN END
  296.     CIRCLE (x3, y3), sz * 2, _RGB32(ccl1, ccl2, ccl3)
  297.     _DELAY .02
  298. NEXT sz
  299. FOR sz = 2 TO 30
  300.     CIRCLE (x3, y3), sz * 2, _RGB32(0, 0, 0)
  301.     _DELAY .02
  302. NEXT sz
  303. f = f + 1
  304. IF f = 20 THEN GOTO face:
  305. GOTO finalboom:
  306. face:
  307. SCREEN _NEWIMAGE(800, 600, 13)
  308.  
  309. 'Make the face.
  310. CIRCLE (400, 300), 100, 10
  311. CIRCLE (350, 250), 20, 10
  312. CIRCLE (450, 250), 20, 10
  313. CIRCLE (400, 300), 15, 10
  314. CIRCLE (400, 350), 30, 10
  315.  
  316. 'Explode the face!
  317. FOR xt = 249 TO 551
  318.     FOR yt = 149 TO 451
  319.         a2$ = INKEY$
  320.         IF a2$ = CHR$(27) THEN END
  321.         IF POINT(xt, yt) > 0 AND POINT(xt, yt) <> 4 THEN
  322.             _LIMIT 5000
  323.             SOUND 100, .5
  324.             FOR b = 1 TO 40 STEP 2
  325.                 CIRCLE (xt, yt), b, 4
  326.                 _DELAY .002
  327.             NEXT b
  328.             FOR b = 1 TO 40 STEP 2
  329.                 CIRCLE (xt, yt), b, 0
  330.                 _DELAY .002
  331.             NEXT b
  332.         END IF
  333.     NEXT yt
  334. NEXT xt
  335.  
  336.  
  337.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Fireworks
« Reply #2 on: August 09, 2019, 06:13:38 pm »
Fireworks in 50! (lines that are commented for students of explosions)
Code: QB64: [Select]
  1. _TITLE "Simple explosion of 200 particles" '2019-08-09 B+
  2. SCREEN _NEWIMAGE(1200, 720, 32) 'need a grphics screen for graphics
  3. _SCREENMOVE 100, 10 'so bplus can view screen past his tool bar on left
  4.  
  5. n = 200 'number of particles
  6. DIM x(n), y(n) 'particle location x, y
  7. DIM dx(n), dy(n) 'traveling in x, y vectors dx, dy (the change in x direction and the change in y direction)
  8.  
  9. GOSUB igniteParticles
  10. 'we have our particle all packed at random (x, y) and are ready to blow!
  11.  
  12. WHILE _KEYHIT <> 27 'while no escape key pressed
  13.     LINE (0, 0)-(_WIDTH, _HEIGHT), _RGBA(0, 0, 0, 30), BF 'only semi black out screen, this effect is so cool!!!!
  14.     'show particle by looping through the bunch
  15.     FOR p = 0 TO n
  16.         CIRCLE (x(p), y(p)), 2
  17.         'update each particle location
  18.         dx(p) = .98 * dx(p) 'retard the spread along x axis, call it air resistance
  19.         x(p) = x(p) + dx(p) 'change x position
  20.         dy(p) = dy(p) + .1 'gravity keeps forcing the particle down more and more
  21.         y(p) = y(p) + dy(p) 'change y position
  22.     NEXT
  23.     loopCntr = loopCntr + 1
  24.     LOCATE 1, 1: PRINT SPACE$(50)
  25.     LOCATE 1, 1: PRINT loopCntr ' OK a fire work in over in about 250 frames but 200 enough
  26.     IF loopCntr MOD 200 = 199 THEN 'show done start another
  27.         loopCntr = 0
  28.         GOSUB igniteParticles
  29.     END IF
  30.     _DISPLAY 'this so screen wont flicker
  31.     _LIMIT 30 'so dont overwork fan
  32. igniteParticles:
  33. 'pick random x, y from which to explode
  34. rx = RND * _WIDTH / 2 + _WIDTH / 4 ' middle half of screen
  35. ry = RND * _HEIGHT / 8 + _HEIGHT / 8 ' upper 1/4 of screen
  36. FOR p = 0 TO n 'for each particle
  37.     'select a random angle = direction to go
  38.     x(p) = rx ' start every particle here rx, ry
  39.     y(p) = ry ' start every particle here rx, ry
  40.     d = 360 * RND 'direction in degrees is a random number from 0 to 360
  41.     v = 10 * RND 'velocity they are moving is random 0 to 10
  42.  
  43.     'the following calculates the x component of the particle vector , the change the particle will make along the x axis
  44.     dx(p) = v * COS(_D2R(d)) ' _D2R converts our random direction in degrees to radians for COS to process
  45.  
  46.     'the following calculates the y component of the particle vector , the change the particle will make along the y axis
  47.     dy(p) = v * SIN(_D2R(d)) ' _D2R converts our random direction in degrees to radians for SIN to process
  48.  
« Last Edit: August 09, 2019, 06:18:51 pm by bplus »

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Fireworks
« Reply #3 on: August 09, 2019, 07:43:54 pm »
Fireworks in 50! (lines that are commented for students of explosions)

Being modest as usual, I see. Removing the white space and comments brings it down to 38 lines...

...and it's so well written that only the barest tweak gives it color...

Code: QB64: [Select]
  1. _TITLE "Simple explosion of 200 particles" '2019-08-09 B+
  2. SCREEN _NEWIMAGE(1200, 720, 32) 'need a grphics screen for graphics
  3. _SCREENMOVE 100, 10 'so bplus can view screen past his tool bar on left
  4.  
  5. n = 200 'number of particles
  6. DIM x(n), y(n) 'particle location x, y
  7. DIM dx(n), dy(n) 'traveling in x, y vectors dx, dy (the change in x direction and the change in y direction)
  8. DIM r&(n), g&(n), b&(n) 'color component of particles added by OldMoses
  9.  
  10. GOSUB igniteParticles
  11. 'we have our particle all packed at random (x, y) and are ready to blow!
  12.  
  13. WHILE _KEYHIT <> 27 'while no escape key pressed
  14.     LINE (0, 0)-(_WIDTH, _HEIGHT), _RGBA(0, 0, 0, 30), BF 'only semi black out screen, this effect is so cool!!!!
  15.     'show particle by looping through the bunch
  16.     FOR p = 0 TO n
  17.         CIRCLE (x(p), y(p)), 2, _RGBA32(r&(p), g&(p), b&(p), 255)
  18.         'update each particle location
  19.         dx(p) = .98 * dx(p) 'retard the spread along x axis, call it air resistance
  20.         x(p) = x(p) + dx(p) 'change x position
  21.         dy(p) = dy(p) + .1 'gravity keeps forcing the particle down more and more
  22.         y(p) = y(p) + dy(p) 'change y position
  23.     NEXT
  24.     loopCntr = loopCntr + 1
  25.     LOCATE 1, 1: PRINT SPACE$(50)
  26.     LOCATE 1, 1: PRINT loopCntr ' OK a fire work in over in about 250 frames but 200 enough
  27.     IF loopCntr MOD 200 = 199 THEN 'show done start another
  28.         loopCntr = 0
  29.         GOSUB igniteParticles
  30.     END IF
  31.     _DISPLAY 'this so screen wont flicker
  32.     _LIMIT 30 'so dont overwork fan
  33. igniteParticles:
  34. 'pick random x, y from which to explode
  35. rx = RND * _WIDTH / 2 + _WIDTH / 4 ' middle half of screen
  36. ry = RND * _HEIGHT / 8 + _HEIGHT / 8 ' upper 1/4 of screen
  37. FOR p = 0 TO n 'for each particle
  38.     'select a random angle = direction to go
  39.     x(p) = rx ' start every particle here rx, ry
  40.     y(p) = ry ' start every particle here rx, ry
  41.     d = 360 * RND 'direction in degrees is a random number from 0 to 360
  42.     v = 10 * RND 'velocity they are moving is random 0 to 10
  43.     r&(p) = INT(RND * 256) 'color components added by OldMoses
  44.     g&(p) = INT(RND * 256)
  45.     b&(p) = INT(RND * 256)
  46.  
  47.     'the following calculates the x component of the particle vector , the change the particle will make along the x axis
  48.     dx(p) = v * COS(_D2R(d)) ' _D2R converts our random direction in degrees to radians for COS to process
  49.  
  50.     'the following calculates the y component of the particle vector , the change the particle will make along the y axis
  51.     dy(p) = v * SIN(_D2R(d)) ' _D2R converts our random direction in degrees to radians for SIN to process
  52.  
  53.  
  54.  
« Last Edit: August 09, 2019, 08:06:46 pm by OldMoses »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Fireworks
« Reply #4 on: August 10, 2019, 12:01:17 am »
Hi Andy,

Color! I could watch that all day!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Fireworks
« Reply #5 on: August 11, 2019, 04:55:53 am »
Cool fireworks... :)

J
Logic is the beginning of wisdom.

Offline pforpond

  • Newbie
  • Posts: 76
  • I am me
    • View Profile
Re: Fireworks
« Reply #6 on: August 11, 2019, 05:56:15 am »
Very pretty! I love this! It's quite mesmerising I could watch it run for hours :)
Loading Signature...