Author Topic: Ken's U.S. Flag version 4 - With moving clouds  (Read 7089 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Ken's U.S. Flag version 4 - With moving clouds
« 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.)
« Last Edit: February 09, 2022, 01:10:40 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #1 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.  

* USAFBTheStarSpangledBannerChoral.mp3 (Filesize: 1.03 MB, Downloads: 183)
« Last Edit: February 09, 2022, 01:13:23 pm by SierraKen »

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #2 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
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

FellippeHeitor

  • Guest
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #3 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.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #4 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

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #5 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

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #6 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.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #7 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.  

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #8 on: February 09, 2022, 12:58:19 pm »
When I change hills the memory does tick upward in Task Manager.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #9 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.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #10 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.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #11 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?

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #12 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

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #13 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.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Ken's U.S. Flag version 4 - With moving clouds
« Reply #14 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