Author Topic: U.S. Flag  (Read 4634 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
U.S. Flag
« 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.  

Ken's US Flag Program.jpg
* Ken's US Flag Program.jpg (Filesize: 359.2 KB, Dimensions: 1909x988, Views: 335)
« Last Edit: May 12, 2020, 12:55:48 am by SierraKen »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: U.S. Flag
« Reply #1 on: May 12, 2020, 04:45:23 am »
Nice! Now, make it wave around.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: U.S. Flag
« Reply #2 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
In order to understand recursion, one must first understand recursion.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: U.S. Flag
« Reply #4 on: May 12, 2020, 12:08:36 pm »
Thanks guys.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: U.S. Flag
« Reply #5 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!

 
task15figure12.gif


Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: U.S. Flag
« Reply #6 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.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: U.S. Flag
« Reply #7 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


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.  
« Last Edit: May 12, 2020, 03:27:59 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: U.S. Flag
« Reply #8 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


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
« Last Edit: May 12, 2020, 03:29:29 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: U.S. Flag
« Reply #9 on: May 12, 2020, 05:44:53 pm »
Incredible bplus and Ashish! Good job.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: U.S. Flag
« Reply #10 on: May 13, 2020, 10:31:52 am »
task15figure12.gif


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.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: U.S. Flag
« Reply #11 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

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.  
qb64flag.png
* qb64flag.png (Filesize: 70.23 KB, Dimensions: 640x960, Views: 245)

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: U.S. Flag
« Reply #12 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().
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: U.S. Flag
« Reply #13 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.  
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: U.S. Flag
« Reply #14 on: May 15, 2020, 11:08:28 am »
@_vince

Very nice coloring with wave, beautiful!