QB64.org Forum

Active Forums => Programs => Topic started by: SierraKen on February 09, 2022, 12:47:16 am

Title: Ken's U.S. Flag version 4 - With moving clouds
Post by: SierraKen on February 09, 2022, 12:47:16 am
Tonight I was going over a list of my old apps I made and remembered that I made a U.S. flag. So I found one I made that is waving and has random hills in the background and decided to add the new moving clouds in the sky that Vince has been using. Just by chance the flag is moving the same direction as the clouds. :) Press the Space Bar to get different random hills. Feel free to mod mod mod. :D Thanks Vince and someone named rattrapmax6!

(Code deleted because of a memory leak, please get the one below instead.)
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: SierraKen on February 09, 2022, 01:02:30 am
I just added the U.S. National Anthem to the background with the hills changing every second or so. It was easy because I had already made this before, just without the clouds. Make sure and download the attachment mp3 song and put it in the same folder as this program. The U.S. National Anthem is played by the United States Air Force. 
I want to thank B+ also for the help he originally gave me with the hills. And I think he also used these clouds too.

EDIT: Memory leak fixed and clouds fixed. Thanks B+, OldMoses, and everyone else!

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 help on the hills!
  6.  
  7. 'Update again on Feb. 8, 2022 from B+, Vince and someone named rattrapmax6 for the clouds, thank you!
  8. 'Added: U.S. National Anthem played by the U.S. Air Force and automatic hills change.
  9.  
  10. _Title "U.S. Flag - Use space bar to change hills background."
  11. Screen _NewImage(800, 600, 32)
  12. x = 150
  13. y = 100
  14. Dim cf&(113000)
  15.  
  16. Const nn = 1
  17. Const twidth = 640, theight = 480, zoom = 128
  18. Dim Shared noise(nn * twidth * theight) '//the noise array
  19. Dim Shared texture(nn * twidth * theight) '//texture array
  20. Dim Shared pal(256) As _Unsigned Long '//color palette
  21.  
  22. Screen _NewImage(640, 480, 32)
  23. MakePalette 255, 155, 255, 10, 100, 180
  24. GenerateNoise
  25. buildtexture
  26.  
  27. vs = _NewImage(twidth, theight, 32)
  28. drawtexture 0
  29.  
  30. ii = 0
  31. jj = -1
  32. kk = 0
  33.  
  34.  
  35.  
  36. GoSub hills:
  37.  
  38. 'Stars
  39. Line (x, y)-(x + 185, y + 130), _RGB32(0, 0, 255), BF
  40. For xx = 155 To 345 Step 32
  41.     For yy = 105 To 220 Step 28
  42.         Line (xx + 2, yy + 12)-(xx + 7, yy), _RGB32(255, 255, 255)
  43.         Line (xx + 7, yy)-(xx + 13, yy + 12), _RGB32(255, 255, 255)
  44.         Line (xx + 13, yy + 12)-(xx, yy + 5), _RGB32(255, 255, 255)
  45.         Line (xx, yy + 5)-(xx + 15, yy + 5), _RGB32(255, 255, 255)
  46.         Line (xx + 15, yy + 5)-(xx + 2, yy + 12), _RGB32(255, 255, 255)
  47.         Paint (xx + 7, yy + 2), _RGB32(255, 255, 255)
  48.         Paint (xx + 7, yy + 6), _RGB32(255, 255, 255)
  49.         Paint (xx + 11, yy + 10), _RGB32(255, 255, 255)
  50.         Paint (xx + 4, yy + 10), _RGB32(255, 255, 255)
  51.         Paint (xx + 3, yy + 6), _RGB32(255, 255, 255)
  52.         Paint (xx + 12, yy + 6), _RGB32(255, 255, 255)
  53.     Next yy
  54. Next xx
  55.  
  56. For xx = 172 To 329 Step 32
  57.     For yy = 118.9 To 213.05 Step 28
  58.         Line (xx + 2, yy + 12)-(xx + 7, yy), _RGB32(255, 255, 255)
  59.         Line (xx + 7, yy)-(xx + 13, yy + 12), _RGB32(255, 255, 255)
  60.         Line (xx + 13, yy + 12)-(xx, yy + 5), _RGB32(255, 255, 255)
  61.         Line (xx, yy + 5)-(xx + 15, yy + 5), _RGB32(255, 255, 255)
  62.         Line (xx + 15, yy + 5)-(xx + 2, yy + 12), _RGB32(255, 255, 255)
  63.         Paint (xx + 7, yy + 2), _RGB32(255, 255, 255)
  64.         Paint (xx + 7, yy + 6), _RGB32(255, 255, 255)
  65.         Paint (xx + 11, yy + 10), _RGB32(255, 255, 255)
  66.         Paint (xx + 4, yy + 10), _RGB32(255, 255, 255)
  67.         Paint (xx + 3, yy + 6), _RGB32(255, 255, 255)
  68.         Paint (xx + 12, yy + 6), _RGB32(255, 255, 255)
  69.     Next yy
  70. Next xx
  71.  
  72. 'Stripes
  73. For rs = 100 To 230 Step 37.2
  74.     w = w + 1
  75.     Line (335, rs)-(612.5, rs + 18.6), _RGB32(255, 0, 0), BF
  76.     If w > 3 Then GoTo nex:
  77.     Line (335, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 255, 255), BF
  78. Next rs
  79. nex:
  80. w = 0
  81. For rs = 230 To 341.6 Step 37.2
  82.     r = r + 1
  83.     Line (150, rs)-(612.5, rs + 18.6), _RGB32(255, 255, 255), BF
  84.     If r > 3 Then GoTo nex2:
  85.     Line (150, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 0, 0), BF
  86. Next rs
  87. nex2:
  88. r = 0
  89. For fy = 100 To 341.6
  90.     For fx = 150 To 612.5
  91.         t5 = t5 + 1
  92.         cf&(t5) = Point(fx, fy)
  93.     Next fx
  94. Next fy
  95. t = 20
  96. song& = _SndOpen("USAFBTheStarSpangledBannerChoral.mp3")
  97. _SndPlay song&
  98. On Timer(7) GoSub hills:
  99.  
  100.     _Limit 10
  101.  
  102.     kk = kk + 1
  103.     ii = ii + 1
  104.     If ii >= 640 Then
  105.         ii = 0
  106.         jj = Not jj
  107.     End If
  108.  
  109.     If jj Then
  110.         _PutImage (ii, 0)-Step(640, 480), vs
  111.         _PutImage (ii, 0)-Step(-640, 480), vs
  112.     Else
  113.         _PutImage (ii + 640, 0)-Step(-640, 480), vs
  114.         _PutImage (ii - 640, 0)-Step(640, 480), vs
  115.     End If
  116.  
  117.     'Sky
  118.     ' ========================================= this code is blocking out the clouds
  119.     'hour$ = Left$(Time$, 2)
  120.     'hour = Val(hour$)
  121.     'If hour < 21 And hour >= 6 Then
  122.     '    Paint (2, 2), _RGB32(0, 205, 255)
  123.     'End If
  124.     ' ============================================================================
  125.     _PutImage , hills&, 0
  126.     'Flag Pole
  127.     For sz = .25 To 10 Step .25
  128.         Circle (145, 80), sz, _RGB32(122, 128, 166)
  129.     Next sz
  130.     Line (142, 80)-(147, 600), _RGB32(122, 128, 166), BF
  131.     fx2 = fx2 + 1.2
  132.     If fx2 > 5 Then fx2 = 1.2
  133.     For fy = 100 To 341.6
  134.         For fx = 150 To 612.5
  135.             t6 = t6 + 1
  136.             PSet ((Sin(fy * 0.017453 / fx2) * t) + fx, (Sin(fx * 0.017453 / fx2) * t) + fy), cf&(t6)
  137.         Next fx
  138.     Next fy
  139.     t6 = 0
  140.     If tt = 0 Then t = t + 1
  141.     If t > 10 Then tt = 1
  142.     If tt = 1 Then t = t - 1
  143.     If t < -10 Then tt = 0
  144.     a$ = InKey$
  145.     If a$ = Chr$(27) Then End
  146.     If a$ = " " Then GoSub hills:
  147.     _Display
  148.     Cls
  149.  
  150. hills:
  151. 'Random Hills
  152. If hills& <> 0 Then _FreeImage hills&
  153. hills& = _NewImage(_Width, _Height, 32)
  154. _Dest hills&
  155. hills = Int(Rnd * 40) + 3
  156. For h = 1 To hills
  157.     hx = Int(Rnd * 800) + 1
  158.     size = Int(Rnd * 450) + 75
  159.     cl = Int(Rnd * 55)
  160.     shape = Rnd
  161.     For sz = .25 To size Step .25
  162.         cl = cl + .05
  163.         Circle (hx, 599), sz, _RGB32(10, cl, 20), , , shape
  164.     Next sz
  165.  
  166. '//interpolation code by rattrapmax6
  167. Sub MakePalette (sr, sg, sb, er, eg, eb) ' (b+) start and end RGB's ? yes
  168.     Dim i, istart(3), iend(3), ishow(3), rend(3), interpol(3)
  169.  
  170.     interpol(0) = 255
  171.     istart(1) = sr
  172.     istart(2) = sg
  173.     istart(3) = sb
  174.     iend(1) = er
  175.     iend(2) = eg
  176.     iend(3) = eb
  177.     interpol(1) = (istart(1) - iend(1)) / interpol(0)
  178.     interpol(2) = (istart(2) - iend(2)) / interpol(0)
  179.     interpol(3) = (istart(3) - iend(3)) / interpol(0)
  180.     rend(1) = istart(1)
  181.     rend(2) = istart(2)
  182.     rend(3) = istart(3)
  183.  
  184.     For i = 0 To 255
  185.         ishow(1) = rend(1)
  186.         ishow(2) = rend(2)
  187.         ishow(3) = rend(3)
  188.  
  189.         pal(i) = _RGB32(ishow(1), ishow(2), ishow(3))
  190.  
  191.         rend(1) = rend(1) - interpol(1)
  192.         rend(2) = rend(2) - interpol(2)
  193.         rend(3) = rend(3) - interpol(3)
  194.     Next i
  195.  
  196. '//generates random noise.
  197. Sub GenerateNoise ()
  198.     Dim As Long x, y
  199.  
  200.     For x = 0 To nn * twidth - 1
  201.         For y = 0 To theight - 1
  202.             zz = Rnd
  203.             noise(x + y * twidth) = zz
  204.         Next y
  205.     Next x
  206.  
  207.  
  208. Function SmoothNoise (x, y)
  209.     '//get fractional part of x and y
  210.     Dim fractx, fracty, x1, y1, x2, y2, value
  211.     fractx = x - Int(x)
  212.     fracty = y - Int(y)
  213.  
  214.     '//wrap around
  215.     x1 = (Int(x) + nn * twidth) Mod twidth
  216.     y1 = (Int(y) + theight) Mod theight
  217.  
  218.     '//neighbor values
  219.     x2 = (x1 + nn * twidth - 1) Mod twidth
  220.     y2 = (y1 + theight - 1) Mod theight
  221.  
  222.     '//smooth the noise with bilinear interpolation
  223.     value = 0.0
  224.     value = value + fractx * fracty * noise(x1 + y1 * twidth)
  225.     value = value + fractx * (1 - fracty) * noise(x1 + y2 * twidth)
  226.     value = value + (1 - fractx) * fracty * noise(x2 + y1 * twidth)
  227.     value = value + (1 - fractx) * (1 - fracty) * noise(x2 + y2 * twidth)
  228.  
  229.     SmoothNoise = value
  230.  
  231. Function Turbulence (x, y, size)
  232.     Dim value, initialsize
  233.  
  234.     initialsize = size
  235.     While (size >= 1)
  236.         value = value + SmoothNoise(x / size, y / size) * size
  237.         size = size / 2.0
  238.     Wend
  239.     Turbulence = (128.0 * value / initialsize)
  240.  
  241. '//builds the texture.
  242. Sub buildtexture
  243.     Dim x, y
  244.  
  245.     For x = 0 To nn * twidth - 1
  246.         For y = 0 To theight - 1
  247.             texture(x + y * nn * twidth) = Turbulence(x, y, zoom)
  248.         Next y
  249.     Next x
  250.  
  251. '//draws texture to screen.
  252. Sub drawtexture (dx)
  253.     Dim x, y
  254.     Dim As Long c, r, g, b
  255.  
  256.     For x = 0 To twidth - 1
  257.         For y = 0 To theight - 1
  258.             c = pal(texture(((x + dx) + y * nn * twidth)))
  259.             r = _Red(c)
  260.             g = _Green(c)
  261.             b = _Blue(c)
  262.             c = _RGB(r - 0.2 * y, g - 0.2 * y, b - 0.2 * b)
  263.             PSet (x, y), c 'pal(texture(((x + dx) + y * nn*twidth)))
  264.         Next y
  265.     Next x
  266.  
  267.  

Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: DANILIN on February 09, 2022, 06:10:00 am
Realistic Flag Logo
https://renderforest.com/en/template/Realistic-flag-logo-bonus-version
renderforest.com/en/template/Realistic-flag-logo-bonus-version
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: FellippeHeitor on February 09, 2022, 11:31:18 am
That was clever @SierraKen! It's cool how you generate it all with line/paint and then store it to "wave" it later on.
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: bplus on February 09, 2022, 12:08:35 pm
I am not seeing all that cloud making code being activated which BTW came from here:
https://qb64forum.alephc.xyz/index.php?topic=4615.msg140454#msg140454
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: _vince on February 09, 2022, 12:30:54 pm
I am not seeing all that cloud making code being activated which BTW came from here:
https://qb64forum.alephc.xyz/index.php?topic=4615.msg140454#msg140454

