QB64.org Forum

Active Forums => Programs => Topic started by: SierraKen on May 12, 2020, 12:30:28 am

Title: U.S. Flag
Post by: SierraKen on May 12, 2020, 12:30:28 am
This is the U.S. Flag I made using numbers and commands. I was able to only use the DATA lines for one single star and copied it enough times to be 50 stars on the flag. I did similar loops with Line commands for the stripes. Feel free to use any or all of this code in your own applications or games. I included a picture of it below.

Code: QB64: [Select]
  1. 'Made to honor the U.S. Flag.
  2. 'Feel free to use any or all of this code in your own applications or games.
  3. 'By Sierraken on May 11, 2020.
  4.  
  5. _LIMIT 300
  6. _TITLE "U.S. Flag"
  7. SCREEN _NEWIMAGE(800, 600, 32)
  8. x = 150
  9. y = 100
  10.  
  11. 'Sky
  12. PAINT (2, 2), _RGB32(0, 205, 255)
  13.  
  14. 'Stars
  15. LINE (x, y)-(x + 185, y + 130), _RGB32(0, 0, 255), BF
  16. FOR xx = 155 TO 345 STEP 32
  17.     FOR yy = 105 TO 220 STEP 28
  18.         FOR stary = 1 TO 10
  19.             FOR starx = 1 TO 12
  20.                 READ c
  21.                 PSET (starx + xx, stary + yy), _RGB32(c, c, 255)
  22.             NEXT starx
  23.         NEXT stary
  24.         RESTORE Stars
  25.     NEXT yy
  26. NEXT xx
  27. RESTORE Stars
  28. FOR xx = 172 TO 329 STEP 32
  29.     FOR yy = 118.9 TO 213.05 STEP 28
  30.         FOR stary = 1 TO 10
  31.             FOR starx = 1 TO 12
  32.                 READ c
  33.                 PSET (starx + xx, stary + yy), _RGB32(c, c, 255)
  34.             NEXT starx
  35.         NEXT stary
  36.         RESTORE Stars
  37.     NEXT yy
  38. NEXT xx
  39.  
  40. 'Stripes
  41. FOR rs = 100 TO 230 STEP 37.2
  42.     w = w + 1
  43.     LINE (335, rs)-(612.5, rs + 18.6), _RGB32(255, 0, 0), BF
  44.     IF w > 3 THEN GOTO nex:
  45.     LINE (335, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 255, 255), BF
  46. NEXT rs
  47. nex:
  48. w = 0
  49. FOR rs = 230 TO 341.6 STEP 37.2
  50.     r = r + 1
  51.     LINE (150, rs)-(612.5, rs + 18.6), _RGB32(255, 255, 255), BF
  52.     IF r > 3 THEN GOTO nex2:
  53.     LINE (150, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 0, 0), BF
  54. NEXT rs
  55. nex2:
  56. r = 0
  57.  
  58. 'Flag Pole
  59. FOR sz = .25 TO 10 STEP .25
  60.     CIRCLE (145, 80), sz, _RGB32(122, 128, 166)
  61. NEXT sz
  62. LINE (142, 80)-(147, 600), _RGB32(122, 128, 166), BF
  63.  
  64. 'Wait for Esc key.
  65.     a$ = INKEY$
  66. LOOP UNTIL a$ = CHR$(27)
  67.  
  68. Stars:
  69. DATA 0,0,0,0,0,255,255,0,0,0,0,0
  70. DATA 0,0,0,0,255,255,255,0,0,0,0,0
  71. DATA 255,255,255,255,255,255,255,255,255,255,255,255
  72. DATA 255,255,255,255,255,255,255,255,255,255,255,255
  73. DATA 0,0,0,255,255,255,255,255,255,0,0,0
  74. DATA 0,0,255,255,255,255,255,255,255,255,0,0
  75. DATA 0,255,255,255,255,255,255,255,255,255,255,0
  76. DATA 255,255,255,0,0,0,0,0,0,0,255,255,255
  77. DATA 255,255,0,0,0,0,0,0,0,0,255,255
  78. DATA 255,0,0,0,0,0,0,0,0,0,0,255
  79.  

Title: Re: U.S. Flag
Post by: Ashish on May 12, 2020, 04:45:23 am
Nice! Now, make it wave around.
Title: Re: U.S. Flag
Post by: Pete on May 12, 2020, 05:19:00 am
Nice! Now, make it wave around.

You guys just make it too easy for me. :D

Pete
Title: Re: U.S. Flag
Post by: TerryRitchie on May 12, 2020, 08:25:16 am
Nice! Now, make it wave around.

Done :-)

http://qb64sourcecode.com/Task7.html#YOURTURN

http://qb64sourcecode.com/task15.html#COPYPASTE
Title: Re: U.S. Flag
Post by: SierraKen on May 12, 2020, 12:08:36 pm
Thanks guys.
Title: Re: U.S. Flag
Post by: Pete on May 12, 2020, 01:30:38 pm
Nice flag design Ken, and cool tutorial, Terryl!

When TheBOB had to do all this stuff with data fields, like Ken's approach, well, that was impressive, but it was also very time consuming, especially when it got into doing sprites for animation. The added ability of QB64 to make use of pre-made images, as in Terry's waiving flag tutorial, shown below, could almost get a stubborn SCREEN 0 Hero, like me, interested in graphics programming.

Looking forward to task 15b, Chinese flag on fire!

 


Pete
Title: Re: U.S. Flag
Post by: SierraKen on May 12, 2020, 02:46:08 pm
That's awesome Pete! Yeah I thought about animating mine but it wouldn't come out good I think. But that's OK, it still can be used in programs that people want little or no added files to theirs.
Title: Re: U.S. Flag
Post by: SierraKen on May 12, 2020, 03:21:02 pm
Stxaxtic had a great wavy flag awhile back. I just tried the link on this post of Petr's flag, but the link no long works on there.
Here is the original post, but I will also put Stxaxtic's code on here, its worth checking out.