Because it happens to be daytime with clear sunny skies
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: bplus on February 09, 2022, 12:41:29 pm
Shouldn't this be causing a memory leak?

Code: QB64: [Select]
  1. hills:
  2. 'Random Hills
  3. hills& = _NewImage(_Width, _Height, 32)
  4. _Dest hills&
  5.  
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: bplus on February 09, 2022, 12:54:56 pm
Well this gets the clouds shown and moving:
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 help on the hills!
  6.  
  7. 'Update again on Feb. 8, 2022 from B+, Vince and someone named rattrapmax6 for the clouds, thank you!
  8. 'Added: U.S. National Anthem played by the U.S. Air Force and automatic hills change.
  9.  
  10. _Title "U.S. Flag - Use space bar to change hills background."
  11. Screen _NewImage(800, 600, 32)
  12. x = 150
  13. y = 100
  14. Dim cf&(113000)
  15.  
  16. Const nn = 1
  17. Const twidth = 640, theight = 480, zoom = 128
  18. Dim Shared noise(nn * twidth * theight) '//the noise array
  19. Dim Shared texture(nn * twidth * theight) '//texture array
  20. Dim Shared pal(256) As _Unsigned Long '//color palette
  21.  
  22. Screen _NewImage(640, 480, 32)
  23. MakePalette 255, 155, 255, 10, 100, 180
  24. GenerateNoise
  25. buildtexture
  26.  
  27. vs = _NewImage(twidth, theight, 32)
  28. drawtexture 0
  29.  
  30. ii = 0
  31. jj = -1
  32. kk = 0
  33.  
  34.  
  35.  
  36. GoSub hills:
  37.  
  38. 'Stars
  39. Line (x, y)-(x + 185, y + 130), _RGB32(0, 0, 255), BF
  40. For xx = 155 To 345 Step 32
  41.     For yy = 105 To 220 Step 28
  42.         Line (xx + 2, yy + 12)-(xx + 7, yy), _RGB32(255, 255, 255)
  43.         Line (xx + 7, yy)-(xx + 13, yy + 12), _RGB32(255, 255, 255)
  44.         Line (xx + 13, yy + 12)-(xx, yy + 5), _RGB32(255, 255, 255)
  45.         Line (xx, yy + 5)-(xx + 15, yy + 5), _RGB32(255, 255, 255)
  46.         Line (xx + 15, yy + 5)-(xx + 2, yy + 12), _RGB32(255, 255, 255)
  47.         Paint (xx + 7, yy + 2), _RGB32(255, 255, 255)
  48.         Paint (xx + 7, yy + 6), _RGB32(255, 255, 255)
  49.         Paint (xx + 11, yy + 10), _RGB32(255, 255, 255)
  50.         Paint (xx + 4, yy + 10), _RGB32(255, 255, 255)
  51.         Paint (xx + 3, yy + 6), _RGB32(255, 255, 255)
  52.         Paint (xx + 12, yy + 6), _RGB32(255, 255, 255)
  53.     Next yy
  54. Next xx
  55.  
  56. For xx = 172 To 329 Step 32
  57.     For yy = 118.9 To 213.05 Step 28
  58.         Line (xx + 2, yy + 12)-(xx + 7, yy), _RGB32(255, 255, 255)
  59.         Line (xx + 7, yy)-(xx + 13, yy + 12), _RGB32(255, 255, 255)
  60.         Line (xx + 13, yy + 12)-(xx, yy + 5), _RGB32(255, 255, 255)
  61.         Line (xx, yy + 5)-(xx + 15, yy + 5), _RGB32(255, 255, 255)
  62.         Line (xx + 15, yy + 5)-(xx + 2, yy + 12), _RGB32(255, 255, 255)
  63.         Paint (xx + 7, yy + 2), _RGB32(255, 255, 255)
  64.         Paint (xx + 7, yy + 6), _RGB32(255, 255, 255)
  65.         Paint (xx + 11, yy + 10), _RGB32(255, 255, 255)
  66.         Paint (xx + 4, yy + 10), _RGB32(255, 255, 255)
  67.         Paint (xx + 3, yy + 6), _RGB32(255, 255, 255)
  68.         Paint (xx + 12, yy + 6), _RGB32(255, 255, 255)
  69.     Next yy
  70. Next xx
  71.  
  72. 'Stripes
  73. For rs = 100 To 230 Step 37.2
  74.     w = w + 1
  75.     Line (335, rs)-(612.5, rs + 18.6), _RGB32(255, 0, 0), BF
  76.     If w > 3 Then GoTo nex:
  77.     Line (335, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 255, 255), BF
  78. Next rs
  79. nex:
  80. w = 0
  81. For rs = 230 To 341.6 Step 37.2
  82.     r = r + 1
  83.     Line (150, rs)-(612.5, rs + 18.6), _RGB32(255, 255, 255), BF
  84.     If r > 3 Then GoTo nex2:
  85.     Line (150, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 0, 0), BF
  86. Next rs
  87. nex2:
  88. r = 0
  89. For fy = 100 To 341.6
  90.     For fx = 150 To 612.5
  91.         t5 = t5 + 1
  92.         cf&(t5) = Point(fx, fy)
  93.     Next fx
  94. Next fy
  95. t = 20
  96. song& = _SndOpen("USAFBTheStarSpangledBannerChoral.mp3")
  97. _SndPlay song&
  98. On Timer(7) GoSub hills:
  99.  
  100.     _Limit 10
  101.  
  102.     kk = kk + 1
  103.     ii = ii + 1
  104.     If ii >= 640 Then
  105.         ii = 0
  106.         jj = Not jj
  107.     End If
  108.  
  109.     If jj Then
  110.         _PutImage (ii, 0)-Step(640, 480), vs
  111.         _PutImage (ii, 0)-Step(-640, 480), vs
  112.     Else
  113.         _PutImage (ii + 640, 0)-Step(-640, 480), vs
  114.         _PutImage (ii - 640, 0)-Step(640, 480), vs
  115.     End If
  116.  
  117.     'Sky
  118.     ' ========================================= this code is blocking out the clouds
  119.     'hour$ = Left$(Time$, 2)
  120.     'hour = Val(hour$)
  121.     'If hour < 21 And hour >= 6 Then
  122.     '    Paint (2, 2), _RGB32(0, 205, 255)
  123.     'End If
  124.     ' ============================================================================
  125.     _PutImage , hills&, 0
  126.     'Flag Pole
  127.     For sz = .25 To 10 Step .25
  128.         Circle (145, 80), sz, _RGB32(122, 128, 166)
  129.     Next sz
  130.     Line (142, 80)-(147, 600), _RGB32(122, 128, 166), BF
  131.     fx2 = fx2 + 1.2
  132.     If fx2 > 5 Then fx2 = 1.2
  133.     For fy = 100 To 341.6
  134.         For fx = 150 To 612.5
  135.             t6 = t6 + 1
  136.             PSet ((Sin(fy * 0.017453 / fx2) * t) + fx, (Sin(fx * 0.017453 / fx2) * t) + fy), cf&(t6)
  137.         Next fx
  138.     Next fy
  139.     t6 = 0
  140.     If tt = 0 Then t = t + 1
  141.     If t > 10 Then tt = 1
  142.     If tt = 1 Then t = t - 1
  143.     If t < -10 Then tt = 0
  144.     a$ = InKey$
  145.     If a$ = Chr$(27) Then End
  146.     If a$ = " " Then GoSub hills:
  147.     _Display
  148.     Cls
  149.  
  150. hills:
  151. 'Random Hills
  152. hills& = _NewImage(_Width, _Height, 32)
  153. _Dest hills&
  154. hills = Int(Rnd * 40) + 3
  155. For h = 1 To hills
  156.     hx = Int(Rnd * 800) + 1
  157.     size = Int(Rnd * 450) + 75
  158.     cl = Int(Rnd * 55)
  159.     shape = Rnd
  160.     For sz = .25 To size Step .25
  161.         cl = cl + .05
  162.         Circle (hx, 599), sz, _RGB32(10, cl, 20), , , shape
  163.     Next sz
  164.  
  165. '//interpolation code by rattrapmax6
  166. Sub MakePalette (sr, sg, sb, er, eg, eb) ' (b+) start and end RGB's ? yes
  167.     Dim i, istart(3), iend(3), ishow(3), rend(3), interpol(3)
  168.  
  169.     interpol(0) = 255
  170.     istart(1) = sr
  171.     istart(2) = sg
  172.     istart(3) = sb
  173.     iend(1) = er
  174.     iend(2) = eg
  175.     iend(3) = eb
  176.     interpol(1) = (istart(1) - iend(1)) / interpol(0)
  177.     interpol(2) = (istart(2) - iend(2)) / interpol(0)
  178.     interpol(3) = (istart(3) - iend(3)) / interpol(0)
  179.     rend(1) = istart(1)
  180.     rend(2) = istart(2)
  181.     rend(3) = istart(3)
  182.  
  183.     For i = 0 To 255
  184.         ishow(1) = rend(1)
  185.         ishow(2) = rend(2)
  186.         ishow(3) = rend(3)
  187.  
  188.         pal(i) = _RGB32(ishow(1), ishow(2), ishow(3))
  189.  
  190.         rend(1) = rend(1) - interpol(1)
  191.         rend(2) = rend(2) - interpol(2)
  192.         rend(3) = rend(3) - interpol(3)
  193.     Next i
  194.  
  195. '//generates random noise.
  196. Sub GenerateNoise ()
  197.     Dim As Long x, y
  198.  
  199.     For x = 0 To nn * twidth - 1
  200.         For y = 0 To theight - 1
  201.             zz = Rnd
  202.             noise(x + y * twidth) = zz
  203.         Next y
  204.     Next x
  205.  
  206.  
  207. Function SmoothNoise (x, y)
  208.     '//get fractional part of x and y
  209.     Dim fractx, fracty, x1, y1, x2, y2, value
  210.     fractx = x - Int(x)
  211.     fracty = y - Int(y)
  212.  
  213.     '//wrap around
  214.     x1 = (Int(x) + nn * twidth) Mod twidth
  215.     y1 = (Int(y) + theight) Mod theight
  216.  
  217.     '//neighbor values
  218.     x2 = (x1 + nn * twidth - 1) Mod twidth
  219.     y2 = (y1 + theight - 1) Mod theight
  220.  
  221.     '//smooth the noise with bilinear interpolation
  222.     value = 0.0
  223.     value = value + fractx * fracty * noise(x1 + y1 * twidth)
  224.     value = value + fractx * (1 - fracty) * noise(x1 + y2 * twidth)
  225.     value = value + (1 - fractx) * fracty * noise(x2 + y1 * twidth)
  226.     value = value + (1 - fractx) * (1 - fracty) * noise(x2 + y2 * twidth)
  227.  
  228.     SmoothNoise = value
  229.  
  230. Function Turbulence (x, y, size)
  231.     Dim value, initialsize
  232.  
  233.     initialsize = size
  234.     While (size >= 1)
  235.         value = value + SmoothNoise(x / size, y / size) * size
  236.         size = size / 2.0
  237.     Wend
  238.     Turbulence = (128.0 * value / initialsize)
  239.  
  240. '//builds the texture.
  241. Sub buildtexture
  242.     Dim x, y
  243.  
  244.     For x = 0 To nn * twidth - 1
  245.         For y = 0 To theight - 1
  246.             texture(x + y * nn * twidth) = Turbulence(x, y, zoom)
  247.         Next y
  248.     Next x
  249.  
  250. '//draws texture to screen.
  251. Sub drawtexture (dx)
  252.     Dim x, y
  253.     Dim As Long c, r, g, b
  254.  
  255.     For x = 0 To twidth - 1
  256.         For y = 0 To theight - 1
  257.             c = pal(texture(((x + dx) + y * nn * twidth)))
  258.             r = _Red(c)
  259.             g = _Green(c)
  260.             b = _Blue(c)
  261.             c = _RGB(r - 0.2 * y, g - 0.2 * y, b - 0.2 * b)
  262.             PSet (x, y), c 'pal(texture(((x + dx) + y * nn*twidth)))
  263.         Next y
  264.     Next x
  265.  
  266.  
  267.  
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: OldMoses on February 09, 2022, 12:58:19 pm
When I change hills the memory does tick upward in Task Manager.
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: bplus on February 09, 2022, 01:04:46 pm
I'm not seeing it my CPU is going back and forth but this might stop an uptick:
Code: QB64: [Select]
  1. hills:
  2. 'Random Hills
  3. If hills& Then _FreeImage (hills&)  ' <<<<<<<<<<<<<<<<<< insert
  4. hills& = _NewImage(_Width, _Height, 32)
  5. _Dest hills&
  6.  
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: SierraKen on February 09, 2022, 01:09:04 pm
Wow I am so embarrassed. I don't know what happened last night to make the clouds not move. I'm guessing I left out some code and put the wrong code here, sorry about that everyone. B+, as always I want to thank you for fixing it. I would have had to start from where started yesterday. Also, thanks for telling me about the memory leak, you too OldMoses. I fixed it by adding a
IF hills&<>0 then _FREEIMAGE hills& right before it makes a new one. I'll post the update over the original ones above because I don't want anyone trying that.
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: bplus on February 09, 2022, 02:48:28 pm
Hey Ken, I could see you did have clouds working after I found what was preventing then from being shown. Not sure what you were thinking with the time thing?
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: SierraKen on February 09, 2022, 02:50:01 pm
The only time thing I can remember is the switching between different hills, using a TIMER. Maybe I put it in the wrong place. But I know it was working last night at some point.  lol
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: bplus on February 09, 2022, 02:51:53 pm
It was here drawing sky:
Code: QB64: [Select]
  1.     'Sky
  2.     ' ========================================= this code is blocking out the clouds
  3.     'hour$ = Left$(Time$, 2)
  4.     'hour = Val(hour$)
  5.     'If hour < 21 And hour >= 6 Then
  6.     '    Paint (2, 2), _RGB32(0, 205, 255)
  7.     'End If
  8.     ' ============================================================================
  9.  