https://www.qb64.org/forum/index.php?topic=44.msg276#msg276
 (https://www.qb64.org/forum/index.php?topic=44.msg276#msg276)

Code: QB64: [Select]
  1. '#lang "qb" '...for freebasic compiler. Keep disabled for QB64.
  2.  
  3. ' *** Video settings. ***
  4.  
  5. screenwidth = 640
  6. screenheight = 480
  7.  
  8. ' *** Performance settings. ***
  9.  
  10. bignumber = 500000 ' Maximum objects per array (determined by memory).
  11. globaldelayinit = 1000 ' Loop damping factor (fine adjustment below).
  12.  
  13. ' *** Initialize counters and array sizes. ***
  14.  
  15. numparticleorig = bignumber
  16. numparticlevisible = bignumber
  17.  
  18. ' *** Define basis arrays and structures. ***
  19.  
  20. ' Screen vectors in three-space.
  21. ' These vectors define the camera angle.
  22. DIM uhat(1 TO 3), vhat(1 TO 3), nhat(1 TO 3)
  23.  
  24. ' Basis vectors defined in three-space.
  25. DIM xhat(1 TO 4), yhat(1 TO 4), zhat(1 TO 4)
  26. xhat(1) = 1: xhat(2) = 0: xhat(3) = 0: xhat(4) = 4
  27. yhat(1) = 0: yhat(2) = 1: yhat(3) = 0: yhat(4) = 2
  28. zhat(1) = 0: zhat(2) = 0: zhat(3) = 1: zhat(4) = 1
  29.  
  30. ' Basis vectors projected into uv two-space.
  31. DIM xhatp(1 TO 2), yhatp(1 TO 2), zhatp(1 TO 2)
  32. DIM xhatp.old(1 TO 2), yhatp.old(1 TO 2), zhatp.old(1 TO 2)
  33.  
  34. ' *** Define particle arrays and structures. ***
  35.  
  36. ' Particle vectors defined in three-space.
  37. DIM vec(numparticleorig, 4)
  38. DIM vecdotnhat(numparticleorig)
  39. DIM vecdotnhatunit.old(numparticleorig)
  40. DIM vecvisible(numparticlevisible, 4)
  41. DIM vecvisibledotnhat(numparticlevisible)
  42. DIM vecvisibledotnhatunit.old(numparticlevisible)
  43.  
  44. ' Particle vectors projected onto infinite uv two-space.
  45. DIM vecpuv(numparticleorig, 1 TO 2)
  46. DIM vecpuv.old(numparticleorig, 1 TO 2)
  47. DIM vecvisiblepuv(numparticlevisible, 1 TO 2)
  48. DIM vecvisiblepuv.old(numparticlevisible, 1 TO 2)
  49.  
  50. ' Particle projections adjusted for screen uv two-space.
  51. DIM vecpuvs(numparticleorig, 1 TO 2)
  52. DIM vecpuvs.old(numparticleorig, 1 TO 2)
  53. DIM vecvisiblepuvs(numparticlevisible, 1 TO 2)
  54. DIM vecvisiblepuvs.old(numparticlevisible, 1 TO 2)
  55.  
  56. ' *** Define specialized arrays and structures. ***
  57.  
  58. ' Arrays for tech 2 mesh plotting.
  59. DIM plotflag(numparticleorig)
  60. DIM plotflag.old(numparticleorig)
  61.  
  62. ' *** Set mathematical constants. ***
  63.  
  64. pi = 3.1415926536
  65. ee = 2.7182818285
  66.  
  67. mainstart:
  68.  
  69. ' *** Initialize user input variables. ***
  70. KEY$ = ""
  71. 'mousekey$ = ""
  72.  
  73. ' *** Process first user input. ***
  74.  
  75. a$ = "13"
  76.  
  77.     CASE "13": genscheme$ = "wave2d": plotmode$ = "simplemesh"
  78.  
  79. substart:
  80.  
  81. ' *** Zero counters and array sizes. ***
  82.  
  83. numparticleorig = 0
  84. numparticlevisible = 0
  85.  
  86. ' *** Constants and switch control. ***
  87.  
  88. ' Perspective and animation switches/defaults.
  89. centerx = screenwidth / 2
  90. centery = screenheight / 2
  91. speedconst = 50
  92. falsedepth = .01
  93. zoom = 30
  94. timevar = 0
  95. T = 0
  96. togglehud = 1
  97. toggleatomnumbers = -1
  98. toggletimeanimate = -1
  99. toggletimealert = 0
  100. camx = 0
  101. camy = 0
  102. camz = 0
  103. uhat(1) = -3: uhat(2) = 5: uhat(3) = 1 / 4
  104. vhat(1) = -1: vhat(2) = -1: vhat(3) = 8
  105.  
  106.  
  107. SELECT CASE LCASE$(genscheme$)
  108.     CASE "wave2d":
  109.         globaldelay = globaldelayinit * 1500
  110.         uhat(1) = .7802773: uhat(2) = -.4759201: uhat(3) = .4058135
  111.         vhat(1) = .2502121: vhat(2) = .8321912: vhat(3) = .4948249
  112.         togglehud = 1
  113.         toggletimealert = 1
  114.         GOSUB genscheme.wave2d.init
  115.         numparticleorig = pcountparticleorig
  116.         REDIM vec2dz(xrange, yrange)
  117.         REDIM vec2dztemp(xrange, yrange)
  118.         REDIM vec2dzprev(xrange, yrange)
  119.         GOSUB genschemeUSAcolors
  120.         GOSUB genscheme.wave2d.gridinit
  121.  
  122. ' Move objects to accomodate initial camera position.
  123. IF camx <> 0 AND camy <> 0 AND camz <> 0 THEN
  124.     FOR i = 1 TO numparticleorig
  125.         vec(i, 1) = vec(i, 1) + camx
  126.         vec(i, 2) = vec(i, 2) + camy
  127.         vec(i, 3) = vec(i, 3) + camz
  128.     NEXT
  129.  
  130. GOSUB redraw
  131.  
  132. ' *** Begin main loop. ***
  133.     IF toggletimeanimate = 1 THEN
  134.         GOSUB timeanimate
  135.         flagredraw = 1
  136.     END IF
  137.     IF flagredraw = 1 THEN
  138.         GOSUB redraw
  139.         flagredraw = -1
  140.     END IF
  141.     GOSUB keyprocess
  142.     IF toggletimeanimate = 1 THEN
  143.         FOR delaycount = 1 TO globaldelay: NEXT
  144.     END IF
  145. ' *** End main loop. ***
  146.  
  147. ' *** Begin function definitions. ***
  148.  
  149. ' Comment out the conents of this gosub for non-QB64 compiler.
  150. mouseprocess:
  151.  
  152. keyprocess:
  153. IF KEY$ <> "" THEN
  154.     flagredraw = 1
  155.     CASE "8":
  156.         GOSUB rotate.vhat.plus
  157.     CASE "2":
  158.         GOSUB rotate.vhat.minus
  159.     CASE "4":
  160.         GOSUB rotate.uhat.minus
  161.     CASE "6":
  162.         GOSUB rotate.uhat.plus
  163.     CASE "7":
  164.         GOSUB rotate.clockwise
  165.     CASE "9":
  166.         GOSUB rotate.counterclockwise
  167.     CASE "1":
  168.         GOSUB rotate.uhat.minus: GOSUB normalize.SCREEN.vectors: GOSUB rotate.clockwise
  169.     CASE "3":
  170.         GOSUB rotate.uhat.plus: GOSUB normalize.SCREEN.vectors: GOSUB rotate.counterclockwise
  171.     CASE "q"
  172.         GOSUB strafe.objects.vhat.plus
  173.         GOSUB strafe.camera.vhat.plus
  174.     CASE "e"
  175.         GOSUB strafe.objects.vhat.minus
  176.         GOSUB strafe.camera.vhat.minus
  177.     CASE "x"
  178.         uhat(1) = 0: uhat(2) = 1: uhat(3) = 0
  179.         vhat(1) = 0: vhat(2) = 0: vhat(3) = 1
  180.     CASE "y"
  181.         uhat(1) = 0: uhat(2) = 0: uhat(3) = 1
  182.         vhat(1) = 1: vhat(2) = 0: vhat(3) = 0
  183.     CASE "z"
  184.         uhat(1) = 1: uhat(2) = 0: uhat(3) = 0
  185.         vhat(1) = 0: vhat(2) = 1: vhat(3) = 0
  186.     CASE "t"
  187.         toggletimeanimate = -toggletimeanimate
  188.     CASE "r"
  189.         timevar = 0
  190.     CASE "f"
  191.         GOTO substart
  192.     CASE "g"
  193.         GOTO mainstart
  194.     CASE "-"
  195.         globaldelay = globaldelay * 1.1
  196.     CASE "="
  197.         globaldelay = globaldelay * 0.9
  198.     CASE "`"
  199.         globaldelayinit = globaldelay
  200.     CASE " "
  201.         togglehud = -togglehud
  202.         CLS
  203.     CASE CHR$(27)
  204.         END
  205.  
  206. convert:
  207. ' Convert graphics from uv-cartesian coordinates to monitor coordinates.
  208. x0 = x: y0 = y
  209. x = x0 + centerx
  210. y = -y0 + centery
  211.  
  212. ' *** Define functions for view translation and rotation. ***
  213.  
  214. rotate.uhat.plus:
  215. uhat(1) = nhat(1) + speedconst * uhat(1)
  216. uhat(2) = nhat(2) + speedconst * uhat(2)
  217. uhat(3) = nhat(3) + speedconst * uhat(3)
  218.  
  219. rotate.uhat.minus:
  220. uhat(1) = -nhat(1) + speedconst * uhat(1)
  221. uhat(2) = -nhat(2) + speedconst * uhat(2)
  222. uhat(3) = -nhat(3) + speedconst * uhat(3)
  223.  
  224. rotate.vhat.plus:
  225. vhat(1) = nhat(1) + speedconst * vhat(1)
  226. vhat(2) = nhat(2) + speedconst * vhat(2)
  227. vhat(3) = nhat(3) + speedconst * vhat(3)
  228.  
  229. rotate.vhat.minus:
  230. vhat(1) = -nhat(1) + speedconst * vhat(1)
  231. vhat(2) = -nhat(2) + speedconst * vhat(2)
  232. vhat(3) = -nhat(3) + speedconst * vhat(3)
  233.  
  234. rotate.counterclockwise:
  235. v1 = vhat(1)
  236. v2 = vhat(2)
  237. v3 = vhat(3)
  238. vhat(1) = uhat(1) + speedconst * vhat(1)
  239. vhat(2) = uhat(2) + speedconst * vhat(2)
  240. vhat(3) = uhat(3) + speedconst * vhat(3)
  241. uhat(1) = -v1 + speedconst * uhat(1)
  242. uhat(2) = -v2 + speedconst * uhat(2)
  243. uhat(3) = -v3 + speedconst * uhat(3)
  244.  
  245. rotate.clockwise:
  246. v1 = vhat(1)
  247. v2 = vhat(2)
  248. v3 = vhat(3)
  249. vhat(1) = -uhat(1) + speedconst * vhat(1)
  250. vhat(2) = -uhat(2) + speedconst * vhat(2)
  251. vhat(3) = -uhat(3) + speedconst * vhat(3)
  252. uhat(1) = v1 + speedconst * uhat(1)
  253. uhat(2) = v2 + speedconst * uhat(2)
  254. uhat(3) = v3 + speedconst * uhat(3)
  255.  
  256. strafe.objects.uhat.plus:
  257. FOR i = 1 TO numparticleorig
  258.     vec(i, 1) = vec(i, 1) + uhat(1) * 1 / zoom
  259.     vec(i, 2) = vec(i, 2) + uhat(2) * 1 / zoom
  260.     vec(i, 3) = vec(i, 3) + uhat(3) * 1 / zoom
  261.  
  262. strafe.objects.uhat.minus:
  263. FOR i = 1 TO numparticleorig
  264.     vec(i, 1) = vec(i, 1) - uhat(1) * 1 / zoom
  265.     vec(i, 2) = vec(i, 2) - uhat(2) * 1 / zoom
  266.     vec(i, 3) = vec(i, 3) - uhat(3) * 1 / zoom
  267.  
  268. strafe.objects.vhat.plus:
  269. FOR i = 1 TO numparticleorig
  270.     vec(i, 1) = vec(i, 1) + vhat(1) * 1 / zoom
  271.     vec(i, 2) = vec(i, 2) + vhat(2) * 1 / zoom
  272.     vec(i, 3) = vec(i, 3) + vhat(3) * 1 / zoom
  273.  
  274. strafe.objects.vhat.minus:
  275. FOR i = 1 TO numparticleorig
  276.     vec(i, 1) = vec(i, 1) - vhat(1) * 1 / zoom
  277.     vec(i, 2) = vec(i, 2) - vhat(2) * 1 / zoom
  278.     vec(i, 3) = vec(i, 3) - vhat(3) * 1 / zoom
  279.  
  280. strafe.objects.nhat.plus:
  281. FOR i = 1 TO numparticleorig
  282.     vec(i, 1) = vec(i, 1) + nhat(1) * 1 / zoom
  283.     vec(i, 2) = vec(i, 2) + nhat(2) * 1 / zoom
  284.     vec(i, 3) = vec(i, 3) + nhat(3) * 1 / zoom
  285.  
  286. strafe.objects.nhat.minus:
  287. FOR i = 1 TO numparticleorig
  288.     vec(i, 1) = vec(i, 1) - nhat(1) * 1 / zoom
  289.     vec(i, 2) = vec(i, 2) - nhat(2) * 1 / zoom
  290.     vec(i, 3) = vec(i, 3) - nhat(3) * 1 / zoom
  291.  
  292. strafe.camera.uhat.plus:
  293. camx = camx + uhat(1) * 1 / zoom
  294. camy = camy + uhat(2) * 1 / zoom
  295. camz = camz + uhat(3) * 1 / zoom
  296.  
  297. strafe.camera.uhat.minus:
  298. camx = camx - uhat(1) * 1 / zoom
  299. camy = camy - uhat(2) * 1 / zoom
  300. camz = camz - uhat(3) * 1 / zoom
  301.  
  302. strafe.camera.vhat.plus:
  303. camx = camx + vhat(1) * 1 / zoom
  304. camy = camy + vhat(2) * 1 / zoom
  305. camz = camz + vhat(3) * 1 / zoom
  306.  
  307. strafe.camera.vhat.minus:
  308. camx = camx - vhat(1) * 1 / zoom
  309. camy = camy - vhat(2) * 1 / zoom
  310. camz = camz - vhat(3) * 1 / zoom
  311.  
  312. strafe.camera.nhat.plus:
  313. camx = camx + nhat(1) * 1 / zoom
  314. camy = camy + nhat(2) * 1 / zoom
  315. camz = camz + nhat(3) * 1 / zoom
  316.  
  317. strafe.camera.nhat.minus:
  318. camx = camx - nhat(1) * 1 / zoom
  319. camy = camy - nhat(2) * 1 / zoom
  320. camz = camz - nhat(3) * 1 / zoom
  321.  
  322. ' *** Define core functions. ***
  323.  
  324. timeanimate:
  325. timevar = timevar + 1
  326. IF timevar > 10 ^ 6 THEN timevar = 1
  327. SELECT CASE genscheme$
  328.     CASE "wave2d": GOSUB genscheme.wave2d.timeanimate
  329.  
  330. normalize.SCREEN.vectors:
  331. 'normalize the two vectors that define the screen orientation
  332. uhatmag = SQR(uhat(1) ^ 2 + uhat(2) ^ 2 + uhat(3) ^ 2)
  333. uhat(1) = uhat(1) / uhatmag: uhat(2) = uhat(2) / uhatmag: uhat(3) = uhat(3) / uhatmag
  334. vhatmag = SQR(vhat(1) ^ 2 + vhat(2) ^ 2 + vhat(3) ^ 2)
  335. vhat(1) = vhat(1) / vhatmag: vhat(2) = vhat(2) / vhatmag: vhat(3) = vhat(3) / vhatmag
  336. uhatdotvhat = uhat(1) * vhat(1) + uhat(2) * vhat(2) + uhat(3) * vhat(3)
  337. IF SQR(uhatdotvhat ^ 2) > .0005 THEN
  338.     CLS: COLOR 15: LOCATE 5, 5: PRINT "Screen vectors are not perpendicular. Press ESC to quit."
  339.     'DO: LOOP UNTIL INKEY$ = CHR$(27): END
  340. ' Compute the normal vector to the view plane.
  341. ' The normal vector points toward the eye, away from view frustum.
  342. nhat(1) = uhat(2) * vhat(3) - uhat(3) * vhat(2)
  343. nhat(2) = uhat(3) * vhat(1) - uhat(1) * vhat(3)
  344. nhat(3) = uhat(1) * vhat(2) - uhat(2) * vhat(1)
  345. nhatmag = SQR(nhat(1) ^ 2 + nhat(2) ^ 2 + nhat(3) ^ 2)
  346. nhat(1) = nhat(1) / nhatmag: nhat(2) = nhat(2) / nhatmag: nhat(3) = nhat(3) / nhatmag
  347.  
  348. redraw:
  349. GOSUB normalize.SCREEN.vectors
  350. ' Project the three-space basis vectors onto the screen plane.
  351. xhatp(1) = xhat(1) * uhat(1) + xhat(2) * uhat(2) + xhat(3) * uhat(3)
  352. xhatp(2) = xhat(1) * vhat(1) + xhat(2) * vhat(2) + xhat(3) * vhat(3)
  353. yhatp(1) = yhat(1) * uhat(1) + yhat(2) * uhat(2) + yhat(3) * uhat(3)
  354. yhatp(2) = yhat(1) * vhat(1) + yhat(2) * vhat(2) + yhat(3) * vhat(3)
  355. zhatp(1) = zhat(1) * uhat(1) + zhat(2) * uhat(2) + zhat(3) * uhat(3)
  356. zhatp(2) = zhat(1) * vhat(1) + zhat(2) * vhat(2) + zhat(3) * vhat(3)
  357. IF numparticleorig > 0 THEN
  358.     GOSUB compute.visible.particles
  359.     GOSUB project.particles
  360.     GOSUB depth.adjust.particles
  361. GOSUB DRAW.all.objects
  362. GOSUB store.SCREEN.projections
  363.  
  364. reverse.uvnhat:
  365. uhat(1) = -uhat(1)
  366. uhat(2) = -uhat(2)
  367. uhat(3) = -uhat(3)
  368. GOSUB normalize.SCREEN.vectors
  369.  
  370. compute.visible.particles:
  371. numparticlevisible = 0
  372. FOR i = 1 TO numparticleorig
  373.     IF falsedepth = 0 THEN
  374.     ELSE
  375.         numparticlevisible = numparticlevisible + 1
  376.         vecvisible(numparticlevisible, 1) = vec(i, 1)
  377.         vecvisible(numparticlevisible, 2) = vec(i, 2)
  378.         vecvisible(numparticlevisible, 3) = vec(i, 3)
  379.         vecvisible(numparticlevisible, 4) = vec(i, 4)
  380.     END IF
  381.  
  382. project.particles:
  383. ' Project object vectors onto the screen plane.
  384. FOR i = 1 TO numparticlevisible
  385.     vecvisibledotnhat(i) = vecvisible(i, 1) * nhat(1) + vecvisible(i, 2) * nhat(2) + vecvisible(i, 3) * nhat(3)
  386.     vecvisiblepuv(i, 1) = (vecvisible(i, 1) * uhat(1) + vecvisible(i, 2) * uhat(2) + vecvisible(i, 3) * uhat(3))
  387.     vecvisiblepuv(i, 2) = (vecvisible(i, 1) * vhat(1) + vecvisible(i, 2) * vhat(2) + vecvisible(i, 3) * vhat(3))
  388.  
  389. depth.adjust.particles:
  390. IF falsedepth = 0 THEN
  391.     FOR i = 1 TO numparticlevisible
  392.         vecvisiblepuvs(i, 1) = vecvisiblepuv(i, 1) * fovd / vecvisibledotnhat(i)
  393.         vecvisiblepuvs(i, 2) = vecvisiblepuv(i, 2) * fovd / vecvisibledotnhat(i)
  394.     NEXT
  395.     FOR i = 1 TO numparticlevisible
  396.         vecvisiblepuvs(i, 1) = vecvisiblepuv(i, 1) * (1 + falsedepth * vecvisibledotnhat(i))
  397.         vecvisiblepuvs(i, 2) = vecvisiblepuv(i, 2) * (1 + falsedepth * vecvisibledotnhat(i))
  398.     NEXT
  399.  
  400. DRAW.all.objects:
  401. SELECT CASE plotmode$
  402.     CASE "simplemesh": GOSUB plotmode.simplemesh
  403. LOCATE 28, 23: PRINT "SPACE = toggle HUD,  ESC = quit."
  404. IF togglehud = 1 THEN
  405.     ' Replace basis vector triad.
  406.     x = 50 * xhatp.old(1): y = 50 * xhatp.old(2): GOSUB convert
  407.     LINE (centerx, centery)-(x, y), 0
  408.     x = 50 * yhatp.old(1): y = 50 * yhatp.old(2): GOSUB convert
  409.     LINE (centerx, centery)-(x, y), 0
  410.     x = 50 * zhatp.old(1): y = 50 * zhatp.old(2): GOSUB convert
  411.     LINE (centerx, centery)-(x, y), 0
  412.     x = 50 * xhatp(1): y = 50 * xhatp(2): GOSUB convert
  413.     LINE (centerx, centery)-(x, y), xhat(4)
  414.     x = 50 * yhatp(1): y = 50 * yhatp(2): GOSUB convert
  415.     LINE (centerx, centery)-(x, y), yhat(4)
  416.     x = 50 * zhatp(1): y = 50 * zhatp(2): GOSUB convert
  417.     LINE (centerx, centery)-(x, y), zhat(4)
  418.     COLOR 14
  419.     LOCATE 25, 68: PRINT "-   VIEW   -"
  420.     COLOR 15
  421.     LOCATE 26, 68: PRINT "  8  "
  422.     LOCATE 27, 68: PRINT "4   6"
  423.     LOCATE 28, 68: PRINT "  2  "
  424.     COLOR 7
  425.     LOCATE 26, 75: PRINT "7   9"
  426.     LOCATE 27, 75: PRINT "     "
  427.     LOCATE 28, 75: PRINT "1   3"
  428. IF toggletimealert = 1 THEN
  429.     COLOR 7
  430.     LOCATE 1, 25: PRINT "Press 'T' to toggle animation."
  431.     LOCATE 2, 25: PRINT "Use numeric keypad to rotate."
  432.     LOCATE 3, 25: PRINT "      Press G to reset."
  433.  
  434. store.SCREEN.projections:
  435. xhatp.old(1) = xhatp(1): xhatp.old(2) = xhatp(2)
  436. yhatp.old(1) = yhatp(1): yhatp.old(2) = yhatp(2)
  437. zhatp.old(1) = zhatp(1): zhatp.old(2) = zhatp(2)
  438. FOR i = 1 TO numparticlevisible
  439.     vecvisiblepuvs.old(i, 1) = vecvisiblepuvs(i, 1)
  440.     vecvisiblepuvs.old(i, 2) = vecvisiblepuvs(i, 2)
  441. numparticlevisible.old = numparticlevisible
  442.  
  443. plotmode.simplemesh:
  444. FOR i = 1 TO numparticlevisible - 1
  445.     IF i MOD yrange <> 0 THEN 'point obeys normal neighbor-connect scheme
  446.         ' Erase old graphics.
  447.         x = zoom * vecvisiblepuvs.old(i, 1): y = zoom * vecvisiblepuvs.old(i, 2): GOSUB convert: x1 = x: y1 = y
  448.         x = zoom * vecvisiblepuvs.old(i + 1, 1): y = zoom * vecvisiblepuvs.old(i + 1, 2): GOSUB convert: x2 = x: y2 = y
  449.         x = zoom * vecvisiblepuvs.old(i + yrange, 1): y = zoom * vecvisiblepuvs.old(i + yrange, 2): GOSUB convert: x3 = x: y3 = y
  450.         LINE (x1, y1)-(x2, y2), 0
  451.         IF i < (numparticlevisible - yrange) THEN LINE (x1, y1)-(x3, y3), 0
  452.         ' Draw new graphics.
  453.         x = zoom * vecvisiblepuvs(i, 1): y = zoom * vecvisiblepuvs(i, 2): GOSUB convert: x1 = x: y1 = y
  454.         x = zoom * vecvisiblepuvs(i + 1, 1): y = zoom * vecvisiblepuvs(i + 1, 2): GOSUB convert: x2 = x: y2 = y
  455.         x = zoom * vecvisiblepuvs(i + yrange, 1): y = zoom * vecvisiblepuvs(i + yrange, 2): GOSUB convert: x3 = x: y3 = y
  456.         LINE (x1, y1)-(x2, y2), vecvisible(i, 4)
  457.         IF i < (numparticlevisible - yrange) THEN LINE (x1, y1)-(x3, y3), vecvisible(i, 4)
  458.     ELSE 'point does not obey normal neighbor-connect scheme
  459.         ' Erase old graphics.
  460.         x = zoom * vecvisiblepuvs.old(i, 1): y = zoom * vecvisiblepuvs.old(i, 2): GOSUB convert: x1 = x: y1 = y
  461.         x = zoom * vecvisiblepuvs.old(i + yrange, 1): y = zoom * vecvisiblepuvs.old(i + yrange, 2): GOSUB convert: x3 = x: y3 = y
  462.         IF i < (numparticlevisible - yrange + 1) THEN LINE (x1, y1)-(x3, y3), 0
  463.         ' Draw new graphics.
  464.         x = zoom * vecvisiblepuvs(i, 1): y = zoom * vecvisiblepuvs(i, 2): GOSUB convert: x1 = x: y1 = y
  465.         x = zoom * vecvisiblepuvs(i + yrange, 1): y = zoom * vecvisiblepuvs(i + yrange, 2): GOSUB convert: x3 = x: y3 = y
  466.         IF i < (numparticlevisible - yrange + 1) THEN LINE (x1, y1)-(x3, y3), vecvisible(i, 4)
  467.     END IF
  468.  
  469. genschemeUSAcolors:
  470. 'delinearize
  471. pcountparticleorig = 0
  472. FOR i = 1 TO xrange
  473.     FOR j = 1 TO yrange
  474.         pcountparticleorig = pcountparticleorig + 1
  475.         vec2dztemp(i, j) = vec(pcountparticleorig, 4)
  476.     NEXT
  477. FOR i = 1 TO xrange
  478.     FOR jj = 0 TO 12 STEP 2
  479.         FOR j = jj * yrange / 13 + 1 TO (jj + 1) * yrange / 13
  480.             vec2dztemp(i, j) = 4
  481.         NEXT
  482.     NEXT
  483.     FOR jj = 1 TO 11 STEP 2
  484.         FOR j = jj * yrange / 13 + 1 TO (jj + 1) * yrange / 13
  485.             vec2dztemp(i, j) = 7
  486.         NEXT
  487.     NEXT
  488. starflag = -1
  489. FOR i = 1 TO xrange * .76 / 1.9
  490.     FOR j = yrange TO yrange * .5385 STEP -1
  491.         IF starflag = 1 THEN
  492.             vec2dztemp(i, j) = 15
  493.         ELSE
  494.             vec2dztemp(i, j) = 1
  495.         END IF
  496.         starflag = -starflag
  497.     NEXT
  498. 'relinearize
  499. pcountparticleorig = 0
  500. FOR i = 1 TO xrange
  501.     FOR j = 1 TO yrange
  502.         pcountparticleorig = pcountparticleorig + 1
  503.         vec(pcountparticleorig, 4) = vec2dztemp(i, j)
  504.     NEXT
  505.  
  506. genscheme.wave2d.init:
  507. xl = -1.9: xr = 1.9
  508. yl = -1: yr = 1
  509. xl = xl * 4: xr = xr * 4: yl = yl * 4: yr = yr * 4
  510. Dx = .32
  511. Dy = .32
  512. xrange = 1 + INT((-xl + xr) / Dx)
  513. yrange = 1 + INT((-yl + yr) / Dy)
  514. alpha = .25
  515. pcountparticleorig = 0
  516. FOR i = xl TO xr STEP Dx
  517.     FOR j = yl TO yr STEP Dy
  518.         pcountparticleorig = pcountparticleorig + 1
  519.         vec(pcountparticleorig, 1) = i
  520.         vec(pcountparticleorig, 2) = j
  521.         vec(pcountparticleorig, 3) = 0
  522.         '*' vec(pcountparticleorig, 4) = 14 'use special color scheme
  523.     NEXT
  524.  
  525. genscheme.wave2d.gridinit:
  526. 'delinearize
  527. pcountparticleorig = 0
  528. FOR i = 1 TO xrange
  529.     FOR j = 1 TO yrange
  530.         pcountparticleorig = pcountparticleorig + 1
  531.         vec2dztemp(i, j) = vec(pcountparticleorig, 3)
  532.     NEXT
  533. 'initial position condition
  534. 'FOR i = 1 TO xrange 'random high points
  535. '  FOR j = 1 TO yrange
  536. '      nrand = RND * 1000
  537. '      IF nrand < 10 THEN
  538. '          vec2dz(i, j) = 5
  539. '      END IF
  540. '  NEXT
  541. 'NEXT
  542. 'vec2dz(xrange * .8, yrange * .2) = -2.5 'single plucked point
  543. 'FOR i = 1 TO xrange 'cross arm
  544. '   vec2dz(i, yrange / 3) = 2
  545. 'NEXT
  546. 'FOR j = 1 TO yrange 'cross arm
  547. '   vec2dz(xrange / 2, j) = 1
  548. 'NEXT
  549. 'sync
  550. pcountparticleorig = 0
  551. FOR i = 1 TO xrange
  552.     FOR j = 1 TO yrange
  553.         pcountparticleorig = pcountparticleorig + 1
  554.         vec2dzprev(i, j) = vec2dz(i, j)
  555.         vec2dztemp(i, j) = vec2dz(i, j)
  556.     NEXT
  557. 'initial velocity condition
  558. vec2dzprev(xrange * .8, yrange * .8) = 1.5 'single struck point
  559. 'relinearize
  560. pcountparticleorig = 0
  561. FOR i = 1 TO xrange
  562.     FOR j = 1 TO yrange
  563.         pcountparticleorig = pcountparticleorig + 1
  564.         vec(pcountparticleorig, 3) = vec2dz(i, j)
  565.     NEXT
  566.  
  567. genscheme.wave2d.timeanimate:
  568. 'delinearize
  569. pcountparticleorig = 0
  570. FOR i = 1 TO xrange
  571.     FOR j = 1 TO yrange
  572.         pcountparticleorig = pcountparticleorig + 1
  573.         vec2dztemp(i, j) = vec(pcountparticleorig, 3)
  574.     NEXT
  575. 'begin propagation process
  576. FOR i = 2 TO xrange - 1 'boDy, no edges
  577.     FOR j = 2 TO yrange - 1
  578.         wp1 = alpha * (vec2dztemp(i + 1, j) + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  579.         wp2 = alpha * (vec2dztemp(i, j + 1) + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  580.         vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  581.     NEXT
  582. 'comment out this section for fixed edges (or pieces of this section)
  583. i = 1 'left edge
  584. FOR j = 2 TO yrange - 1
  585.     wfp = vec2dztemp(i, j)
  586.     wp1 = alpha * (vec2dztemp(i + 1, j) + wfp) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  587.     wp2 = alpha * (vec2dztemp(i, j + 1) + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  588.     'vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  589. i = xrange 'right edge
  590. FOR j = 2 TO yrange - 1
  591.     wfp = vec2dztemp(i, j)
  592.     wp1 = alpha * (wfp + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  593.     wp2 = alpha * (vec2dztemp(i, j + 1) + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  594.     vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  595. j = 1 'bottom edge
  596. FOR i = 2 TO xrange - 1
  597.     wfp = vec2dztemp(i, j)
  598.     wp2 = alpha * (vec2dztemp(i, j + 1) + wfp) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  599.     wp1 = alpha * (vec2dztemp(i + 1, j) + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  600.     vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  601. j = yrange 'top edge
  602. FOR i = 2 TO xrange - 1
  603.     wfp = vec2dztemp(i, j)
  604.     wp2 = alpha * (wfp + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  605.     wp1 = alpha * (vec2dztemp(i + 1, j) + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  606.     vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  607. 'bottom left corner
  608. i = 1: j = 1
  609. wfp1 = vec2dztemp(i, j)
  610. wfp2 = vec2dztemp(i, j)
  611. wp1 = alpha * (vec2dztemp(i + 1, j) + wfp1) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  612. wp2 = alpha * (vec2dztemp(i, j + 1) + wfp2) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  613. 'vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  614. 'bottom right corner
  615. i = xrange: j = 1
  616. wfp1 = vec2dztemp(i, j)
  617. wfp2 = vec2dztemp(i, j)
  618. wp1 = alpha * (wfp1 + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  619. wp2 = alpha * (vec2dztemp(i, j + 1) + wfp2) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  620. vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  621. 'top left corner
  622. i = 1: j = yrange
  623. wfp1 = vec2dztemp(i, j)
  624. wfp2 = vec2dztemp(i, j)
  625. wp1 = alpha * (vec2dztemp(i + 1, j) + wfp1) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  626. wp2 = alpha * (wfp2 + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  627. 'vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  628. 'top right corner
  629. i = xrange: j = yrange
  630. wfp1 = vec2dztemp(i, j)
  631. wfp2 = vec2dztemp(i, j)
  632. wp1 = alpha * (wfp1 + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  633. wp2 = alpha * (wfp2 + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  634. vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  635. 'start special movements
  636. T = timevar / 5
  637. IF T < pi THEN 'wave left edge just once
  638.     FOR j = 1 TO yrange
  639.         i = 1
  640.         vec2dz(i, j) = (j / yrange) * 1.5 * SIN(T)
  641.     NEXT
  642. IF T < pi THEN 'wave bottom edge just once
  643.     FOR i = 1 TO xrange
  644.         j = 1
  645.         vec2dz(i, j) = (i / xrange) * .45 * SIN(T)
  646.     NEXT
  647. 'relinearize
  648. pcountparticleorig = 0
  649. FOR i = 1 TO xrange
  650.     FOR j = 1 TO yrange
  651.         pcountparticleorig = pcountparticleorig + 1
  652.         vec2dzprev(i, j) = vec2dztemp(i, j)
  653.         vec2dztemp(i, j) = vec2dz(i, j)
  654.         vec(pcountparticleorig, 3) = vec2dz(i, j)
  655.     NEXT
  656.  
  657.  
Title: Re: U.S. Flag
Post by: bplus on May 12, 2020, 03:28:11 pm
I just found Static's wavy flag I have on my computer, which you can find on a reply to Petr's other flag post here:


https://www.qb64.org/forum/index.php?topic=44.msg276#msg276
 (https://www.qb64.org/forum/index.php?topic=44.msg276#msg276)

That link leads to file not found? Do you have the code? Update: Why yes you do! :)

Here is nice one by Ashish mod of one I started:
https://www.qb64.org/forum/index.php?topic=1384.msg105761#msg105761
Title: Re: U.S. Flag
Post by: SierraKen on May 12, 2020, 05:44:53 pm
Incredible bplus and Ashish! Good job.
Title: Re: U.S. Flag
Post by: _vince on May 13, 2020, 10:31:52 am


Pete

I'd like to see this one but generated from a single flat 2D image in QB64, would be more impressive without GL.  Then you wouldn't even need the image because the stars and stripes are fairly easy to draw.
Title: Re: U.S. Flag
Post by: _vince on May 15, 2020, 01:16:26 am
Ok, I went for it.  I used these instructions for drawing the flag:  https://en.wikipedia.org/wiki/Flag_of_the_United_States#Specifications (https://en.wikipedia.org/wiki/Flag_of_the_United_States#Specifications)

Code: QB64: [Select]
  1. deflng a-z
  2.  
  3. sw = 640
  4. sh = 480
  5.  
  6. pi = 4*atn(1)
  7.  
  8. screen _newimage(sw, sh*2, 32)
  9.  
  10. h = 300
  11. w = 1.9*h
  12. a = h/7
  13.  
  14. img = _newimage(w, h, 32)
  15. _dest img
  16. x0 = 0
  17. y0 = 0
  18.  
  19. line (0, 0)-step(w, h),_rgb(255,255,255),bf
  20. for i=0 to 6
  21.         line (0, i*h*2/13)-step(w, h/13),_rgb(255*0.698,255*0.132,255*0.203),bf
  22. line (0, 0)-step(w*2/5, h*7/13),_rgb(255*0.234,255*0.233,255*0.430),bf
  23.  
  24. for i=0 to 4
  25. for j=0 to 5
  26.         starf (j*2 + 1)*w*2/(5*12), (i*2 + 1)*h*7/130, h*4/(13*5*2), _rgb(255,255,255)
  27.  
  28. for i=1 to 4
  29. for j=1 to 5
  30.         starf (j*2)*w*2/(5*12), (i*2)*h*7/130, h*4/(13*5*2), _rgb(255,255,255)
  31.  
  32. _putimage (sw/2 - w/2, sh/2 - h/2), img
  33.  
  34. x0 = sw/2 - w/2
  35. y0 = sh/2 - h/2 + sh
  36.  
  37.  
  38.         t = t + 0.2
  39.  
  40.         line (0,sh)-step(sw, sh),_rgb(0,0,0),bf
  41.  
  42.         for y=0 to h + a*0.707 step 1
  43.         for x=0 to w + a*0.707 step 1
  44.                 z = (0.1 + 0.4*(x/w))*a*sin(x/35 - y/70 - t) + 0.5*a
  45.                 dz = 50*a*cos(x/35 - y/70 - t)/35
  46.  
  47.                 xx = x + z*0.707 - a*0.707
  48.                 yy = y - z*0.707
  49.  
  50.                 if (int(xx) >=0 and int(xx) < w - 1 and int(yy) >= 0 and int(yy) < h - 1) then
  51.                         tl = point(int(xx), int(yy))
  52.                         tr = point(int(xx) + 1, int(yy))
  53.                         bl = point(int(xx), int(yy) + 1)
  54.                         br = point(int(xx) + 1, int(yy) + 1)
  55.  
  56.                         dx = xx - int(xx)
  57.                         dy = yy - int(yy)
  58.  
  59.                         r =_round((1 - dy)*((1 - dx)*  _red(tl) + dx*  _red(tr)) + dy*((1 - dx)*  _red(bl) + dx*  _red(br)))
  60.                         g = _round((1 - dy)*((1 - dx)*_green(tl) + dx*_green(tr)) + dy*((1 - dx)*_green(bl) + dx*_green(br)))
  61.                         b = _round((1 - dy)*((1 - dx)* _blue(tl) + dx* _blue(tr)) + dy*((1 - dx)* _blue(bl) + dx* _blue(br)))
  62.  
  63.                         r = r + dz
  64.                         g = g + dz
  65.                         b = b + dz
  66.  
  67.                         if r<0 then r = 0
  68.                         if r>255 then r = 255
  69.                         if g<0 then g = 0
  70.                         if g>255 then g = 255
  71.                         if b<0 then b = 0
  72.                         if b>255 then b = 255
  73.  
  74.                         pset (x0 + x, y0 - a*0.707 + y), _rgb(r,g,b)
  75.                 end if
  76.         next
  77.         next
  78.  
  79.         _display
  80.         _limit 50
  81.  
  82.  
  83. sub starf(x, y, r, c)
  84.         pset (x + r*cos(pi/2), y - r*sin(pi/2)),c
  85.         for i = 0 to 5
  86.                 xx = r*cos(i*4*pi/5 + pi/2)
  87.                 yy = r*sin(i*4*pi/5 + pi/2)
  88.                 line -(x + xx, y - yy),c
  89.         next
  90.         paint (x, y),c
  91.         for i = 0 to 5
  92.                 xx = r*cos(i*4*pi/5 + pi/2)/2
  93.                 yy = r*sin(i*4*pi/5 + pi/2)/2
  94.                 paint (x + xx, y - yy),c
  95.         next
  96.  
Title: Re: U.S. Flag
Post by: Ashish on May 15, 2020, 02:24:48 am
@vince Brilliant!
I think it could also be done if one :-
1.  Create the US Flag image
2. Divide the image into many smaller rectangles and store its coordinates
3. Use _maptriangle 3d command and oscillate the z value with sin() or cos().
Title: Re: U.S. Flag
Post by: STxAxTIC on May 15, 2020, 04:18:55 am
Nice work boys.

Here's one that obeys the wave equation and plots in 3D:

Code: QB64: [Select]
  1. '#lang "qb" '...for freebasic compiler. Keep disabled for QB64.
  2.  
  3. ' *** Video settings. ***
  4.  
  5. screenwidth = 640
  6. screenheight = 480
  7.  
  8. ' *** Performance settings. ***
  9.  
  10. bignumber = 500000 ' Maximum objects per array (determined by memory).
  11. globaldelayinit = 1000 ' Loop damping factor (fine adjustment below).
  12.  
  13. ' *** Initialize counters and array sizes. ***
  14.  
  15. numparticleorig = bignumber
  16. numparticlevisible = bignumber
  17.  
  18. ' *** Define basis arrays and structures. ***
  19.  
  20. ' Screen vectors in three-space.
  21. ' These vectors define the camera angle.
  22. DIM uhat(1 TO 3), vhat(1 TO 3), nhat(1 TO 3)
  23.  
  24. ' Basis vectors defined in three-space.
  25. DIM xhat(1 TO 4), yhat(1 TO 4), zhat(1 TO 4)
  26. xhat(1) = 1: xhat(2) = 0: xhat(3) = 0: xhat(4) = 4
  27. yhat(1) = 0: yhat(2) = 1: yhat(3) = 0: yhat(4) = 2
  28. zhat(1) = 0: zhat(2) = 0: zhat(3) = 1: zhat(4) = 1
  29.  
  30. ' Basis vectors projected into uv two-space.
  31. DIM xhatp(1 TO 2), yhatp(1 TO 2), zhatp(1 TO 2)
  32. DIM xhatp.old(1 TO 2), yhatp.old(1 TO 2), zhatp.old(1 TO 2)
  33.  
  34. ' *** Define particle arrays and structures. ***
  35.  
  36. ' Particle vectors defined in three-space.
  37. DIM vec(numparticleorig, 4)
  38. DIM vecdotnhat(numparticleorig)
  39. DIM vecdotnhatunit.old(numparticleorig)
  40. DIM vecvisible(numparticlevisible, 4)
  41. DIM vecvisibledotnhat(numparticlevisible)
  42. DIM vecvisibledotnhatunit.old(numparticlevisible)
  43.  
  44. ' Particle vectors projected onto infinite uv two-space.
  45. DIM vecpuv(numparticleorig, 1 TO 2)
  46. DIM vecpuv.old(numparticleorig, 1 TO 2)
  47. DIM vecvisiblepuv(numparticlevisible, 1 TO 2)
  48. DIM vecvisiblepuv.old(numparticlevisible, 1 TO 2)
  49.  
  50. ' Particle projections adjusted for screen uv two-space.
  51. DIM vecpuvs(numparticleorig, 1 TO 2)
  52. DIM vecpuvs.old(numparticleorig, 1 TO 2)
  53. DIM vecvisiblepuvs(numparticlevisible, 1 TO 2)
  54. DIM vecvisiblepuvs.old(numparticlevisible, 1 TO 2)
  55.  
  56. ' *** Define specialized arrays and structures. ***
  57.  
  58. ' Arrays for tech 2 mesh plotting.
  59. DIM plotflag(numparticleorig)
  60. DIM plotflag.old(numparticleorig)
  61.  
  62. ' *** Set mathematical constants. ***
  63.  
  64. pi = 3.1415926536
  65. ee = 2.7182818285
  66.  
  67. mainstart:
  68.  
  69. ' *** Initialize user input variables. ***
  70. key$ = ""
  71. 'mousekey$ = ""
  72.  
  73. ' *** Process first user input. ***
  74.  
  75. a$ = "13"
  76.  
  77.     CASE "13": genscheme$ = "wave2d": plotmode$ = "simplemesh"
  78.  
  79. substart:
  80.  
  81. ' *** Zero counters and array sizes. ***
  82.  
  83. numparticleorig = 0
  84. numparticlevisible = 0
  85.  
  86. ' *** Constants and switch control. ***
  87.  
  88. ' Perspective and animation switches/defaults.
  89. centerx = screenwidth / 2
  90. centery = screenheight / 2
  91. speedconst = 50
  92. falsedepth = .01
  93. zoom = 30
  94. timevar = 0
  95. T = 0
  96. togglehud = 1
  97. toggleatomnumbers = -1
  98. toggletimeanimate = -1
  99. toggletimealert = 0
  100. camx = 0
  101. camy = 0
  102. camz = 0
  103. uhat(1) = -3: uhat(2) = 5: uhat(3) = 1 / 4
  104. vhat(1) = -1: vhat(2) = -1: vhat(3) = 8
  105.  
  106.  
  107. SELECT CASE LCASE$(genscheme$)
  108.     CASE "wave2d":
  109.         globaldelay = globaldelayinit * 1500
  110.         uhat(1) = .7802773: uhat(2) = -.4759201: uhat(3) = .4058135
  111.         vhat(1) = .2502121: vhat(2) = .8321912: vhat(3) = .4948249
  112.         togglehud = 1
  113.         toggletimealert = 1
  114.         GOSUB genscheme.wave2d.init
  115.         numparticleorig = pcountparticleorig
  116.         REDIM vec2dz(xrange, yrange)
  117.         REDIM vec2dztemp(xrange, yrange)
  118.         REDIM vec2dzprev(xrange, yrange)
  119.         GOSUB genschemeUSAcolors
  120.         GOSUB genscheme.wave2d.gridinit
  121.  
  122. ' Move objects to accomodate initial camera position.
  123. IF camx <> 0 AND camy <> 0 AND camz <> 0 THEN
  124.     FOR i = 1 TO numparticleorig
  125.         vec(i, 1) = vec(i, 1) + camx
  126.         vec(i, 2) = vec(i, 2) + camy
  127.         vec(i, 3) = vec(i, 3) + camz
  128.     NEXT
  129.  
  130. GOSUB redraw
  131.  
  132. ' *** Begin main loop. ***
  133.     IF toggletimeanimate = 1 THEN
  134.         GOSUB timeanimate
  135.         flagredraw = 1
  136.     END IF
  137.     IF flagredraw = 1 THEN
  138.         GOSUB redraw
  139.         flagredraw = -1
  140.     END IF
  141.     GOSUB keyprocess
  142.     IF toggletimeanimate = 1 THEN
  143.         FOR delaycount = 1 TO globaldelay: NEXT
  144.     END IF
  145. ' *** End main loop. ***
  146.  
  147. ' *** Begin function definitions. ***
  148.  
  149. ' Comment out the conents of this gosub for non-QB64 compiler.
  150. mouseprocess:
  151.  
  152. keyprocess:
  153. IF key$ <> "" THEN
  154.     flagredraw = 1
  155.     CASE "8":
  156.         GOSUB rotate.vhat.plus
  157.     CASE "2":
  158.         GOSUB rotate.vhat.minus
  159.     CASE "4":
  160.         GOSUB rotate.uhat.minus
  161.     CASE "6":
  162.         GOSUB rotate.uhat.plus
  163.     CASE "7":
  164.         GOSUB rotate.clockwise
  165.     CASE "9":
  166.         GOSUB rotate.counterclockwise
  167.     CASE "1":
  168.         GOSUB rotate.uhat.minus: GOSUB normalize.screen.vectors: GOSUB rotate.clockwise
  169.     CASE "3":
  170.         GOSUB rotate.uhat.plus: GOSUB normalize.screen.vectors: GOSUB rotate.counterclockwise
  171.     CASE "q"
  172.         GOSUB strafe.objects.vhat.plus
  173.         GOSUB strafe.camera.vhat.plus
  174.     CASE "e"
  175.         GOSUB strafe.objects.vhat.minus
  176.         GOSUB strafe.camera.vhat.minus
  177.     CASE "x"
  178.         uhat(1) = 0: uhat(2) = 1: uhat(3) = 0
  179.         vhat(1) = 0: vhat(2) = 0: vhat(3) = 1
  180.     CASE "y"
  181.         uhat(1) = 0: uhat(2) = 0: uhat(3) = 1
  182.         vhat(1) = 1: vhat(2) = 0: vhat(3) = 0
  183.     CASE "z"
  184.         uhat(1) = 1: uhat(2) = 0: uhat(3) = 0
  185.         vhat(1) = 0: vhat(2) = 1: vhat(3) = 0
  186.     CASE "t"
  187.         toggletimeanimate = -toggletimeanimate
  188.     CASE "r"
  189.         timevar = 0
  190.     CASE "f"
  191.         GOTO substart
  192.     CASE "g"
  193.         GOTO mainstart
  194.     CASE "-"
  195.         globaldelay = globaldelay * 1.1
  196.     CASE "="
  197.         globaldelay = globaldelay * 0.9
  198.     CASE "`"
  199.         globaldelayinit = globaldelay
  200.     CASE " "
  201.         togglehud = -togglehud
  202.         CLS
  203.     CASE CHR$(27)
  204.         END
  205.  
  206. convert:
  207. ' Convert graphics from uv-cartesian coordinates to monitor coordinates.
  208. x0 = x: y0 = y
  209. x = x0 + centerx
  210. y = -y0 + centery
  211.  
  212. ' *** Define functions for view translation and rotation. ***
  213.  
  214. rotate.uhat.plus:
  215. uhat(1) = nhat(1) + speedconst * uhat(1)
  216. uhat(2) = nhat(2) + speedconst * uhat(2)
  217. uhat(3) = nhat(3) + speedconst * uhat(3)
  218.  
  219. rotate.uhat.minus:
  220. uhat(1) = -nhat(1) + speedconst * uhat(1)
  221. uhat(2) = -nhat(2) + speedconst * uhat(2)
  222. uhat(3) = -nhat(3) + speedconst * uhat(3)
  223.  
  224. rotate.vhat.plus:
  225. vhat(1) = nhat(1) + speedconst * vhat(1)
  226. vhat(2) = nhat(2) + speedconst * vhat(2)
  227. vhat(3) = nhat(3) + speedconst * vhat(3)
  228.  
  229. rotate.vhat.minus:
  230. vhat(1) = -nhat(1) + speedconst * vhat(1)
  231. vhat(2) = -nhat(2) + speedconst * vhat(2)
  232. vhat(3) = -nhat(3) + speedconst * vhat(3)
  233.  
  234. rotate.counterclockwise:
  235. v1 = vhat(1)
  236. v2 = vhat(2)
  237. v3 = vhat(3)
  238. vhat(1) = uhat(1) + speedconst * vhat(1)
  239. vhat(2) = uhat(2) + speedconst * vhat(2)
  240. vhat(3) = uhat(3) + speedconst * vhat(3)
  241. uhat(1) = -v1 + speedconst * uhat(1)
  242. uhat(2) = -v2 + speedconst * uhat(2)
  243. uhat(3) = -v3 + speedconst * uhat(3)
  244.  
  245. rotate.clockwise:
  246. v1 = vhat(1)
  247. v2 = vhat(2)
  248. v3 = vhat(3)
  249. vhat(1) = -uhat(1) + speedconst * vhat(1)
  250. vhat(2) = -uhat(2) + speedconst * vhat(2)
  251. vhat(3) = -uhat(3) + speedconst * vhat(3)
  252. uhat(1) = v1 + speedconst * uhat(1)
  253. uhat(2) = v2 + speedconst * uhat(2)
  254. uhat(3) = v3 + speedconst * uhat(3)
  255.  
  256. strafe.objects.uhat.plus:
  257. FOR i = 1 TO numparticleorig
  258.     vec(i, 1) = vec(i, 1) + uhat(1) * 1 / zoom
  259.     vec(i, 2) = vec(i, 2) + uhat(2) * 1 / zoom
  260.     vec(i, 3) = vec(i, 3) + uhat(3) * 1 / zoom
  261.  
  262. strafe.objects.uhat.minus:
  263. FOR i = 1 TO numparticleorig
  264.     vec(i, 1) = vec(i, 1) - uhat(1) * 1 / zoom
  265.     vec(i, 2) = vec(i, 2) - uhat(2) * 1 / zoom
  266.     vec(i, 3) = vec(i, 3) - uhat(3) * 1 / zoom
  267.  
  268. strafe.objects.vhat.plus:
  269. FOR i = 1 TO numparticleorig
  270.     vec(i, 1) = vec(i, 1) + vhat(1) * 1 / zoom
  271.     vec(i, 2) = vec(i, 2) + vhat(2) * 1 / zoom
  272.     vec(i, 3) = vec(i, 3) + vhat(3) * 1 / zoom
  273.  
  274. strafe.objects.vhat.minus:
  275. FOR i = 1 TO numparticleorig
  276.     vec(i, 1) = vec(i, 1) - vhat(1) * 1 / zoom
  277.     vec(i, 2) = vec(i, 2) - vhat(2) * 1 / zoom
  278.     vec(i, 3) = vec(i, 3) - vhat(3) * 1 / zoom
  279.  
  280. strafe.objects.nhat.plus:
  281. FOR i = 1 TO numparticleorig
  282.     vec(i, 1) = vec(i, 1) + nhat(1) * 1 / zoom
  283.     vec(i, 2) = vec(i, 2) + nhat(2) * 1 / zoom
  284.     vec(i, 3) = vec(i, 3) + nhat(3) * 1 / zoom
  285.  
  286. strafe.objects.nhat.minus:
  287. FOR i = 1 TO numparticleorig
  288.     vec(i, 1) = vec(i, 1) - nhat(1) * 1 / zoom
  289.     vec(i, 2) = vec(i, 2) - nhat(2) * 1 / zoom
  290.     vec(i, 3) = vec(i, 3) - nhat(3) * 1 / zoom
  291.  
  292. strafe.camera.uhat.plus:
  293. camx = camx + uhat(1) * 1 / zoom
  294. camy = camy + uhat(2) * 1 / zoom
  295. camz = camz + uhat(3) * 1 / zoom
  296.  
  297. strafe.camera.uhat.minus:
  298. camx = camx - uhat(1) * 1 / zoom
  299. camy = camy - uhat(2) * 1 / zoom
  300. camz = camz - uhat(3) * 1 / zoom
  301.  
  302. strafe.camera.vhat.plus:
  303. camx = camx + vhat(1) * 1 / zoom
  304. camy = camy + vhat(2) * 1 / zoom
  305. camz = camz + vhat(3) * 1 / zoom
  306.  
  307. strafe.camera.vhat.minus:
  308. camx = camx - vhat(1) * 1 / zoom
  309. camy = camy - vhat(2) * 1 / zoom
  310. camz = camz - vhat(3) * 1 / zoom
  311.  
  312. strafe.camera.nhat.plus:
  313. camx = camx + nhat(1) * 1 / zoom
  314. camy = camy + nhat(2) * 1 / zoom
  315. camz = camz + nhat(3) * 1 / zoom
  316.  
  317. strafe.camera.nhat.minus:
  318. camx = camx - nhat(1) * 1 / zoom
  319. camy = camy - nhat(2) * 1 / zoom
  320. camz = camz - nhat(3) * 1 / zoom
  321.  
  322. ' *** Define core functions. ***
  323.  
  324. timeanimate:
  325. timevar = timevar + 1
  326. IF timevar > 10 ^ 6 THEN timevar = 1
  327. SELECT CASE genscheme$
  328.     CASE "wave2d": GOSUB genscheme.wave2d.timeanimate
  329.  
  330. normalize.screen.vectors:
  331. 'normalize the two vectors that define the screen orientation
  332. uhatmag = SQR(uhat(1) ^ 2 + uhat(2) ^ 2 + uhat(3) ^ 2)
  333. uhat(1) = uhat(1) / uhatmag: uhat(2) = uhat(2) / uhatmag: uhat(3) = uhat(3) / uhatmag
  334. vhatmag = SQR(vhat(1) ^ 2 + vhat(2) ^ 2 + vhat(3) ^ 2)
  335. vhat(1) = vhat(1) / vhatmag: vhat(2) = vhat(2) / vhatmag: vhat(3) = vhat(3) / vhatmag
  336. uhatdotvhat = uhat(1) * vhat(1) + uhat(2) * vhat(2) + uhat(3) * vhat(3)
  337. IF SQR(uhatdotvhat ^ 2) > .0005 THEN
  338.     CLS: COLOR 15: LOCATE 5, 5: PRINT "Screen vectors are not perpendicular. Press ESC to quit."
  339.     'DO: LOOP UNTIL INKEY$ = CHR$(27): END
  340. ' Compute the normal vector to the view plane.
  341. ' The normal vector points toward the eye, away from view frustum.
  342. nhat(1) = uhat(2) * vhat(3) - uhat(3) * vhat(2)
  343. nhat(2) = uhat(3) * vhat(1) - uhat(1) * vhat(3)
  344. nhat(3) = uhat(1) * vhat(2) - uhat(2) * vhat(1)
  345. nhatmag = SQR(nhat(1) ^ 2 + nhat(2) ^ 2 + nhat(3) ^ 2)
  346. nhat(1) = nhat(1) / nhatmag: nhat(2) = nhat(2) / nhatmag: nhat(3) = nhat(3) / nhatmag
  347.  
  348. redraw:
  349. GOSUB normalize.screen.vectors
  350. ' Project the three-space basis vectors onto the screen plane.
  351. xhatp(1) = xhat(1) * uhat(1) + xhat(2) * uhat(2) + xhat(3) * uhat(3)
  352. xhatp(2) = xhat(1) * vhat(1) + xhat(2) * vhat(2) + xhat(3) * vhat(3)
  353. yhatp(1) = yhat(1) * uhat(1) + yhat(2) * uhat(2) + yhat(3) * uhat(3)
  354. yhatp(2) = yhat(1) * vhat(1) + yhat(2) * vhat(2) + yhat(3) * vhat(3)
  355. zhatp(1) = zhat(1) * uhat(1) + zhat(2) * uhat(2) + zhat(3) * uhat(3)
  356. zhatp(2) = zhat(1) * vhat(1) + zhat(2) * vhat(2) + zhat(3) * vhat(3)
  357. IF numparticleorig > 0 THEN
  358.     GOSUB compute.visible.particles
  359.     GOSUB project.particles
  360.     GOSUB depth.adjust.particles
  361. GOSUB draw.all.objects
  362. GOSUB store.screen.projections
  363.  
  364. reverse.uvnhat:
  365. uhat(1) = -uhat(1)
  366. uhat(2) = -uhat(2)
  367. uhat(3) = -uhat(3)
  368. GOSUB normalize.screen.vectors
  369.  
  370. compute.visible.particles:
  371. numparticlevisible = 0
  372. FOR i = 1 TO numparticleorig
  373.     IF falsedepth = 0 THEN
  374.     ELSE
  375.         numparticlevisible = numparticlevisible + 1
  376.         vecvisible(numparticlevisible, 1) = vec(i, 1)
  377.         vecvisible(numparticlevisible, 2) = vec(i, 2)
  378.         vecvisible(numparticlevisible, 3) = vec(i, 3)
  379.         vecvisible(numparticlevisible, 4) = vec(i, 4)
  380.     END IF
  381.  
  382. project.particles:
  383. ' Project object vectors onto the screen plane.
  384. FOR i = 1 TO numparticlevisible
  385.     vecvisibledotnhat(i) = vecvisible(i, 1) * nhat(1) + vecvisible(i, 2) * nhat(2) + vecvisible(i, 3) * nhat(3)
  386.     vecvisiblepuv(i, 1) = (vecvisible(i, 1) * uhat(1) + vecvisible(i, 2) * uhat(2) + vecvisible(i, 3) * uhat(3))
  387.     vecvisiblepuv(i, 2) = (vecvisible(i, 1) * vhat(1) + vecvisible(i, 2) * vhat(2) + vecvisible(i, 3) * vhat(3))
  388.  
  389. depth.adjust.particles:
  390. IF falsedepth = 0 THEN
  391.     FOR i = 1 TO numparticlevisible
  392.         vecvisiblepuvs(i, 1) = vecvisiblepuv(i, 1) * fovd / vecvisibledotnhat(i)
  393.         vecvisiblepuvs(i, 2) = vecvisiblepuv(i, 2) * fovd / vecvisibledotnhat(i)
  394.     NEXT
  395.     FOR i = 1 TO numparticlevisible
  396.         vecvisiblepuvs(i, 1) = vecvisiblepuv(i, 1) * (1 + falsedepth * vecvisibledotnhat(i))
  397.         vecvisiblepuvs(i, 2) = vecvisiblepuv(i, 2) * (1 + falsedepth * vecvisibledotnhat(i))
  398.     NEXT
  399.  
  400. draw.all.objects:
  401. SELECT CASE plotmode$
  402.     CASE "simplemesh": GOSUB plotmode.simplemesh
  403. LOCATE 28, 23: PRINT "SPACE = toggle HUD,  ESC = quit."
  404. IF togglehud = 1 THEN
  405.     ' Replace basis vector triad.
  406.     x = 50 * xhatp.old(1): y = 50 * xhatp.old(2): GOSUB convert
  407.     LINE (centerx, centery)-(x, y), 0
  408.     x = 50 * yhatp.old(1): y = 50 * yhatp.old(2): GOSUB convert
  409.     LINE (centerx, centery)-(x, y), 0
  410.     x = 50 * zhatp.old(1): y = 50 * zhatp.old(2): GOSUB convert
  411.     LINE (centerx, centery)-(x, y), 0
  412.     x = 50 * xhatp(1): y = 50 * xhatp(2): GOSUB convert
  413.     LINE (centerx, centery)-(x, y), xhat(4)
  414.     x = 50 * yhatp(1): y = 50 * yhatp(2): GOSUB convert
  415.     LINE (centerx, centery)-(x, y), yhat(4)
  416.     x = 50 * zhatp(1): y = 50 * zhatp(2): GOSUB convert
  417.     LINE (centerx, centery)-(x, y), zhat(4)
  418.     COLOR 14
  419.     LOCATE 25, 68: PRINT "-   VIEW   -"
  420.     COLOR 15
  421.     LOCATE 26, 68: PRINT "  8  "
  422.     LOCATE 27, 68: PRINT "4   6"
  423.     LOCATE 28, 68: PRINT "  2  "
  424.     COLOR 7
  425.     LOCATE 26, 75: PRINT "7   9"
  426.     LOCATE 27, 75: PRINT "     "
  427.     LOCATE 28, 75: PRINT "1   3"
  428. IF toggletimealert = 1 THEN
  429.     COLOR 7
  430.     LOCATE 1, 25: PRINT "Press 'T' to toggle animation."
  431.     LOCATE 2, 25: PRINT "Use numeric keypad to rotate."
  432.     LOCATE 3, 25: PRINT "      Press G to reset."
  433.  
  434. store.screen.projections:
  435. xhatp.old(1) = xhatp(1): xhatp.old(2) = xhatp(2)
  436. yhatp.old(1) = yhatp(1): yhatp.old(2) = yhatp(2)
  437. zhatp.old(1) = zhatp(1): zhatp.old(2) = zhatp(2)
  438. FOR i = 1 TO numparticlevisible
  439.     vecvisiblepuvs.old(i, 1) = vecvisiblepuvs(i, 1)
  440.     vecvisiblepuvs.old(i, 2) = vecvisiblepuvs(i, 2)
  441. numparticlevisible.old = numparticlevisible
  442.  
  443. plotmode.simplemesh:
  444. FOR i = 1 TO numparticlevisible - 1
  445.     IF i MOD yrange <> 0 THEN 'point obeys normal neighbor-connect scheme
  446.         ' Erase old graphics.
  447.         x = zoom * vecvisiblepuvs.old(i, 1): y = zoom * vecvisiblepuvs.old(i, 2): GOSUB convert: x1 = x: y1 = y
  448.         x = zoom * vecvisiblepuvs.old(i + 1, 1): y = zoom * vecvisiblepuvs.old(i + 1, 2): GOSUB convert: x2 = x: y2 = y
  449.         x = zoom * vecvisiblepuvs.old(i + yrange, 1): y = zoom * vecvisiblepuvs.old(i + yrange, 2): GOSUB convert: x3 = x: y3 = y
  450.         LINE (x1, y1)-(x2, y2), 0
  451.         IF i < (numparticlevisible - yrange) THEN LINE (x1, y1)-(x3, y3), 0
  452.         ' Draw new graphics.
  453.         x = zoom * vecvisiblepuvs(i, 1): y = zoom * vecvisiblepuvs(i, 2): GOSUB convert: x1 = x: y1 = y
  454.         x = zoom * vecvisiblepuvs(i + 1, 1): y = zoom * vecvisiblepuvs(i + 1, 2): GOSUB convert: x2 = x: y2 = y
  455.         x = zoom * vecvisiblepuvs(i + yrange, 1): y = zoom * vecvisiblepuvs(i + yrange, 2): GOSUB convert: x3 = x: y3 = y
  456.         LINE (x1, y1)-(x2, y2), vecvisible(i, 4)
  457.         IF i < (numparticlevisible - yrange) THEN LINE (x1, y1)-(x3, y3), vecvisible(i, 4)
  458.     ELSE 'point does not obey normal neighbor-connect scheme
  459.         ' Erase old graphics.
  460.         x = zoom * vecvisiblepuvs.old(i, 1): y = zoom * vecvisiblepuvs.old(i, 2): GOSUB convert: x1 = x: y1 = y
  461.         x = zoom * vecvisiblepuvs.old(i + yrange, 1): y = zoom * vecvisiblepuvs.old(i + yrange, 2): GOSUB convert: x3 = x: y3 = y
  462.         IF i < (numparticlevisible - yrange + 1) THEN LINE (x1, y1)-(x3, y3), 0
  463.         ' Draw new graphics.
  464.         x = zoom * vecvisiblepuvs(i, 1): y = zoom * vecvisiblepuvs(i, 2): GOSUB convert: x1 = x: y1 = y
  465.         x = zoom * vecvisiblepuvs(i + yrange, 1): y = zoom * vecvisiblepuvs(i + yrange, 2): GOSUB convert: x3 = x: y3 = y
  466.         IF i < (numparticlevisible - yrange + 1) THEN LINE (x1, y1)-(x3, y3), vecvisible(i, 4)
  467.     END IF
  468.  
  469. genschemeUSAcolors:
  470. 'delinearize
  471. pcountparticleorig = 0
  472. FOR i = 1 TO xrange
  473.     FOR j = 1 TO yrange
  474.         pcountparticleorig = pcountparticleorig + 1
  475.         vec2dztemp(i, j) = vec(pcountparticleorig, 4)
  476.     NEXT
  477. FOR i = 1 TO xrange
  478.     FOR jj = 0 TO 12 STEP 2
  479.         FOR j = jj * yrange / 13 + 1 TO (jj + 1) * yrange / 13
  480.             vec2dztemp(i, j) = 4
  481.         NEXT
  482.     NEXT
  483.     FOR jj = 1 TO 11 STEP 2
  484.         FOR j = jj * yrange / 13 + 1 TO (jj + 1) * yrange / 13
  485.             vec2dztemp(i, j) = 7
  486.         NEXT
  487.     NEXT
  488. starflag = -1
  489. FOR i = 1 TO xrange * .76 / 1.9
  490.     FOR j = yrange TO yrange * .5385 STEP -1
  491.         IF starflag = 1 THEN
  492.             vec2dztemp(i, j) = 15
  493.         ELSE
  494.             vec2dztemp(i, j) = 1
  495.         END IF
  496.         starflag = -starflag
  497.     NEXT
  498. 'relinearize
  499. pcountparticleorig = 0
  500. FOR i = 1 TO xrange
  501.     FOR j = 1 TO yrange
  502.         pcountparticleorig = pcountparticleorig + 1
  503.         vec(pcountparticleorig, 4) = vec2dztemp(i, j)
  504.     NEXT
  505.  
  506. genscheme.wave2d.init:
  507. xl = -1.9: xr = 1.9
  508. yl = -1: yr = 1
  509. xl = xl * 4: xr = xr * 4: yl = yl * 4: yr = yr * 4
  510. Dx = .32
  511. Dy = .32
  512. xrange = 1 + INT((-xl + xr) / Dx)
  513. yrange = 1 + INT((-yl + yr) / Dy)
  514. alpha = .25
  515. pcountparticleorig = 0
  516. FOR i = xl TO xr STEP Dx
  517.     FOR j = yl TO yr STEP Dy
  518.         pcountparticleorig = pcountparticleorig + 1
  519.         vec(pcountparticleorig, 1) = i
  520.         vec(pcountparticleorig, 2) = j
  521.         vec(pcountparticleorig, 3) = 0
  522.         '*' vec(pcountparticleorig, 4) = 14 'use special color scheme
  523.     NEXT
  524.  
  525. genscheme.wave2d.gridinit:
  526. 'delinearize
  527. pcountparticleorig = 0
  528. FOR i = 1 TO xrange
  529.     FOR j = 1 TO yrange
  530.         pcountparticleorig = pcountparticleorig + 1
  531.         vec2dztemp(i, j) = vec(pcountparticleorig, 3)
  532.     NEXT
  533. 'initial position condition
  534. 'FOR i = 1 TO xrange 'random high points
  535. '  FOR j = 1 TO yrange
  536. '      nrand = RND * 1000
  537. '      IF nrand < 10 THEN
  538. '          vec2dz(i, j) = 5
  539. '      END IF
  540. '  NEXT
  541. 'NEXT
  542. 'vec2dz(xrange * .8, yrange * .2) = -2.5 'single plucked point
  543. 'FOR i = 1 TO xrange 'cross arm
  544. '   vec2dz(i, yrange / 3) = 2
  545. 'NEXT
  546. 'FOR j = 1 TO yrange 'cross arm
  547. '   vec2dz(xrange / 2, j) = 1
  548. 'NEXT
  549. 'sync
  550. pcountparticleorig = 0
  551. FOR i = 1 TO xrange
  552.     FOR j = 1 TO yrange
  553.         pcountparticleorig = pcountparticleorig + 1
  554.         vec2dzprev(i, j) = vec2dz(i, j)
  555.         vec2dztemp(i, j) = vec2dz(i, j)
  556.     NEXT
  557. 'initial velocity condition
  558. vec2dzprev(xrange * .8, yrange * .8) = 1.5 'single struck point
  559. 'relinearize
  560. pcountparticleorig = 0
  561. FOR i = 1 TO xrange
  562.     FOR j = 1 TO yrange
  563.         pcountparticleorig = pcountparticleorig + 1
  564.         vec(pcountparticleorig, 3) = vec2dz(i, j)
  565.     NEXT
  566.  
  567. genscheme.wave2d.timeanimate:
  568. 'delinearize
  569. pcountparticleorig = 0
  570. FOR i = 1 TO xrange
  571.     FOR j = 1 TO yrange
  572.         pcountparticleorig = pcountparticleorig + 1
  573.         vec2dztemp(i, j) = vec(pcountparticleorig, 3)
  574.     NEXT
  575. 'begin propagation process
  576. FOR i = 2 TO xrange - 1 'boDy, no edges
  577.     FOR j = 2 TO yrange - 1
  578.         wp1 = alpha * (vec2dztemp(i + 1, j) + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  579.         wp2 = alpha * (vec2dztemp(i, j + 1) + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  580.         vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  581.     NEXT
  582. 'comment out this section for fixed edges (or pieces of this section)
  583. i = 1 'left edge
  584. FOR j = 2 TO yrange - 1
  585.     wfp = vec2dztemp(i, j)
  586.     wp1 = alpha * (vec2dztemp(i + 1, j) + wfp) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  587.     wp2 = alpha * (vec2dztemp(i, j + 1) + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  588.     'vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  589. i = xrange 'right edge
  590. FOR j = 2 TO yrange - 1
  591.     wfp = vec2dztemp(i, j)
  592.     wp1 = alpha * (wfp + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  593.     wp2 = alpha * (vec2dztemp(i, j + 1) + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  594.     vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  595. j = 1 'bottom edge
  596. FOR i = 2 TO xrange - 1
  597.     wfp = vec2dztemp(i, j)
  598.     wp2 = alpha * (vec2dztemp(i, j + 1) + wfp) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  599.     wp1 = alpha * (vec2dztemp(i + 1, j) + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  600.     vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  601. j = yrange 'top edge
  602. FOR i = 2 TO xrange - 1
  603.     wfp = vec2dztemp(i, j)
  604.     wp2 = alpha * (wfp + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  605.     wp1 = alpha * (vec2dztemp(i + 1, j) + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  606.     vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  607. 'bottom left corner
  608. i = 1: j = 1
  609. wfp1 = vec2dztemp(i, j)
  610. wfp2 = vec2dztemp(i, j)
  611. wp1 = alpha * (vec2dztemp(i + 1, j) + wfp1) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  612. wp2 = alpha * (vec2dztemp(i, j + 1) + wfp2) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  613. 'vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  614. 'bottom right corner
  615. i = xrange: j = 1
  616. wfp1 = vec2dztemp(i, j)
  617. wfp2 = vec2dztemp(i, j)
  618. wp1 = alpha * (wfp1 + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  619. wp2 = alpha * (vec2dztemp(i, j + 1) + wfp2) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  620. vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  621. 'top left corner
  622. i = 1: j = yrange
  623. wfp1 = vec2dztemp(i, j)
  624. wfp2 = vec2dztemp(i, j)
  625. wp1 = alpha * (vec2dztemp(i + 1, j) + wfp1) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  626. wp2 = alpha * (wfp2 + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  627. 'vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  628. 'top right corner
  629. i = xrange: j = yrange
  630. wfp1 = vec2dztemp(i, j)
  631. wfp2 = vec2dztemp(i, j)
  632. wp1 = alpha * (wfp1 + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  633. wp2 = alpha * (wfp2 + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
  634. vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
  635. 'start special movements
  636. T = timevar / 5
  637. IF T < pi THEN 'wave left edge just once
  638.     FOR j = 1 TO yrange
  639.         i = 1
  640.         vec2dz(i, j) = (j / yrange) * 1.5 * SIN(T)
  641.     NEXT
  642. IF T < pi THEN 'wave bottom edge just once
  643.     FOR i = 1 TO xrange
  644.         j = 1
  645.         vec2dz(i, j) = (i / xrange) * .45 * SIN(T)
  646.     NEXT
  647. 'relinearize
  648. pcountparticleorig = 0
  649. FOR i = 1 TO xrange
  650.     FOR j = 1 TO yrange
  651.         pcountparticleorig = pcountparticleorig + 1
  652.         vec2dzprev(i, j) = vec2dztemp(i, j)
  653.         vec2dztemp(i, j) = vec2dz(i, j)
  654.         vec(pcountparticleorig, 3) = vec2dz(i, j)
  655.     NEXT
  656.  
Title: Re: U.S. Flag
Post by: bplus on May 15, 2020, 11:08:28 am
@_vince

Very nice coloring with wave, beautiful!
Title: Re: U.S. Flag
Post by: SierraKen on May 15, 2020, 11:56:36 am
Great work Vince!
Stxaxtic, I posted yours above already. :)
Title: Re: U.S. Flag
Post by: SierraKen on June 06, 2020, 09:33:32 pm
Today I decided to make the stars on this flag look better without using DATA lines. I also added random hills in the background. Pressing the Space Bar makes different random hills in the background. I added a picture here.

Code: QB64: [Select]
  1. 'Made to honor the U.S. Flag.
  2. 'Feel free to use any or all of this code in your own applications or games.
  3. 'By Sierraken on May 11, 2020.
  4. 'Updated with better stars without using DATA lines and random hills on June 6, 2020.
  5.  
  6. _LIMIT 300
  7. _TITLE "U.S. Flag - Press Space Bar to change hills."
  8. SCREEN _NEWIMAGE(800, 600, 32)
  9. Go:
  10. x = 150
  11. y = 100
  12.  
  13. 'Sky
  14. PAINT (2, 2), _RGB32(0, 205, 255)
  15.  
  16. 'Random Hills
  17. hills = INT(RND * 40) + 3
  18. FOR h = 1 TO hills
  19.     hx = INT(RND * 800) + 1
  20.     size = INT(RND * 450) + 75
  21.     cl = INT(RND * 155) + 100
  22.     shape = RND
  23.     FOR sz = .25 TO size STEP .25
  24.         CIRCLE (hx, 599), sz, _RGB32(10, cl, 20), , , shape
  25.     NEXT sz
  26. 'Stars
  27. LINE (x, y)-(x + 185, y + 130), _RGB32(0, 0, 255), BF
  28. FOR xx = 155 TO 345 STEP 32
  29.     FOR yy = 105 TO 220 STEP 28
  30.         LINE (xx + 2, yy + 12)-(xx + 7, yy), _RGB32(255, 255, 255)
  31.         LINE (xx + 7, yy)-(xx + 13, yy + 12), _RGB32(255, 255, 255)
  32.         LINE (xx + 13, yy + 12)-(xx, yy + 5), _RGB32(255, 255, 255)
  33.         LINE (xx, yy + 5)-(xx + 15, yy + 5), _RGB32(255, 255, 255)
  34.         LINE (xx + 15, yy + 5)-(xx + 2, yy + 12), _RGB32(255, 255, 255)
  35.         PAINT (xx + 7, yy + 2), _RGB32(255, 255, 255)
  36.         PAINT (xx + 7, yy + 6), _RGB32(255, 255, 255)
  37.         PAINT (xx + 11, yy + 10), _RGB32(255, 255, 255)
  38.         PAINT (xx + 4, yy + 10), _RGB32(255, 255, 255)
  39.         PAINT (xx + 3, yy + 6), _RGB32(255, 255, 255)
  40.         PAINT (xx + 12, yy + 6), _RGB32(255, 255, 255)
  41.     NEXT yy
  42. NEXT xx
  43.  
  44. FOR xx = 172 TO 329 STEP 32
  45.     FOR yy = 118.9 TO 213.05 STEP 28
  46.         LINE (xx + 2, yy + 12)-(xx + 7, yy), _RGB32(255, 255, 255)
  47.         LINE (xx + 7, yy)-(xx + 13, yy + 12), _RGB32(255, 255, 255)
  48.         LINE (xx + 13, yy + 12)-(xx, yy + 5), _RGB32(255, 255, 255)
  49.         LINE (xx, yy + 5)-(xx + 15, yy + 5), _RGB32(255, 255, 255)
  50.         LINE (xx + 15, yy + 5)-(xx + 2, yy + 12), _RGB32(255, 255, 255)
  51.         PAINT (xx + 7, yy + 2), _RGB32(255, 255, 255)
  52.         PAINT (xx + 7, yy + 6), _RGB32(255, 255, 255)
  53.         PAINT (xx + 11, yy + 10), _RGB32(255, 255, 255)
  54.         PAINT (xx + 4, yy + 10), _RGB32(255, 255, 255)
  55.         PAINT (xx + 3, yy + 6), _RGB32(255, 255, 255)
  56.         PAINT (xx + 12, yy + 6), _RGB32(255, 255, 255)
  57.     NEXT yy
  58. NEXT xx
  59.  
  60. 'Stripes
  61. FOR rs = 100 TO 230 STEP 37.2
  62.     w = w + 1
  63.     LINE (335, rs)-(612.5, rs + 18.6), _RGB32(255, 0, 0), BF
  64.     IF w > 3 THEN GOTO nex:
  65.     LINE (335, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 255, 255), BF
  66. NEXT rs
  67. nex:
  68. w = 0
  69. FOR rs = 230 TO 341.6 STEP 37.2
  70.     r = r + 1
  71.     LINE (150, rs)-(612.5, rs + 18.6), _RGB32(255, 255, 255), BF
  72.     IF r > 3 THEN GOTO nex2:
  73.     LINE (150, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 0, 0), BF
  74. NEXT rs
  75. nex2:
  76. r = 0
  77.  
  78. 'Flag Pole
  79. FOR sz = .25 TO 10 STEP .25
  80.     CIRCLE (145, 80), sz, _RGB32(122, 128, 166)
  81. NEXT sz
  82. LINE (142, 80)-(147, 600), _RGB32(122, 128, 166), BF
  83. 'Wait for key.
  84.     a$ = INKEY$
  85.     IF a$ = " " THEN GOTO Go:
  86.     IF a$ = CHR$(27) THEN END
  87.  
Title: Re: U.S. Flag
Post by: Ashish on June 07, 2020, 01:32:18 am
Good work... Nice graphics. :)
Title: Re: U.S. Flag
Post by: SierraKen on June 07, 2020, 01:13:45 pm
Thanks Ashish :). My first flag I made a month ago has stars that are very "curvy" looking so I decided to make them look a little sharper and better and without the DATA lines. So what I did was just use  LINE commands making a star just like you would draw it on paper. Then I used PAINT commands to fill in the gaps. :)
Title: Re: U.S. Flag
Post by: SierraKen on June 16, 2020, 12:40:33 am
Tonight I was able to use my water waves formula to capture the colors of my flag and make the flag wave. I also added a night/day cycle for the sky. I had to delete the hills though because I couldn't figure out the PUTIMAGE stuff again, not sure if it's even possible to keep an animation moving and grab new hills and keep them in the background. I tried it with just using arrays, without the PUTIMAGE stuff and it just slowed the flag animation down greatly and got slower as it went. I do use a huge amount of memory to grab the entire flag and put every pixel in memory to make it wave, I hope it's not too much for one DIM statement. Anyhow, please check it out. I've wanted to make a flag wave for a very long time. It's not as good as the realistic one somewhere else on this thread, but it's an accomplishment for me. :)

Code: QB64: [Select]
  1. 'Made to honor the U.S. Flag.
  2. 'Feel free to use any or all of this code in your own applications or games.
  3. 'By Sierraken on May 11, 2020.
  4. 'Updated to make the flag wave and night and day cycle on June 15, 2020.
  5.  
  6. _TITLE "U.S. Flag"
  7. SCREEN _NEWIMAGE(800, 600, 32)
  8. x = 150
  9. y = 100
  10. DIM cf&(113000)
  11.  
  12. 'Stars
  13. LINE (x, y)-(x + 185, y + 130), _RGB32(0, 0, 255), BF
  14. FOR xx = 155 TO 345 STEP 32
  15.     FOR yy = 105 TO 220 STEP 28
  16.         LINE (xx + 2, yy + 12)-(xx + 7, yy), _RGB32(255, 255, 255)
  17.         LINE (xx + 7, yy)-(xx + 13, yy + 12), _RGB32(255, 255, 255)
  18.         LINE (xx + 13, yy + 12)-(xx, yy + 5), _RGB32(255, 255, 255)
  19.         LINE (xx, yy + 5)-(xx + 15, yy + 5), _RGB32(255, 255, 255)
  20.         LINE (xx + 15, yy + 5)-(xx + 2, yy + 12), _RGB32(255, 255, 255)
  21.         PAINT (xx + 7, yy + 2), _RGB32(255, 255, 255)
  22.         PAINT (xx + 7, yy + 6), _RGB32(255, 255, 255)
  23.         PAINT (xx + 11, yy + 10), _RGB32(255, 255, 255)
  24.         PAINT (xx + 4, yy + 10), _RGB32(255, 255, 255)
  25.         PAINT (xx + 3, yy + 6), _RGB32(255, 255, 255)
  26.         PAINT (xx + 12, yy + 6), _RGB32(255, 255, 255)
  27.     NEXT yy
  28. NEXT xx
  29.  
  30. FOR xx = 172 TO 329 STEP 32
  31.     FOR yy = 118.9 TO 213.05 STEP 28
  32.         LINE (xx + 2, yy + 12)-(xx + 7, yy), _RGB32(255, 255, 255)
  33.         LINE (xx + 7, yy)-(xx + 13, yy + 12), _RGB32(255, 255, 255)
  34.         LINE (xx + 13, yy + 12)-(xx, yy + 5), _RGB32(255, 255, 255)
  35.         LINE (xx, yy + 5)-(xx + 15, yy + 5), _RGB32(255, 255, 255)
  36.         LINE (xx + 15, yy + 5)-(xx + 2, yy + 12), _RGB32(255, 255, 255)
  37.         PAINT (xx + 7, yy + 2), _RGB32(255, 255, 255)
  38.         PAINT (xx + 7, yy + 6), _RGB32(255, 255, 255)
  39.         PAINT (xx + 11, yy + 10), _RGB32(255, 255, 255)
  40.         PAINT (xx + 4, yy + 10), _RGB32(255, 255, 255)
  41.         PAINT (xx + 3, yy + 6), _RGB32(255, 255, 255)
  42.         PAINT (xx + 12, yy + 6), _RGB32(255, 255, 255)
  43.     NEXT yy
  44. NEXT xx
  45.  
  46. 'Stripes
  47. FOR rs = 100 TO 230 STEP 37.2
  48.     w = w + 1
  49.     LINE (335, rs)-(612.5, rs + 18.6), _RGB32(255, 0, 0), BF
  50.     IF w > 3 THEN GOTO nex:
  51.     LINE (335, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 255, 255), BF
  52. NEXT rs
  53. nex:
  54. w = 0
  55. FOR rs = 230 TO 341.6 STEP 37.2
  56.     r = r + 1
  57.     LINE (150, rs)-(612.5, rs + 18.6), _RGB32(255, 255, 255), BF
  58.     IF r > 3 THEN GOTO nex2:
  59.     LINE (150, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 0, 0), BF
  60. NEXT rs
  61. nex2:
  62. r = 0
  63. FOR fy = 100 TO 341.6
  64.     FOR fx = 150 TO 612.5
  65.         t5 = t5 + 1
  66.         cf&(t5) = POINT(fx, fy)
  67.     NEXT fx
  68. NEXT fy
  69. t = 20
  70.     _LIMIT 20
  71.     'Sky
  72.     hour$ = LEFT$(TIME$, 2)
  73.     hour = VAL(hour$)
  74.     IF hour < 21 AND hour >= 6 THEN
  75.         PAINT (2, 2), _RGB32(0, 205, 255)
  76.     END IF
  77.  
  78.     'Flag Pole
  79.     FOR sz = .25 TO 10 STEP .25
  80.         CIRCLE (145, 80), sz, _RGB32(122, 128, 166)
  81.     NEXT sz
  82.     LINE (142, 80)-(147, 600), _RGB32(122, 128, 166), BF
  83.     FOR fy = 100 TO 341.6
  84.         FOR fx = 150 TO 612.5
  85.             t6 = t6 + 1
  86.             PSET (fx, (SIN(fx * 0.017453) * t) + fy), cf&(t6)
  87.         NEXT fx
  88.     NEXT fy
  89.     fx2 = fx2 + 1
  90.     IF fx2 = 242 THEN fx2 = 0
  91.     t6 = 0
  92.     IF tt = 0 THEN t = t + 1
  93.     IF t > 30 THEN tt = 1
  94.     IF tt = 1 THEN t = t - 1
  95.     IF t < -30 THEN tt = 0
  96.     a$ = INKEY$
  97.     IF a$ = CHR$(27) THEN END
  98.     _DISPLAY
  99.     CLS
  100.  
Title: Re: U.S. Flag
Post by: bplus on June 16, 2020, 11:56:25 am
Wave back to you Ken, coming along nicely!

Since last night Podcast, I've been thinking about layers allot.

Do the hills on completely different screen:
hills& = _Newimage(_width, _height, 32)

_DEST hills&
'now draw just hills like normal

'now back to main screen
_DEST 0

'use hills for background and then draw flag in fore ground on top of background.

_PUTIMAGE , hills&, 0  'my background hills

'draw flag

'use _PUTIMAGE , hills&, 0  'my background hills to CLS putting the background in loop for waving flag drawing

Might be more details to get it working but that is gist I think.
Title: Re: U.S. Flag
Post by: SierraKen on June 16, 2020, 02:15:36 pm
Thanks b+, it works perfectly now! I also made the flag waving look more realistic.

Code: QB64: [Select]
  1. 'Made to honor the U.S. Flag.
  2. 'By Sierraken
  3. 'Feel free to use any or all of this code in your own applications or games.
  4. 'Updated with better flag waving and a hills fix on June 16, 2020.
  5. 'Thank you to B+ for a little help on the hills!
  6.  
  7. _TITLE "U.S. Flag - Use space bar to change hills background."
  8. SCREEN _NEWIMAGE(800, 600, 32)
  9. x = 150
  10. y = 100
  11. DIM cf&(113000)
  12.  
  13. GOSUB hills:
  14.  
  15. 'Stars
  16. LINE (x, y)-(x + 185, y + 130), _RGB32(0, 0, 255), BF
  17. FOR xx = 155 TO 345 STEP 32
  18.     FOR yy = 105 TO 220 STEP 28
  19.         LINE (xx + 2, yy + 12)-(xx + 7, yy), _RGB32(255, 255, 255)
  20.         LINE (xx + 7, yy)-(xx + 13, yy + 12), _RGB32(255, 255, 255)
  21.         LINE (xx + 13, yy + 12)-(xx, yy + 5), _RGB32(255, 255, 255)
  22.         LINE (xx, yy + 5)-(xx + 15, yy + 5), _RGB32(255, 255, 255)
  23.         LINE (xx + 15, yy + 5)-(xx + 2, yy + 12), _RGB32(255, 255, 255)
  24.         PAINT (xx + 7, yy + 2), _RGB32(255, 255, 255)
  25.         PAINT (xx + 7, yy + 6), _RGB32(255, 255, 255)
  26.         PAINT (xx + 11, yy + 10), _RGB32(255, 255, 255)
  27.         PAINT (xx + 4, yy + 10), _RGB32(255, 255, 255)
  28.         PAINT (xx + 3, yy + 6), _RGB32(255, 255, 255)
  29.         PAINT (xx + 12, yy + 6), _RGB32(255, 255, 255)
  30.     NEXT yy
  31. NEXT xx
  32.  
  33. FOR xx = 172 TO 329 STEP 32
  34.     FOR yy = 118.9 TO 213.05 STEP 28
  35.         LINE (xx + 2, yy + 12)-(xx + 7, yy), _RGB32(255, 255, 255)
  36.         LINE (xx + 7, yy)-(xx + 13, yy + 12), _RGB32(255, 255, 255)
  37.         LINE (xx + 13, yy + 12)-(xx, yy + 5), _RGB32(255, 255, 255)
  38.         LINE (xx, yy + 5)-(xx + 15, yy + 5), _RGB32(255, 255, 255)
  39.         LINE (xx + 15, yy + 5)-(xx + 2, yy + 12), _RGB32(255, 255, 255)
  40.         PAINT (xx + 7, yy + 2), _RGB32(255, 255, 255)
  41.         PAINT (xx + 7, yy + 6), _RGB32(255, 255, 255)
  42.         PAINT (xx + 11, yy + 10), _RGB32(255, 255, 255)
  43.         PAINT (xx + 4, yy + 10), _RGB32(255, 255, 255)
  44.         PAINT (xx + 3, yy + 6), _RGB32(255, 255, 255)
  45.         PAINT (xx + 12, yy + 6), _RGB32(255, 255, 255)
  46.     NEXT yy
  47. NEXT xx
  48.  
  49. 'Stripes
  50. FOR rs = 100 TO 230 STEP 37.2
  51.     w = w + 1
  52.     LINE (335, rs)-(612.5, rs + 18.6), _RGB32(255, 0, 0), BF
  53.     IF w > 3 THEN GOTO nex:
  54.     LINE (335, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 255, 255), BF
  55. NEXT rs
  56. nex:
  57. w = 0
  58. FOR rs = 230 TO 341.6 STEP 37.2
  59.     r = r + 1
  60.     LINE (150, rs)-(612.5, rs + 18.6), _RGB32(255, 255, 255), BF
  61.     IF r > 3 THEN GOTO nex2:
  62.     LINE (150, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 0, 0), BF
  63. NEXT rs
  64. nex2:
  65. r = 0
  66. FOR fy = 100 TO 341.6
  67.     FOR fx = 150 TO 612.5
  68.         t5 = t5 + 1
  69.         cf&(t5) = POINT(fx, fy)
  70.     NEXT fx
  71. NEXT fy
  72. t = 20
  73.     _LIMIT 10
  74.     'Sky
  75.     hour$ = LEFT$(TIME$, 2)
  76.     hour = VAL(hour$)
  77.     IF hour < 21 AND hour >= 6 THEN
  78.         PAINT (2, 2), _RGB32(0, 205, 255)
  79.     END IF
  80.     _PUTIMAGE , hills&, 0
  81.     'Flag Pole
  82.     FOR sz = .25 TO 10 STEP .25
  83.         CIRCLE (145, 80), sz, _RGB32(122, 128, 166)
  84.     NEXT sz
  85.     LINE (142, 80)-(147, 600), _RGB32(122, 128, 166), BF
  86.     fx2 = fx2 + 1.2
  87.     IF fx2 > 5 THEN fx2 = 1.2
  88.     FOR fy = 100 TO 341.6
  89.         FOR fx = 150 TO 612.5
  90.             t6 = t6 + 1
  91.             PSET ((SIN(fy * 0.017453 / fx2) * t) + fx, (SIN(fx * 0.017453 / fx2) * t) + fy), cf&(t6)
  92.         NEXT fx
  93.     NEXT fy
  94.     t6 = 0
  95.     IF tt = 0 THEN t = t + 1
  96.     IF t > 10 THEN tt = 1
  97.     IF tt = 1 THEN t = t - 1
  98.     IF t < -10 THEN tt = 0
  99.     a$ = INKEY$
  100.     IF a$ = CHR$(27) THEN END
  101.     IF a$ = " " THEN GOSUB hills:
  102.     _DISPLAY
  103.     CLS
  104.  
  105. hills:
  106. 'Random Hills
  107. hills& = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
  108. _DEST hills&
  109. hills = INT(RND * 40) + 3
  110. FOR h = 1 TO hills
  111.     hx = INT(RND * 800) + 1
  112.     size = INT(RND * 450) + 75
  113.     cl = INT(RND * 155) + 100
  114.     shape = RND
  115.     FOR sz = .25 TO size STEP .25
  116.         CIRCLE (hx, 599), sz, _RGB32(10, cl, 20), , , shape
  117.     NEXT sz
  118.  

Title: Re: U.S. Flag
Post by: MasterGy on June 16, 2020, 02:35:58 pm

very beautiful and spectacular !! congratulations!
Title: Re: U.S. Flag
Post by: bplus on June 16, 2020, 02:37:08 pm
+1

Wow that was fast!

I wonder why that flag looks a little jumpy, I sped up the _LIMIT, a little less jumpy but too fast.

I wonder if you make a flag image (only 1 time draw) like the hills image and lay different width sections on top of each other starting from left and going right, or take vertical lines of the flag and lay them out with slight overlaps going up and down but also going lower towards ground towards right.

Now I wonder if you got that?  ;-))

Title: Re: U.S. Flag
Post by: SierraKen on June 16, 2020, 03:35:25 pm
Nothing overlaps except over the hills and sometimes the pole. It makes a new flag on every frame of animation. Or are you hinting at that? Yesterday I had it overlapping a tiny bit but it was a mess. lol The flag moves like that as an effect from the wind. :)

I just added the National Anthem and the hills change every 2 seconds. (Please no political posts.) I'll add the .bas and the .mp3 file to the attachments in a zip file. Enjoy. I'm also going to make a YouTube of it as well.

Title: Re: U.S. Flag
Post by: bplus on June 16, 2020, 05:49:38 pm
Wow you have it on YouTube! I feel like saluting!
Title: Re: U.S. Flag
Post by: SierraKen on June 16, 2020, 07:06:54 pm
LOL Thanks :)
Title: Re: U.S. Flag
Post by: Ashish on June 17, 2020, 12:12:26 am
Amazing! Beautiful!
Title: Re: U.S. Flag
Post by: SierraKen on June 17, 2020, 12:20:40 am
Thanks everyone :))
Title: Re: U.S. Flag
Post by: DANILIN on June 17, 2020, 01:05:46 pm
Flagimation & Ezgif