I commented out the code and the moving clouds worked fine.
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: SierraKen on February 09, 2022, 02:59:08 pm
Wow OK, I see that also in an older version of the flag. What it was for is changing the sky to a blue daytime when it was daytime in the real world using the clock. Yeah it wouldn't work anyway with the clouds, thanks for pointing that out. The reason why it worked for me last night was because in the real world it was night time therefore it didn't change the sky color. LOL
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: SMcNeill on February 09, 2022, 03:05:04 pm
Wouldn't you just draw the clouds on top of the sky?  A simple change in order of operations might be all you need.
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: SierraKen on February 09, 2022, 03:11:55 pm
Steve, no reason to if you would never see it. The clouds are there 24/7 unless I want to change it. But I would rather not because the clouds are so cool to watch.
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: bplus on February 09, 2022, 03:24:51 pm
@SMcNeill  the clouds are sky and cloud generated by a noise texture routine first discussed here:
https://qb64forum.alephc.xyz/index.php?topic=4615.msg140454#msg140454

Vince made a good mod of some code I translated from Yabasic.

Then Ken probably picked up here:
https://qb64forum.alephc.xyz/index.php?topic=4638.msg140509#msg140509
Where vince included the sky cloud code without labels in Falling letters game.
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: _vince on February 12, 2022, 05:55:44 pm
B+ mod time, you know the drill

Code: QB64: [Select]
  1. _Title "U.S. Flag - Use space bar to change hills background."
  2. const sw = 800
  3. const sh = 600
  4. Screen _NewImage(sw, sh, 32)
  5. x = 150
  6. y = 100
  7. Dim cf&(113000)
  8.  
  9. Const nn = 1
  10. Const twidth = sw, theight = sh, zoom = 128
  11. Dim Shared noise(nn * twidth * theight) '//the noise array
  12. Dim Shared texture(nn * twidth * theight) '//texture array
  13. Dim Shared pal(256) As _Unsigned Long '//color palette
  14.  
  15. MakePalette 255, 155, 255, 10, 100, 180
  16. GenerateNoise
  17. buildtexture
  18.  
  19. vs = _NewImage(twidth, theight, 32)
  20. drawtexture 0
  21.  
  22. GoSub hills:
  23.  
  24. dim vvs as long
  25. vvs = _newimage(sw, sh, 32)
  26. vvs2 = _newimage(sw, sh, 32)
  27. _dest vvs
  28.  
  29. 'Stars
  30. Line (x, y)-(x + 185, y + 130), _RGB32(0, 0, 255), BF
  31. For xx = 155 To 345 Step 32
  32.     For yy = 105 To 220 Step 28
  33.         Line (xx + 2, yy + 12)-(xx + 7, yy), _RGB32(255, 255, 255)
  34.         Line (xx + 7, yy)-(xx + 13, yy + 12), _RGB32(255, 255, 255)
  35.         Line (xx + 13, yy + 12)-(xx, yy + 5), _RGB32(255, 255, 255)
  36.         Line (xx, yy + 5)-(xx + 15, yy + 5), _RGB32(255, 255, 255)
  37.         Line (xx + 15, yy + 5)-(xx + 2, yy + 12), _RGB32(255, 255, 255)
  38.         Paint (xx + 7, yy + 2), _RGB32(255, 255, 255)
  39.         Paint (xx + 7, yy + 6), _RGB32(255, 255, 255)
  40.         Paint (xx + 11, yy + 10), _RGB32(255, 255, 255)
  41.         Paint (xx + 4, yy + 10), _RGB32(255, 255, 255)
  42.         Paint (xx + 3, yy + 6), _RGB32(255, 255, 255)
  43.         Paint (xx + 12, yy + 6), _RGB32(255, 255, 255)
  44.     Next yy
  45. Next xx
  46.  
  47. For xx = 172 To 329 Step 32
  48.     For yy = 118.9 To 213.05 Step 28
  49.         Line (xx + 2, yy + 12)-(xx + 7, yy), _RGB32(255, 255, 255)
  50.         Line (xx + 7, yy)-(xx + 13, yy + 12), _RGB32(255, 255, 255)
  51.         Line (xx + 13, yy + 12)-(xx, yy + 5), _RGB32(255, 255, 255)
  52.         Line (xx, yy + 5)-(xx + 15, yy + 5), _RGB32(255, 255, 255)
  53.         Line (xx + 15, yy + 5)-(xx + 2, yy + 12), _RGB32(255, 255, 255)
  54.         Paint (xx + 7, yy + 2), _RGB32(255, 255, 255)
  55.         Paint (xx + 7, yy + 6), _RGB32(255, 255, 255)
  56.         Paint (xx + 11, yy + 10), _RGB32(255, 255, 255)
  57.         Paint (xx + 4, yy + 10), _RGB32(255, 255, 255)
  58.         Paint (xx + 3, yy + 6), _RGB32(255, 255, 255)
  59.         Paint (xx + 12, yy + 6), _RGB32(255, 255, 255)
  60.     Next yy
  61. Next xx
  62.  
  63. 'Stripes
  64. For rs = 100 To 230 Step 37.2
  65.     w = w + 1
  66.     Line (335, rs)-(612.5, rs + 18.6), _RGB32(255, 0, 0), BF
  67.     If w > 3 Then GoTo nex:
  68.     Line (335, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 255, 255), BF
  69. Next rs
  70. nex:
  71. w = 0
  72. dim z(98) as _unsigned _integer64 'Marshawn polynomial coefficients of the nth order
  73. z(0)=&h3000000~&&:z(1)=&hFFF8~&&:z(2)=&h0~&&:z(3)=&h830E000000000000~&&
  74. z(4)=&h47FF080000000~&&:z(5)=&h1BFFFE6000~&&:z(6)=&h37FFFE~&&
  75. z(7)=&h900000000000006E~&&:z(8)=&hFFFFC80000000000~&&:z(9)=&h5FFFFFE8000000~&&
  76. z(10)=&hBFFFFFF400~&&:z(11)=&h17FFFFE~&&:z(12)=&hF80000000000017A~&&
  77. z(13)=&hFFFFFA0000000000~&&:z(14)=&h2F7FFFFFA000000~&&:z(15)=&h2EDFFFFFF00~&&
  78. z(16)=&h2DBFFFE~&&:z(17)=&hFD000000000002D6~&&:z(18)=&hFFFFED0000000000~&&
  79. z(19)=&h2B7FFFFAD000000~&&:z(20)=&h6B41FC7AD00~&&:z(21)=&h6E3EFB8~&&
  80. z(22)=&hAD0000000000066C~&&:z(23)=&h17463D0000000000~&&:z(24)=&h2D016C0B5000000~&&
  81. z(25)=&h2B00A805900~&&:z(26)=&h2A00A80~&&:z(27)=&h1B000000000002A0~&&
  82. z(28)=&h9801A0000000000~&&:z(29)=&h3A00A801A000000~&&:z(30)=&hA008805A00~&&
  83. z(31)=&h901660~&&:z(32)=&h580000000000026E~&&:z(33)=&hEC90D00000000000~&&
  84. z(34)=&h2F0096F2F000000~&&:z(35)=&h6FFE9B0F100~&&:z(36)=&h2FFD0BE~&&
  85. z(37)=&hFD000000000002C6~&&:z(38)=&hD2DFFD0000000000~&&:z(39)=&h33BD55F1B000000~&&
  86. z(40)=&h16DEDBDEA00~&&:z(41)=&h54F27A~&&:z(42)=&hF400000000000046~&&
  87. z(43)=&hEEFAA80000000000~&&:z(44)=&h4B5D5EA0000000~&&:z(45)=&h6BD1AFA000~&&
  88. z(46)=&h69FFFA~&&:z(47)=&h64~&&:z(48)=&h57AB400000000000~&&:z(49)=&h25D7AF40000000~&&
  89. z(50)=&h2BF3BF4000~&&:z(51)=&h2B7FEE~&&:z(52)=&h4000000000000024~&&
  90. z(53)=&h6EAEC00000000000~&&:z(54)=&h19FEBC80000000~&&:z(55)=&h4FFBC8000~&&
  91. z(56)=&hE000003C0002AFC8~&&:z(57)=&h1080000420000~&&:z(58)=&h7032000204000040~&&
  92. z(59)=&hBFEC00020400~&&:z(60)=&h8080009FC80004~&&:z(61)=&h400004060004010~&&
  93. z(62)=&h18040000C19C00~&&:z(63)=&h3FE0007604000080~&&:z(64)=&h8700000003860400~&&
  94. z(65)=&h100F0E000000C1E~&&:z(66)=&h2000100E61C0000~&&:z(67)=&hE1CC010001009FC2~&&
  95. z(68)=&hC0078FF601000100~&&:z(69)=&h3B8703837020200~&&:z(70)=&h101803F2FC3B002~&&
  96. z(71)=&h2000101FC07F83E~&&:z(72)=&h80FE0200008207C0~&&:z(73)=&hF01C0F810600005C~&&
  97. z(74)=&h3C00007800E800~&&:z(75)=&h1F00036000~&&:z(76)=&h1DFE01E~&&
  98. z(77)=&hEE00000000001E7E~&&:z(78)=&h8307F9E000000000~&&:z(79)=&hE3FC1CE07F1C0000~&&
  99. z(80)=&h381E3FC1C00E0FF0~&&:z(81)=&hC03047F1FF0F0002~&&:z(82)=&hC3FE3FC8C31E7078~&&
  100. z(83)=&h3839C10C83E2~&&:z(84)=&h8180000006071B04~&&:z(85)=&hC2180C00000000C0~&&
  101. z(86)=&h610442E070000000~&&:z(87)=&h381D085B018000~&&:z(88)=&h60348360C~&&:z(89)=&h181B0~&&
  102. z(90)=&h2430000000000000~&&:z(91)=&h30D0C04000000000~&&:z(92)=&h80D00800000~&&
  103. z(93)=&h4070100~&&:z(94)=&h202~&&:z(95)=&h8200000000000000~&&:z(96)=&h1045C0000000000~&&
  104. z(97)=&hEC60000000~&&
  105. dim as _unsigned _integer64 b, i, n, j,d
  106. redim f(320, 240) as double
  107. redim ff(320, 240) as double
  108. dim p(300) as long
  109. for i=1 to 100
  110.         fr = 240*i/100 + 15
  111.         p(i) = _rgb(fr,0,0)
  112.         p(i + 100) = _rgb(255, fr, 0)
  113.         p(i + 200) = _rgb(255, 255, fr)
  114. For rs = 230 To 341.6 Step 37.2
  115.     r = r + 1
  116.     Line (150, rs)-(612.5, rs + 18.6), _RGB32(255, 255, 255), BF
  117.     If r > 3 Then GoTo nex2:
  118.     Line (150, rs + 18.6)-(612.5, rs + 37.2), _RGB32(255, 0, 0), BF
  119. Next rs
  120. i = 0
  121. n = 0
  122. b = z(n)
  123. xstep = 3
  124. ystep = 2
  125. for y=0 to 79-1
  126. for x=0 to 80-1
  127.         if (b and _shl(1~&&, 63)) then
  128.                 line (280 + x*xstep, 150 + y*ystep)-step(xstep,ystep),_rgb(0,0,0),bf
  129.                 f (x + 120, y + 80) = 300
  130.                 ff(x + 120, y + 80) = 300
  131.         end if
  132.         b = _shl(b, 1~&&)
  133.         i=i+1
  134.         if i = 64 then
  135.                 n = n + 1
  136.                 b = z(n)
  137.                 i = 0
  138.         end if
  139. paint (370,190),_rgb(0,0,0)
  140. paint (420,190),_rgb(0,0,0)
  141. _source vvs2
  142. nex2:
  143. r = 0
  144. For fy = 100 To 341.6
  145.     For fx = 150 To 612.5
  146.         t5 = t5 + 1
  147.         cf&(t5) = Point(fx, fy)
  148.     Next fx
  149. Next fy
  150. t = 20
  151.  
  152. 'On Timer(2) GoSub hills:
  153. 'Timer On
  154.  
  155. ii = 0
  156. jj = -1
  157.  
  158.     'Sky
  159.     ii = ii + 1
  160.     If ii >= sw Then
  161.         ii = 0
  162.         jj = Not jj
  163.     End If
  164.  
  165.     If jj Then
  166.         _PutImage (ii, 0)-Step(sw, sh), vs
  167.         _PutImage (ii, 0)-Step(-sw, sh), vs
  168.     Else
  169.         _PutImage (ii + sw, 0)-Step(-sw, sh), vs
  170.         _PutImage (ii - sw, 0)-Step(sw, sh), vs
  171.     End If
  172.  
  173.     'hour$ = Left$(Time$, 2)
  174.     'hour = Val(hour$)
  175.     'If hour < 21 And hour >= 6 Then
  176.         'Paint (2, 2), _RGB32(0, 205, 255)
  177.     'End If
  178.     _PutImage , hills&, 0
  179.     'Flag Pole
  180.     For sz = .25 To 10 Step .25
  181.         Circle (145, 80), sz, _RGB32(122, 128, 166)
  182.     Next sz
  183.     Line (142, 80)-(147, 600), _RGB32(122, 128, 166), BF
  184.  
  185.         _dest vvs2
  186.         _putimage ,vvs
  187.         for y=1 to 240-1
  188.         for x=1 to 320-1
  189.                 dim r as double
  190.                 r = rnd
  191.                 if r > 0.65 then f(x,y) = ff(x,y)
  192.         next
  193.         next
  194.         for y=0 to 240-2
  195.         for x=1 to 320-1
  196.                 f(x,y) = max((f(x-1,y+1) + f(x,y+1) + f(x+1,y+1) + f(x-1,y+2))/4 - 5, 0)
  197.                 line (x*xstep - 81, y*ystep - 6)-step(xstep, ystep), p(f(x,y)),bf
  198.         next
  199.         next
  200.  
  201.         _source vvs2
  202.         r = 0
  203.         t5 = 0
  204.         For fy = 100 To 341.6
  205.                 For fx = 150 To 612.5
  206.                         t5 = t5 + 1
  207.                         cf&(t5) = Point(fx, fy)
  208.                 Next fx
  209.         Next fy
  210.         t = 20
  211.         _source 0
  212.         _dest 0
  213.  
  214.     fx2 = fx2 + 1.2
  215.     If fx2 > 5 Then fx2 = 1.2
  216.     For fy = 100 To 341.6
  217.         For fx = 150 To 612.5
  218.             t6 = t6 + 1
  219.                         if cf&(t6) <> _rgb(0,0,0) then
  220.                         PSet ((Sin(fy * 0.017453 / fx2) * t) + fx, (Sin(fx * 0.017453 / fx2) * t) + fy), cf&(t6)
  221.                         end if
  222.         Next fx
  223.     Next fy
  224.  
  225.     t6 = 0
  226.     If tt = 0 Then t = t + 1
  227.     If t > 10 Then tt = 1
  228.     If tt = 1 Then t = t - 1
  229.     If t < -10 Then tt = 0
  230.     a$ = InKey$
  231.     If a$ = Chr$(27) Then End
  232.     'If a$ = " " Then
  233.         GoSub hills:
  234.  
  235.     _Display
  236.     _Limit 50
  237.  
  238. hills:
  239. 'Random Hills
  240. hills& = _NewImage(_Width, _Height, 32)
  241. _Dest hills&
  242. hills = 8'Int(Rnd * 40) + 3
  243. For h = -3 To hills + 1
  244.     hx = 800*h/hills + (ii*8 mod 300) 'Int(Rnd * 800) + 1
  245.     size = 300'Int(Rnd * 450) + 75
  246.     cl = 15'Int(Rnd * 55)
  247.     shape = 0.7'Rnd
  248.     For sz = .25 To size Step .25
  249.         cl = cl + .05
  250.         Circle (hx, 599), sz, _RGB32(10, cl, 20), , , shape
  251.     Next sz
  252. hills = 5'Int(Rnd * 40) + 3
  253. For h = -3 To hills + 1
  254.     hx = 800*h/hills + (ii*5 mod 300) 'Int(Rnd * 800) + 1
  255.     size = 250'Int(Rnd * 450) + 75
  256.     cl = 35'Int(Rnd * 55)
  257.     shape = 0.7'Rnd
  258.     For sz = .25 To size Step .25
  259.         cl = cl + .05
  260.         Circle (hx, 599), sz, _RGB32(10, cl, 20), , , shape
  261.     Next sz
  262. hills = 3'Int(Rnd * 40) + 3
  263. For h = -3 To hills + 1
  264.     hx = 800*h/hills + (ii mod 300) 'Int(Rnd * 800) + 1
  265.     size = 180'Int(Rnd * 450) + 75
  266.     cl = 55'Int(Rnd * 55)
  267.     shape = 0.7'Rnd
  268.     For sz = .25 To size Step .25
  269.         cl = cl + .05
  270.         Circle (hx, 599), sz, _RGB32(10, cl, 20), , , shape
  271.     Next sz
  272.  
  273. function max(a, b)
  274.         if a > b then max = a else max = b'+
  275.  
  276. '//interpolation code by rattrapmax6
  277. Sub MakePalette (sr, sg, sb, er, eg, eb) ' (b+) start and end RGB's ? yes
  278.     Dim i, istart(3), iend(3), ishow(3), rend(3), interpol(3)
  279.  
  280.     interpol(0) = 255
  281.     istart(1) = sr
  282.     istart(2) = sg
  283.     istart(3) = sb
  284.     iend(1) = er
  285.     iend(2) = eg
  286.     iend(3) = eb
  287.     interpol(1) = (istart(1) - iend(1)) / interpol(0)
  288.     interpol(2) = (istart(2) - iend(2)) / interpol(0)
  289.     interpol(3) = (istart(3) - iend(3)) / interpol(0)
  290.     rend(1) = istart(1)
  291.     rend(2) = istart(2)
  292.     rend(3) = istart(3)
  293.  
  294.     For i = 0 To 255
  295.         ishow(1) = rend(1)
  296.         ishow(2) = rend(2)
  297.         ishow(3) = rend(3)
  298.  
  299.         pal(i) = _RGB32(ishow(1), ishow(2), ishow(3))
  300.  
  301.         rend(1) = rend(1) - interpol(1)
  302.         rend(2) = rend(2) - interpol(2)
  303.         rend(3) = rend(3) - interpol(3)
  304.     Next i
  305.  
  306. '//generates random noise.
  307. Sub GenerateNoise ()
  308.     Dim As Long x, y
  309.  
  310.     For x = 0 To nn * twidth - 1
  311.         For y = 0 To theight - 1
  312.             zz = Rnd
  313.             noise(x + y * twidth) = zz
  314.         Next y
  315.     Next x
  316.  
  317.  
  318. Function SmoothNoise (x, y)
  319.     '//get fractional part of x and y
  320.     Dim fractx, fracty, x1, y1, x2, y2, value
  321.     fractx = x - Int(x)
  322.     fracty = y - Int(y)
  323.  
  324.     '//wrap around
  325.     x1 = (Int(x) + nn * twidth) Mod twidth
  326.     y1 = (Int(y) + theight) Mod theight
  327.  
  328.     '//neighbor values
  329.     x2 = (x1 + nn * twidth - 1) Mod twidth
  330.     y2 = (y1 + theight - 1) Mod theight
  331.  
  332.     '//smooth the noise with bilinear interpolation
  333.     value = 0.0
  334.     value = value + fractx * fracty * noise(x1 + y1 * twidth)
  335.     value = value + fractx * (1 - fracty) * noise(x1 + y2 * twidth)
  336.     value = value + (1 - fractx) * fracty * noise(x2 + y1 * twidth)
  337.     value = value + (1 - fractx) * (1 - fracty) * noise(x2 + y2 * twidth)
  338.  
  339.     SmoothNoise = value
  340.  
  341. Function Turbulence (x, y, size)
  342.     Dim value, initialsize
  343.  
  344.     initialsize = size
  345.     While (size >= 1)
  346.         value = value + SmoothNoise(x / size, y / size) * size
  347.         size = size / 2.0
  348.     Wend
  349.     Turbulence = (128.0 * value / initialsize)
  350.  
  351. '//builds the texture.
  352. Sub buildtexture
  353.     Dim x, y
  354.  
  355.     For x = 0 To nn * twidth - 1
  356.         For y = 0 To theight - 1
  357.             texture(x + y * nn * twidth) = Turbulence(x, y, zoom)
  358.         Next y
  359.     Next x
  360.  
  361. '//draws texture to screen.
  362. Sub drawtexture (dx)
  363.     Dim x, y
  364.     Dim As Long c, r, g, b
  365.  
  366.     For x = 0 To twidth - 1
  367.         For y = 0 To theight - 1
  368.             c = pal(texture(((x + dx) + y * nn * twidth)))
  369.             r = _Red(c)
  370.             g = _Green(c)
  371.             b = _Blue(c)
  372.             c = _RGB(r - 0.2 * y, g - 0.2 * y, b - 0.2 * b)
  373.             PSet (x, y), c 'pal(texture(((x + dx) + y * nn*twidth)))
  374.         Next y
  375.     Next x
  376.  
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: SierraKen on February 12, 2022, 06:10:20 pm
LOL Vince, looks like a Pirates Flag in the U.S. I like how the hills also move.
Title: Re: Ken's U.S. Flag version 4 - With moving clouds
Post by: bplus on February 12, 2022, 06:43:44 pm
@vince I offer a different way to move the hills:
Code: QB64: [Select]
  1. _Title "Drawlandscape Parallax test" 'started 2019-03-27
  2. 'test if can get end of landscape level to start for big looping background
  3. '2019-03-27 a more gentle adjustment back to Mountain starting height for
  4. 'more seamless connect of back end to front
  5. '2019-03-27 start this file with parallax drawing test
  6.  
  7.  
  8. Screen _NewImage(800, 600, 32)
  9. _ScreenMove 100, 20
  10. Type parallaxType
  11.     handle As Long
  12.     rate As Single 'number of pixels per frame added to le (leading edge)
  13.     le As Single
  14. nLevels = 6
  15. Dim Shared para(1 To nLevels) As parallaxType
  16.  
  17. Dim Shared scape&
  18. LoadLandscape
  19. scapeWidth = _Width(para(1).handle)
  20. scapeHeight = _Height(para(1).handle)
  21.  
  22. While t < 6000
  23.     Cls
  24.     For i = 1 To nLevels
  25.         If para(i).le + 800 > scapeWidth Then
  26.             te = scapeWidth - para(i).le
  27.             _PutImage (0, 0)-(te, scapeHeight), para(i).handle, 0, (scapeWidth - te, 0)-(scapeWidth, scapeHeight)
  28.             _PutImage (te, 0)-(800, scapeHeight), para(i).handle, 0, (0, 0)-(800 - te, scapeHeight)
  29.  
  30.         Else
  31.             _PutImage (0, 0)-(800, scapeHeight), para(i).handle, 0, (para(i).le, 0)-(para(i).le + 800, scapeHeight)
  32.         End If
  33.  
  34.         para(i).le = para(i).le - para(i).rate
  35.         If para(i).le < 0 Then para(i).le = scapeWidth
  36.     Next
  37.     t = t + 1
  38.     _Display
  39.     _Limit 120
  40.  
  41. Sub LoadLandscape
  42.     cur& = _Dest
  43.     xmax = 800 * 3.25: ymax = 600
  44.     hdl& = 1
  45.     para(hdl&).handle = _NewImage(xmax, ymax, 32)
  46.     _Dest para(hdl&).handle
  47.  
  48.     For i = 0 To ymax
  49.         midInk 0, 0, 128, 128, 128, 200, i / ymax
  50.         Line (0, i)-(xmax, i)
  51.     Next
  52.     'the land
  53.     startH = ymax - 200
  54.     rr = 70: gg = 70: bb = 90
  55.     For mountain = 1 To nLevels
  56.         If mountain > 1 Then
  57.             para(mountain).handle = _NewImage(xmax, ymax, 32)
  58.             _Dest para(mountain).handle
  59.         End If
  60.         Xright = 0
  61.         y = startH
  62.         Color _RGB(rr, gg, bb)
  63.         While Xright < xmax - 50
  64.             ' upDown = local up / down over range, change along Y
  65.             ' range = how far up / down, along X
  66.             upDown = (Rnd * .8 - .4) * (mountain * .5)
  67.             range = Xright + rand%(15, 25) * 2.5 / mountain
  68.             If range > xmax - 50 Then range = xmax - 50
  69.             lastx = Xright - 1
  70.             For x = Xright To range 'need less flat tops
  71.                 test = y + upDown
  72.                 test2 = y - upDown
  73.                 If Abs(test - startH) < .13 * startH Then y = test Else y = test2: upDown = -upDown
  74.                 Line (lastx, y)-(x, ymax), , BF 'just lines weren't filling right
  75.                 lastx = x
  76.             Next
  77.             Xright = range
  78.         Wend
  79.         x = lastx + 1
  80.         dy = (startH - y) / 50 'more gentle adjustment back to start of screen
  81.         While x <= xmax
  82.             y = y + dy
  83.             Line (lastx, y)-(x, ymax), , BF 'just lines weren't filling right
  84.             lastx = x
  85.             x = x + 1
  86.         Wend
  87.         rr = rand%(rr - 15, rr): gg = rand%(gg - 15, gg): bb = rand%(bb - 25, bb)
  88.         If rr < 0 Then rr = 0
  89.         If gg < 0 Then gg = 0
  90.         If bb < 0 Then bb = 0
  91.         startH = startH + mountain * rand%(2, 10)
  92.         para(mountain).le = xmax - 800
  93.         para(mountain).rate = mountain * .5
  94.     Next
  95.     _Dest cur&
  96.  
  97. Function rand% (lo%, hi%)
  98.     rand% = Int(Rnd * (hi% - lo% + 1)) + lo%
  99.  
  100. Sub midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  101.     Color _RGB(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  102.  
  103.