Author Topic: Rain Storm Screensaver coding.  (Read 1494 times)

0 Members and 1 Guest are viewing this topic.

Offline Phlashlite

  • Newbie
  • Posts: 50
Rain Storm Screensaver coding.
« on: January 22, 2022, 03:06:07 pm »
A multi monitor screensaver I have been working on as my first coding project.  I started by translating this coding challenge:

https://www.youtube.com/watch?v=KkyIDI6rQJI

Algorithms are algorithms!

Enjoy,
Phlashlite

Code: QB64: [Select]
  1. 'A work in progress...
  2.  
  3. ' - Adding better lightnig affects.
  4. '   - Maybe adding screen flash?
  5. ' - Working on colors.
  6. ' - Add a ground plane
  7. '   - Maybe Add splash effects?
  8. ' - Add cloud layer
  9. ' - Always working on code efficiency.
  10.  
  11. 'Author: Phlashlite, Jan 2022
  12.  
  13. ' NOTES: If you see code enclosed in "++++" there are adjustable setting to play with in there.
  14.  
  15. '        The original code was translated from watching this Coding Challenge Video:
  16. '        [youtube]https://www.youtube.com/watch?v=KkyIDI6rQJI[/youtube]
  17.  
  18.  
  19. 'Most of the adjustable settings+++++++++++++++++++++++++++++++++++++++++++++++
  20.  
  21. 'Screen________________________________________________________________________
  22.  
  23. 'Your screen width
  24. CONST SCRWDTH = 5760
  25.  
  26. 'Your screen height
  27. CONST SCRHGHT = 1200
  28.  
  29. 'Virtual depth of the scene
  30. CONST SCRDPTH = 15
  31.  
  32.  
  33. 'Rain__________________________________________________________________________
  34.  
  35. 'Number of raindrops to draw
  36. CONST NUMDROPS = 5000
  37.  
  38. 'Lower limit of raindrop (drp) speed
  39. CONST LDRPSPEED = 17
  40.  
  41. 'Upper limit of drp speed
  42. CONST UDRPSPEED = 30
  43.  
  44. 'Lower limit of drp length
  45. CONST LDRPLENGTH = 3
  46.  
  47. 'Upper limit of drp length
  48. CONST UDRPLENGTH = 40
  49.  
  50. 'Lower limit of drp width
  51. CONST LDRPWDTH = 1
  52.  
  53. 'Upper limit of drp width
  54. CONST UDRPWDTH = 5
  55.  
  56.  
  57. 'Lightning_____________________________________________________________________
  58.  
  59. 'Bolt detail, smaller is more detailed, 7 is default
  60. CONST BLTDETAIL = 1
  61.  
  62. 'How crazy the bolt path is (angle displacement) 500 is default
  63. CONST BLTDISP = 500
  64.  
  65. 'Bolt width
  66. CONST BLTWDTH = 1
  67.  
  68. 'Bolt Glow width
  69. CONST BLTGLOW = 50
  70.  
  71. 'Ticks Bolt is on screen
  72. CONST BLTTIME = 2
  73.  
  74. 'Frequency of Bolts.  Range is 1 to 1000. > = less frequency.
  75. CONST BLTFFREQ = 995
  76. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  77.  
  78. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  79. _MOUSEHIDE 'hide the mouse if you want (use if you are going to use as a screensaver
  80. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  81.  
  82. SCREEN _NEWIMAGE(SCRWDTH, SCRHGHT, 32) ' set the drawing screen
  83.  
  84. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  85. _SCREENMOVE (-SCRWDTH / 3) - 3, -26 'Moves the screen to hide widows title bars and frames
  86. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  87.  
  88. 'this is a drp
  89. TYPE Drop
  90.     x AS SINGLE '   x coordinate
  91.     y AS SINGLE '   y coordinate
  92.     z AS SINGLE '   z virtual coordinate
  93.     wth AS SINGLE ' drp width
  94.     lng AS SINGLE ' drp length
  95.     spd AS SINGLE ' drp speed
  96.  
  97.  
  98. 'GroundY = SCRHGHT * 0.75
  99.  
  100. 'Initialize and fill the array that holds all the drops________________________
  101. DIM SHARED Rain(NUMDROPS) AS Drop
  102.  
  103. FOR i% = 0 TO NUMDROPS
  104.     fillDropArray (i%)
  105.  
  106. 'Main loop to draw each Drop and call the lightning bolts______________________
  107.     FOR i% = 0 TO NUMDROPS
  108.  
  109.         'Fall
  110.         Rain(i%).y = Rain(i%).y + Rain(i%).spd
  111.  
  112.         'Draw
  113.         LINE (Rain(i%).x, Rain(i%).y)-(Rain(i%).x + Rain(i%).wth, Rain(i%).y + Rain(i%).lng), _RGBA(161, 166, 172, 100), BF
  114.  
  115.         'Fill
  116.         'Restart each Drop in the array if it's y value passes the bottom of the screen (SCRHGHT)
  117.         IF Rain(i%).y > SCRHGHT THEN
  118.             fillDropArray (i%)
  119.         END IF
  120.  
  121.     NEXT
  122.  
  123.     'Call the lightning bolt (blt)_____________________________________________
  124.  
  125.     'How far the bolt wanders++++++++++++++++++++++++++++++++++++++++++++++++++
  126.     x1! = Rndm!(-10, SCRWDTH + 10) 'Sets blts x axis starting point range
  127.  
  128.     x2! = Rndm!(x1! - 500, x1! + 500) 'Sets how much a blts end x axis point
  129.     '                                  varies from its starting x axis point
  130.  
  131.     y1! = 0 ' Rndm!(0, SCRHGHT - 1000) 'Sets blts y axis starting point range
  132.  
  133.     y2! = Rndm!(1000, SCRHGHT) 'Sets blts y axis ending point range
  134.  
  135.     'Adjust how often bolts strike+++++++++++++++++++++++++++++++++++++++++++++
  136.     k% = Rndm(1, 1000)
  137.     IF k% > BLTFFREQ THEN drawLightning x1!, y1!, x2!, y2!, BLTDISP
  138.     '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  139.  
  140.     '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  141.     _LIMIT 40
  142.     '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  143.  
  144.     _DISPLAY
  145.     CLS
  146.  
  147.  
  148. '______________________________________________________________________________
  149.  
  150. 'Does all the drop calculations and fills the array.
  151.  
  152. SUB fillDropArray (i%)
  153.  
  154.     Rain(i%).x = Rndm(0, SCRWDTH)
  155.     Rain(i%).y = Rndm(-SCRHGHT, 0) 'start drops off screen on the y axis
  156.  
  157.     'bias rnd# gen for  more drops farther away (shorter, slower, narrower)___
  158.     j! = Rndm(1, SCRDPTH * 2.5)
  159.     IF j! > SCRDPTH THEN j! = Rndm(1, SCRDPTH * .25)
  160.  
  161.     Rain(i%).z = j! 'Rndm(1, SCRDPTH)
  162.     Rain(i%).wth = map(Rain(i%).z, 0, SCRDPTH, LDRPWDTH, UDRPWDTH)
  163.     Rain(i%).lng = map(Rain(i%).z, 0, SCRDPTH, LDRPLENGTH, UDRPLENGTH)
  164.     Rain(i%).spd = map(Rain(i%).z, 0, SCRDPTH, LDRPSPEED, UDRPSPEED)
  165.  
  166.  
  167. '______________________________________________________________________________
  168.  
  169. 'Does all the lightning calculations usimg a "midpoint displacement alrorithm".
  170.  
  171. SUB drawLightning (x1!, y1!, x2!, y2!, BLTDISP)
  172.  
  173.     DIM midX!, midY!
  174.  
  175.     IF BLTDISP < BLTDETAIL THEN
  176.  
  177.         FOR l% = 1 TO BLTTIME
  178.             LINE (x1!, y1!)-(x2! + BLTWDTH, y2!), _RGBA(255, 255, 255, 255), BF
  179.         NEXT
  180.  
  181.     ELSE
  182.         midX = (x1! + x2!) / 2
  183.         midY = (y1! + y2!) / 2
  184.         midX! = midX! + (RND - .5) * BLTDISP
  185.         midY! = midY! + (RND - .5) * BLTDISP
  186.  
  187.         drawLightning x1!, y1!, midX!, midY!, BLTDISP / 2
  188.         drawLightning x2!, y2!, midX!, midY!, BLTDISP / 2
  189.  
  190.     END IF
  191.  
  192.  
  193. '______________________________________________________________________________
  194.  
  195. 'Standard random numbers in a range of mn! (min) to mx! (max)
  196.  
  197. FUNCTION Rndm! (mn!, mx!)
  198.     IF mn! > mx! THEN
  199.         SWAP mn!, mx!
  200.     END IF
  201.     Rndm! = RND * (mx! - mn!) + mn!
  202.  
  203. '______________________________________________________________________________
  204.  
  205. ' Map function I found or translated from somewhere.
  206. ' The Coding Train" guy on youtube, where I translated the rain code from explained it in one of his videos.
  207.  
  208. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  209.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  210.  
  211.  
  212.  
  213.  


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Rain Storm Screensaver coding.
« Reply #1 on: January 22, 2022, 03:22:47 pm »
Hey another lightning fan! :)

Welcome to forum @Phlashlite

Offline Phlashlite

  • Newbie
  • Posts: 50
Re: Rain Storm Screensaver coding.
« Reply #2 on: January 22, 2022, 03:29:50 pm »
@bplus

Thanks!  I've been lurking forever... lol!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: Rain Storm Screensaver coding.
« Reply #3 on: January 22, 2022, 03:30:17 pm »
Fascinating.
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Rain Storm Screensaver coding.
« Reply #4 on: January 22, 2022, 03:33:16 pm »
@bplus

Thanks!  I've been lurking forever... lol!

Glad you came out of the closet, we could always use more graphics code. Got any strange clocks?

Offline Phlashlite

  • Newbie
  • Posts: 50
Re: Rain Storm Screensaver coding.
« Reply #5 on: January 22, 2022, 03:45:22 pm »
Glad you came out of the closet, we could always use more graphics code. Got any strange clocks?

Only in my mind...

I honestly haven't done any graphics coding before and only any other coding out of necessity.

I'm a technical writer by trade, if you didn't catch that by all the code comments :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Rain Storm Screensaver coding.
« Reply #6 on: January 22, 2022, 04:05:18 pm »
@Phlashlite

You might like this:
Code: QB64: [Select]
  1. 'Rain Drain.bas started 2017-09-13
  2. 'translated from
  3. 'Rain Drain.bas  SmallBASIC 0.12.9 [B+=MGA] 2017-04-26
  4.  
  5. Const xmax = 1100
  6. Const ymax = 700
  7.  
  8. Screen _NewImage(xmax, ymax, 32)
  9. _Delay .25
  10. _Title "Rain Drain by bplus,    spacebar for new arrangement,    esc to quit"
  11.  
  12. Type ball
  13.     x As Single
  14.     y As Single
  15.     speed As Single
  16.     r As Single
  17.     c As Long
  18.  
  19. Type bLine
  20.     x1 As Integer
  21.     y1 As Integer
  22.     x2 As Integer
  23.     y2 As Integer
  24.     a As Double
  25.  
  26.     balls = 2500
  27.     ReDim b(balls) As ball
  28.     For i = 1 To balls
  29.         b(i).x = Rnd * xmax
  30.         b(i).y = Rnd * ymax
  31.         b(i).speed = 9.85
  32.         b(i).r = 5
  33.         b(i).c = _RGB(0, rand%(200, 255), rand%(200, 255))
  34.     Next
  35.  
  36.     m = 10
  37.     nbl = 12
  38.     ReDim bl(nbl) As bLine
  39.     For i = 1 To nbl
  40.         d = rand%(50, 200)
  41.         bl(i).x1 = rand%(m, xmax - d - m)
  42.         bl(i).y1 = i * ymax / nbl - 10
  43.         bl(i).a = Rnd * _Pi(1 / 32) - _Pi(1 / 64)
  44.         bl(i).x2 = bl(i).x1 + d * Cos(bl(i).a)
  45.         bl(i).y2 = bl(i).y1 + d * Sin(bl(i).a)
  46.     Next
  47.  
  48.     While 1
  49.         Cls
  50.         If 32 = _KeyHit Then
  51.             Exit While
  52.         ElseIf 27 = _KeyHit Then
  53.             End
  54.         End If
  55.         For j = 1 To balls
  56.             If b(j).y - b(j).r > ymax Or b(j).x + b(j).r < 0 Or b(j).x - b(j).r > xmax Then
  57.                 b(j).x = rand%(0, xmax): b(j).y = 0
  58.             End If
  59.             Color b(j).c
  60.             fcirc b(j).x, b(j).y, b(j).r
  61.             testx = b(j).x + b(j).speed * Cos(_Pi(.5))
  62.             testy = b(j).y + b(j).speed * Sin(_Pi(.5))
  63.             cFlag = 0
  64.             For i = 1 To nbl
  65.                 Color _RGB(255, 0, 0)
  66.                 lien bl(i).x1, bl(i).y1, bl(i).x2, bl(i).y2
  67.                 If cFlag = 0 Then
  68.                     If hitLine(testx, testy, b(j).r, bl(i).x1, bl(i).y1, bl(i).x2, bl(i).y2) Then
  69.                         bx1 = b(j).x + b(j).speed * Cos(bl(i).a)
  70.                         bx2 = b(j).x + b(j).speed * Cos(_Pi(1) - bl(i).a)
  71.                         by1 = yy(bx1, bl(i).x1, bl(i).y1, bl(i).x2, bl(i).y2) - b(j).r - 1
  72.                         by2 = yy(bx2, bl(i).x1, bl(i).y1, bl(i).x2, bl(i).y2) - b(j).r - 1
  73.                         If by1 = (-9999 - b(j).r - 1) Or by2 = (-9999 - b(j).r - 1) Then
  74.                             cFlag = 0: Exit For
  75.                         End If
  76.                         If by1 >= by2 Then b(j).y = by1: b(j).x = bx1 Else b(j).y = by2: b(j).x = bx2
  77.                         cFlag = 1
  78.                     End If
  79.                 End If
  80.             Next
  81.             If cFlag = 0 Then b(j).x = testx: b(j).y = testy
  82.         Next
  83.         _Display
  84.     Wend
  85.  
  86. Sub lien (x1, y1, x2, y2)
  87.     Line (x1, y1)-(x2, y2)
  88.  
  89. Function hitLine (x, y, r, xx1, yy1, xx2, yy2)
  90.     x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2
  91.     If x1 > x2 Then Swap x1, x2: Swap y1, y2
  92.     If x < x1 Or x > x2 Then hitLine = 0: Exit Function
  93.     If ((y2 - y1) / (x2 - x1)) * (x - x1) + y1 - r < y And y < ((y2 - y1) / (x2 - x1)) * (x - x1) + y1 + r Then
  94.         hitLine = 1
  95.     Else
  96.         hitLine = 0
  97.     End If
  98.  
  99. Function yy (x, xx1, yy1, xx2, yy2) 'this puts drop on line
  100.     'copy parameters that are changed
  101.     x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2
  102.     If x1 > x2 Then Swap x1, x2: Swap y1, y2
  103.     If x1 <= x And x <= x2 Then
  104.         yy = ((y2 - y1) / (x2 - x1)) * (x - x1) + y1
  105.     Else
  106.         yy = -9999
  107.     End If
  108.  
  109. Function rand% (lo%, hi%)
  110.     rand% = (Rnd * (hi% - lo% + 1)) \ 1 + lo%
  111.  
  112. Function rdir% ()
  113.     If Rnd < .5 Then rdir% = -1 Else rdir% = 1
  114.  
  115. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  116. Sub fcirc (CX As Long, CY As Long, R As Long)
  117.     Dim subRadius As Long, RadiusError As Long
  118.     Dim X As Long, Y As Long
  119.  
  120.     subRadius = Abs(R)
  121.     RadiusError = -subRadius
  122.     X = subRadius
  123.     Y = 0
  124.  
  125.     If subRadius = 0 Then PSet (CX, CY): Exit Sub
  126.  
  127.     ' Draw the middle span here so we don't draw it twice in the main loop,
  128.     ' which would be a problem with blending turned on.
  129.     Line (CX - X, CY)-(CX + X, CY), , BF
  130.  
  131.     While X > Y
  132.         RadiusError = RadiusError + Y * 2 + 1
  133.         If RadiusError >= 0 Then
  134.             If X <> Y + 1 Then
  135.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  136.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  137.             End If
  138.             X = X - 1
  139.             RadiusError = RadiusError - X * 2
  140.         End If
  141.         Y = Y + 1
  142.         Line (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  143.         Line (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  144.     Wend
  145.  
  146.  

Maybe make a rain gage? Very handy fcirc = Circle Fill in that code, QB64 doesn't have that.

Offline Phlashlite

  • Newbie
  • Posts: 50
Re: Rain Storm Screensaver coding.
« Reply #7 on: January 22, 2022, 04:30:46 pm »
@bplus

I do like that!

I once saw one similar that had the platforms tilting in oscillation.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Rain Storm Screensaver coding.
« Reply #8 on: January 22, 2022, 09:18:36 pm »
Yeah that was Rain Drain 2, tilted but not oscillating, that would be Rain Drain 3  :)

Offline Phlashlite

  • Newbie
  • Posts: 50
Re: Rain Storm Screensaver coding.
« Reply #9 on: January 22, 2022, 09:25:40 pm »
Yep,  I knew I had seen it!

Code: QB64: [Select]
  1. 'Rain Drain.bas started 2017-09-13
  2. 'translated from
  3. 'Rain Drain.bas  SmallBASIC 0.12.9 [B+=MGA] 2017-04-26
  4. '2020-08-29 Rain Drain 2: What if we move one side of every line up and down?
  5.  
  6. CONST xmax = 1024 'SCREEN WIDTH
  7. CONST ymax = 768 'SCREEN HEIGHT
  8.  
  9. SCREEN _NEWIMAGE(xmax, ymax, 32)
  10. _DELAY 1 '.25
  11. _TITLE "Rain Drain 2:   spacebar for new arrangement,    esc to quit"
  12.  
  13. TYPE ball
  14.     x AS SINGLE 'X COORDINATE
  15.     y AS SINGLE 'Y COORDINATE
  16.     speed AS SINGLE 'SPEED
  17.     r AS SINGLE 'RADIUS
  18.     c AS LONG 'COLOR
  19.  
  20. TYPE bLine
  21.     x1 AS SINGLE
  22.     y1 AS SINGLE
  23.     x2 AS SINGLE
  24.     y2 AS SINGLE
  25.     a AS DOUBLE
  26.  
  27.  
  28.     'init ball array
  29.     balls = 1000
  30.     REDIM b(balls) AS ball
  31.     FOR i = 1 TO balls
  32.         b(i).x = RND * xmax 'RANDOM STARTING LOCATION
  33.         b(i).y = RND * ymax '^
  34.         b(i).speed = 5 '9.85 'SPEED
  35.         b(i).r = 5 'RADIUS
  36.         b(i).c = _RGB(0, rand%(200, 255), rand%(200, 255)) 'COLOR
  37.     NEXT
  38.  
  39.     'intit bLine array
  40.     m = 10
  41.     nbl = 7 'NUMBER OF BLINES
  42.     REDIM bl(nbl) AS bLine
  43.     FOR i = 1 TO nbl
  44.         d = rand%(50, 200)
  45.         bl(i).x1 = rand%(m, xmax - d - m)
  46.         bl(i).y1 = i * ymax / nbl - 10
  47.         bl(i).a = RND * _PI(1 / 4) - _PI(1 / 8)
  48.         bl(i).x2 = bl(i).x1 + d * COS(bl(i).a)
  49.         bl(i).y2 = bl(i).y1 + d * SIN(bl(i).a)
  50.     NEXT
  51.  
  52.     dir = .5
  53.     lp = 0
  54.     WHILE 1
  55.         CLS
  56.         IF 32 = _KEYHIT THEN
  57.             EXIT WHILE
  58.         ELSEIF 27 = _KEYHIT THEN
  59.             END
  60.         END IF
  61.         lp = lp + dir
  62.         IF lp > 50 THEN dir = -dir
  63.         IF lp < -50 THEN dir = -dir
  64.  
  65.         FOR j = 1 TO balls
  66.  
  67.             IF b(j).y - b(j).r > ymax OR b(j).x + b(j).r < 0 OR b(j).x - b(j).r > xmax THEN
  68.                 b(j).x = rand%(0, xmax): b(j).y = 0
  69.             END IF
  70.  
  71.             fcirc b(j).x, b(j).y, b(j).r, b(j).c
  72.             testx = b(j).x + b(j).speed * COS(_PI(.5))
  73.             testy = b(j).y + b(j).speed * SIN(_PI(.5))
  74.             cFlag = 0
  75.  
  76.             FOR i = 1 TO nbl
  77.                 COLOR _RGB(255, 0, 0)
  78.                 IF j = 1 THEN bl(i).y1 = bl(i).y1 + dir
  79.                 LINE (bl(i).x1, bl(i).y1)-(bl(i).x2, bl(i).y2)
  80.                 IF cFlag = 0 THEN
  81.                     IF hitLine(testx, testy, b(j).r, bl(i).x1, bl(i).y1, bl(i).x2, bl(i).y2) THEN
  82.                         bx1 = b(j).x + b(j).speed * COS(bl(i).a)
  83.                         bx2 = b(j).x + b(j).speed * COS(_PI(1) - bl(i).a)
  84.                         by1 = yy(bx1, bl(i).x1, bl(i).y1, bl(i).x2, bl(i).y2) - b(j).r - 1
  85.                         by2 = yy(bx2, bl(i).x1, bl(i).y1, bl(i).x2, bl(i).y2) - b(j).r - 1
  86.                         IF by1 = (-9999 - b(j).r - 1) OR by2 = (-9999 - b(j).r - 1) THEN
  87.                             cFlag = 0: EXIT FOR
  88.                         END IF
  89.                         IF by1 >= by2 THEN b(j).y = by1: b(j).x = bx1 ELSE b(j).y = by2: b(j).x = bx2
  90.                         cFlag = 1
  91.                     END IF
  92.                 END IF
  93.             NEXT
  94.             IF cFlag = 0 THEN b(j).x = testx: b(j).y = testy
  95.         NEXT
  96.         '_Limit 20
  97.         _DISPLAY
  98.     WEND
  99.  
  100. FUNCTION hitLine (x, y, r, xx1, yy1, xx2, yy2)
  101.     x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2
  102.     IF x1 > x2 THEN SWAP x1, x2: SWAP y1, y2
  103.     IF x < x1 OR x > x2 THEN hitLine = 0: EXIT FUNCTION
  104.     IF ((y2 - y1) / (x2 - x1)) * (x - x1) + y1 - r < y AND y < ((y2 - y1) / (x2 - x1)) * (x - x1) + y1 + r THEN
  105.         hitLine = 1
  106.     ELSE
  107.         hitLine = 0
  108.     END IF
  109.  
  110. FUNCTION yy (x, xx1, yy1, xx2, yy2) 'this puts drop on line
  111.     'copy parameters that are changed
  112.     x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2
  113.     IF x1 > x2 THEN SWAP x1, x2: SWAP y1, y2
  114.     IF x1 <= x AND x <= x2 THEN
  115.         yy = ((y2 - y1) / (x2 - x1)) * (x - x1) + y1
  116.     ELSE
  117.         yy = -9999
  118.     END IF
  119.  
  120. FUNCTION rand% (lo%, hi%)
  121.     rand% = (RND * (hi% - lo% + 1)) \ 1 + lo%
  122.  
  123. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  124.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  125.     DIM X AS INTEGER, Y AS INTEGER
  126.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  127.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  128.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  129.     WHILE X > Y
  130.         RadiusError = RadiusError + Y * 2 + 1
  131.         IF RadiusError >= 0 THEN
  132.             IF X <> Y + 1 THEN
  133.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  134.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  135.             END IF
  136.             X = X - 1
  137.             RadiusError = RadiusError - X * 2
  138.         END IF
  139.         Y = Y + 1
  140.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  141.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  142.     WEND
  143.  
  144.  

Offline Phlashlite

  • Newbie
  • Posts: 50
Re: Rain Storm Screensaver coding.
« Reply #10 on: January 23, 2022, 11:20:19 pm »
*** WARNING! *** If you suffer from epilepsy, you may not want to run this.  It is quite flashy!

Same code as the screensaver code uploaded earlier except with improved lightning effects, modified colors and reduced to demo sized application.

~Phlashlite


Code: QB64: [Select]
  1.  
  2. 'A work in progress...
  3.  
  4. ' - Added better lightnig affects.
  5. '   - Added screen flash
  6. ' - Worked on colors.
  7. ' - Add a ground plane
  8. '   - Maybe Add splash effects?
  9. ' - Add cloud layer
  10. ' - Always working on code efficiency.
  11.  
  12. 'Author: Phlashlite, Jan 2022
  13.  
  14. ' NOTES: If you see code enclosed in "++++" there are adjustable setting to play with in there.
  15.  
  16. '        The original code was translated from watching this Coding Challenge Video:
  17. '        [youtube]https://www.youtube.com/watch?v=KkyIDI6rQJI[/youtube]
  18.  
  19.  
  20. 'Most of the adjustable settings+++++++++++++++++++++++++++++++++++++++++++++++
  21.  
  22. 'Screen________________________________________________________________________
  23.  
  24. 'Your screen width
  25. CONST SCR_WDTH = 1536
  26.  
  27. 'Your screen height
  28. CONST SCR_HGHT = SCR_WDTH * .5625
  29.  
  30. 'Virtual depth of the scene
  31. CONST SCR_DPTH = 15
  32.  
  33.  
  34. 'Rain__________________________________________________________________________
  35.  
  36. 'Number of raindrops to draw
  37. CONST NUM_DROPS = 5000
  38.  
  39. 'Lower limit of raindrop (drp) speed
  40. CONST MIN_DRP_SPEED = 13
  41.  
  42. 'Upper limit of drp speed
  43. CONST MAX_DRP_SPEED = 60
  44.  
  45. 'Lower limit of drp length
  46. CONST MIN_DRP_LNGTH = 3
  47.  
  48. 'Upper limit of drp length
  49. CONST MAX_DRP_LNGTH = 60
  50.  
  51. 'Lower limit of drp width
  52. CONST MIN_DRP_WDTH = 1
  53.  
  54. 'Upper limit of drp width
  55. CONST MAX_DRP_WDTH = 5
  56.  
  57.  
  58. 'Lightning_____________________________________________________________________
  59.  
  60. 'Bolt detail, smaller is more detailed, 1 is default
  61. CONST BLT_DETAIL = 1
  62.  
  63. 'How crazy the bolt path is (angle displacement) 650 is default
  64. CONST BLT_DISP = 650
  65.  
  66. 'Bolt width
  67. CONST BLT_HLF_WDTH = 1.5
  68.  
  69. 'Ticks Bolt is on screen
  70. CONST BLT_TIME = 15
  71.  
  72. 'Frequency of Bolts.  Range is 1 to 1000. > = less frequency.
  73. CONST BLT_FREQ = 990
  74.  
  75. 'Lightning Bolt glow___________________________________________________________
  76.  
  77. 'One side gradient width
  78. CONST BLT_GRD_HLF_WDTH = 17
  79.  
  80. 'Intensity of the gradient
  81. CONST BLT_GRD_INTENSTY = 168
  82.  
  83. 'Map gradient to 255 color scale
  84. CONST BLT_GRD_CALC = BLT_GRD_INTENSTY / BLT_GRD_HLF_WDTH
  85.  
  86.  
  87. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  88.  
  89. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  90. _MOUSEHIDE 'hide the mouse if you want (use if you are going to use as a screensaver
  91. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  92.  
  93. SCREEN _NEWIMAGE(SCR_WDTH, SCR_HGHT, 32) ' set the drawing screen
  94.  
  95. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  96. _SCREENMOVE _MIDDLE '(-SCR_WDTH / 3) - 3, -26 'Moves the screen to hide widows title bars and frames
  97. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  98.  
  99. 'This is a drp
  100. TYPE Drop
  101.     x AS SINGLE '   x coordinate
  102.     y AS SINGLE '   y coordinate
  103.     z AS SINGLE '   z virtual coordinate
  104.     wth AS SINGLE ' drp width
  105.     lng AS SINGLE ' drp length
  106.     spd AS SINGLE ' drp speed
  107.  
  108.  
  109. 'GroundY = SCR_HGHT * 0.75
  110.  
  111. 'Initialize and fill the rain array____________________________________________
  112. DIM SHARED Rain(NUM_DROPS) AS Drop
  113.  
  114. FOR i! = 0 TO NUM_DROPS
  115.     fillDropArray (i!)
  116.  
  117.  
  118. 'Initialize and fill the glow array____________________________________________
  119. DIM SHARED gradtable(BLT_GRD_HLF_WDTH) AS INTEGER
  120.  
  121. FOR g! = BLT_GRD_HLF_WDTH TO 1 STEP -1
  122.     gradtable(g!) = BLT_GRD_INTENSTY - BLT_GRD_CALC * g!
  123.  
  124. 'Main loop to draw each Drop and call the lightning bolts______________________
  125.     FOR i! = 0 TO NUM_DROPS
  126.  
  127.         'Fall
  128.         Rain(i!).y = Rain(i!).y + Rain(i!).spd
  129.  
  130.         'Draw
  131.         LINE (Rain(i!).x, Rain(i!).y)-(Rain(i!).x + Rain(i!).wth, Rain(i!).y + Rain(i!).lng), _RGBA(205, 205, 205, 21), BF
  132.  
  133.         'Fill
  134.         'Restart each Drop in the array if it's y value passes the bottom of the screen (SCR_HGHT)
  135.         IF Rain(i!).y > SCR_HGHT THEN
  136.             fillDropArray (i!)
  137.         END IF
  138.  
  139.     NEXT
  140.  
  141.     'Call the lightning bolt (blt)_____________________________________________
  142.  
  143.     'How far the bolt wanders++++++++++++++++++++++++++++++++++++++++++++++++++
  144.     x1! = Rndm!(-10, SCR_WDTH + 10) 'Sets blts x axis starting point range
  145.  
  146.     x2! = Rndm!(x1! - SCR_WDTH / 2, x1! + SCR_WDTH / 2) 'Sets how much a blt's end x axis point
  147.     '                                  varies from its starting x axis point
  148.  
  149.     y1! = 0 ' Rndm!(0, SCR_HGHT - 1000) 'Sets blts y axis starting point range
  150.  
  151.     y2! = Rndm!(1100, SCR_HGHT) 'Sets blts y axis ending point range
  152.  
  153.     'Adjust how often bolts strike_____________________________________________
  154.     k! = Rndm(1, 1000)
  155.     IF k! > BLT_FREQ THEN
  156.         CLS , _RGBA(61, 72, 155, 100)
  157.         drawLightning x1!, y1!, x2!, y2!, BLT_DISP
  158.  
  159.         '_DISPLAY
  160.         'DO
  161.         'LOOP UNTIL INKEY$ <> ""
  162.  
  163.     END IF
  164.     '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  165.     _LIMIT 30
  166.     '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  167.    0
  168.     _DISPLAY
  169.  
  170.     CLS , _RGB(0, 0, 13)
  171.  
  172.  
  173. '______________________________________________________________________________
  174.  
  175. 'Does all the drop calculations and fills the array.
  176.  
  177. SUB fillDropArray (i!)
  178.  
  179.     Rain(i!).x = Rndm(0, SCR_WDTH)
  180.     Rain(i!).y = Rndm(-SCR_HGHT, 0) 'start drops off screen on the y axis
  181.  
  182.     'bias rnd# gen for  more drops farther away (shorter, slower, narrower)___
  183.     j! = Rndm(1, SCR_DPTH * 2.5)
  184.     IF j! > SCR_DPTH THEN j! = Rndm(1, SCR_DPTH * .25)
  185.  
  186.     Rain(i!).z = j! 'Rndm(1, SCR_DPTH)
  187.     Rain(i!).wth = map(Rain(i!).z, 0, SCR_DPTH, MIN_DRP_WDTH, MAX_DRP_WDTH)
  188.     Rain(i!).lng = map(Rain(i!).z, 0, SCR_DPTH, MIN_DRP_LNGTH, MAX_DRP_LNGTH)
  189.     Rain(i!).spd = map(Rain(i!).z, 0, SCR_DPTH, MIN_DRP_SPEED, MAX_DRP_SPEED)
  190.  
  191.  
  192. '______________________________________________________________________________
  193.  
  194. 'Does all the lightning calculations usimg a "midpoint displacement alrorithm".
  195.  
  196. SUB drawLightning (x1!, y1!, x2!, y2!, BLT_DISP)
  197.  
  198.     x3! = x1! - BLT_HLF_WDTH 'start x1 adjusted for width
  199.     x4! = x1! + BLTWHLFDTH 'end x1 adjusted for width
  200.     x5! = x2! - BLT_HLF_WDTH 'start x2 adjusted for width
  201.     x6! = x2! - BLT_HLF_WDTH 'end x2 adjusted for width
  202.  
  203.     DIM midX!, midY!
  204.  
  205.     IF BLT_DISP < BLT_DETAIL THEN
  206.  
  207.         FOR l! = 1 TO BLT_TIME
  208.  
  209.             FOR bw! = 1 TO BLT_HLF_WDTH
  210.                 LINE (x1!, y1!)-(x2!, y2!), _RGBA(255, 255, 255, 200)
  211.                 LINE (x1! + bw!, y1!)-(x2! + bw!, y2!), _RGBA(255, 255, 255, 200)
  212.                 LINE (x1! - bw!, y1!)-(x2! - bw!, y2!), _RGBA(255, 255, 255, 200)
  213.             NEXT
  214.  
  215.             FOR bgw! = 1 TO BLT_GRD_HLF_WDTH
  216.                 LINE (x3! + bgw!, y1!)-(x4! + bgw!, y2!), _RGBA(gradtable(bgw!), gradtable(bgw!), gradtable(bgw!), gradtable(bgw!))
  217.                 LINE (x3! - bgw!, y1!)-(x4! - bgw!, y2!), _RGBA(gradtable(bgw!), gradtable(bgw!), gradtable(bgw!), gradtable(bgw!))
  218.             NEXT
  219.  
  220.         NEXT
  221.  
  222.     ELSE
  223.         midX = (x1! + x2!) / 2
  224.         midY = (y1! + y2!) / 2
  225.         midX! = midX! + (RND - .5) * BLT_DISP
  226.         midY! = midY! + (RND - .5) * BLT_DISP
  227.  
  228.         drawLightning x1!, y1!, midX!, midY!, BLT_DISP / 2
  229.         drawLightning x2!, y2!, midX!, midY!, BLT_DISP / 2
  230.  
  231.     END IF
  232.  
  233.  
  234. '______________________________________________________________________________
  235.  
  236. 'Standard random numbers in a range of mn! (min) to mx! (max)
  237.  
  238. FUNCTION Rndm! (mn!, mx!)
  239.     IF mn! > mx! THEN
  240.         SWAP mn!, mx!
  241.     END IF
  242.     Rndm! = RND * (mx! - mn!) + mn!
  243.  
  244. '______________________________________________________________________________
  245.  
  246. ' Map function I found or translated from somewhere.
  247. ' The Coding Train" guy on youtube, where I translated the rain code from explained it in one of his videos.
  248.  
  249. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  250.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  251.  
  252.  

Offline Phlashlite

  • Newbie
  • Posts: 50
Re: Rain Storm Screensaver coding.
« Reply #11 on: January 23, 2022, 11:40:57 pm »
Very handy fcirc = Circle Fill in that code, QB64 doesn't have that.

Funny you bring that up... I made these awhile back when I was thinking about making an "A-LIFE" sim.

Code: QB64: [Select]
  1. SUB CircleFillDia2 (CX AS INTEGER, CY AS INTEGER, C AS _UNSIGNED LONG)
  2.  
  3.     ' CX = offset x coordinate
  4.     ' CY = offset y coordinate
  5.     '  C = fill color
  6.     '
  7.     ' Output: A fast filled circle of diameter 2
  8.     ' *** Only included for OCD completeness :) ***
  9.     '
  10.     '          ±Û
  11.     '          ÛÛ
  12.  
  13.  
  14.     PSET (CX, CY), C
  15.  
  16.  
  17. 'ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
  18.  
  19. SUB CircleFillDia3 (CX AS INTEGER, CY AS INTEGER, C AS _UNSIGNED LONG)
  20.  
  21.     ' CX = center x coordinate
  22.     ' CY = center y coordinate
  23.     '  C = fill color
  24.     '
  25.     ' Output: A fast filled circle of diameter 3
  26.     '
  27.     '          ÛÛÛ
  28.     '          Û±Û
  29.     '          ÛÛÛ
  30.  
  31.  
  32.     LINE (CX - 1, CY - 1)-(CX + 1, CY + 1), C, BF
  33.  
  34.  
  35. 'ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
  36.  
  37. SUB CircleFillDia4 (CX AS INTEGER, CY AS INTEGER, C AS _UNSIGNED LONG)
  38.  
  39.     ' CX = offset x coordinate
  40.     ' CY = offset y coordinate
  41.     '  C = fill color
  42.     '
  43.     ' Output: A fast filled circle of diameter 4
  44.     '
  45.     '           ÛÛ
  46.     '          Û±ÛÛ
  47.     '          ÛÛÛÛ
  48.     '           ÛÛ
  49.  
  50.  
  51.     LINE (CX, CY - 1)-(CX + 1, CY - 1), C
  52.     LINE (CX - 1, CY)-(CX + 2, CY + 1), C, BF
  53.     LINE (CX, CY + 2)-(CX + 1, CY + 2), C
  54.  
  55.  
  56. 'ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
  57.  
  58. SUB CircleFillDia5 (CX AS INTEGER, CY AS INTEGER, C AS _UNSIGNED LONG)
  59.  
  60.     ' CX = center x coordinate
  61.     ' CY = center y coordinate
  62.     '  C = fill color
  63.     '
  64.     ' Output: A fast filled circle of diameter 5
  65.     '
  66.     '          ÛÛÛ
  67.     '         ÛÛÛÛÛ
  68.     '         ÛÛ±ÛÛ
  69.     '         ÛÛÛÛÛ
  70.     '          ÛÛÛ
  71.  
  72.  
  73.     LINE (CX - 1, CY - 2)-(CX + 1, CY - 2), C
  74.     LINE (CX - 2, CY - 1)-(CX + 2, CY + 1), C, BF
  75.     LINE (CX - 1, CY + 2)-(CX + 1, CY + 2), C
  76.  
  77.  
  78. 'ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
  79.  
  80. SUB CircleFillDia6 (CX AS INTEGER, CY AS INTEGER, C AS _UNSIGNED LONG)
  81.  
  82.     ' CX = offset x coordinate
  83.     ' CY = offset y coordinate
  84.     '  C = fill color
  85.     '
  86.     ' Output: A fast filled circle of diameter 6
  87.     '
  88.     '          ÛÛÛÛ
  89.     '         ÛÛÛÛÛÛ
  90.     '         ÛÛ±ÛÛÛ
  91.     '         ÛÛÛÛÛÛ
  92.     '         ÛÛÛÛÛÛ
  93.     '          ÛÛÛÛ
  94.  
  95.  
  96.     LINE (CX - 1, CY - 2)-(CX + 2, CY - 2), C
  97.     LINE (CX - 2, CY - 1)-(CX + 3, CY + 2), C, BF
  98.     LINE (CX - 1, CY + 3)-(CX + 2, CY + 3), C
  99.  
  100.  
  101. 'ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
  102.  
  103. SUB CircleFillDia7 (CX AS INTEGER, CY AS INTEGER, C AS _UNSIGNED LONG)
  104.  
  105.     ' CX = center x coordinate
  106.     ' CY = center y coordinate
  107.     '  C = fill color
  108.     '
  109.     ' Output: A fast filled circle of diameter 7
  110.     '
  111.     '           ÛÛÛ
  112.     '          ÛÛÛÛÛ
  113.     '         ÛÛÛÛÛÛÛ
  114.     '         ÛÛÛ±ÛÛÛ
  115.     '         ÛÛÛÛÛÛÛ
  116.     '          ÛÛÛÛÛ
  117.     '           ÛÛÛ
  118.  
  119.  
  120.     LINE (CX - 1, CY - 3)-(CX + 1, CY - 3), C
  121.     LINE (CX - 2, CY - 2)-(CX + 2, CY - 2), C
  122.     LINE (CX - 3, CY - 1)-(CX + 3, CY + 1), C, BF
  123.     LINE (CX - 2, CY + 2)-(CX + 2, CY + 2), C
  124.     LINE (CX - 1, CY + 3)-(CX + 1, CY + 3), C
  125.  
  126.  
  127. 'ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
  128.  
  129. SUB CircleFillDia8 (CX AS INTEGER, CY AS INTEGER, C AS _UNSIGNED LONG)
  130.  
  131.     ' CX = center x coordinate
  132.     ' CY = center y coordinate
  133.     '  C = fill color
  134.     '
  135.     ' Output: A fast filled circle of diameter 8
  136.     '
  137.     '         ÛÛÛÛ
  138.     '        ÛÛÛÛÛÛ
  139.     '       ÛÛÛÛÛÛÛÛ
  140.     '       ÛÛÛ±ÛÛÛÛ
  141.     '       ÛÛÛÛÛÛÛÛ
  142.     '       ÛÛÛÛÛÛÛÛ
  143.     '        ÛÛÛÛÛÛ
  144.     '         ÛÛÛÛ
  145.     '
  146.  
  147.     LINE (CX - 2, CY - 4)-(CX + 2, CY - 4), C
  148.     LINE (CX - 3, CY - 3)-(CX + 3, CY - 3), C
  149.     LINE (CX - 4, CY - 2)-(CX + 4, CY + 2), C, BF
  150.     LINE (CX - 3, CY + 3)-(CX + 3, CY + 3), C
  151.     LINE (CX - 2, CY + 4)-(CX + 2, CY + 4), C
  152.  
  153.  
  154. 'ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
  155.  
  156. SUB CircleFillDia9 (CX AS INTEGER, CY AS INTEGER, C AS _UNSIGNED LONG)
  157.  
  158.     ' CX = center x coordinate
  159.     ' CY = center y coordinate
  160.     '  C = fill color
  161.     '
  162.     ' Output: A fast filled circle of diameter 9
  163.     '
  164.     '         ÛÛÛÛÛ
  165.     '        ÛÛÛÛÛÛÛ
  166.     '       ÛÛÛÛÛÛÛÛÛ
  167.     '       ÛÛÛÛÛÛÛÛÛ
  168.     '       ÛÛÛÛ±ÛÛÛÛ
  169.     '       ÛÛÛÛÛÛÛÛÛ
  170.     '       ÛÛÛÛÛÛÛÛÛ
  171.     '        ÛÛÛÛÛÛÛ
  172.     '         ÛÛÛÛÛ
  173.  
  174.  
  175.     LINE (CX - 2, CY - 4)-(CX + 2, CY - 4), C
  176.     LINE (CX - 3, CY - 3)-(CX + 3, CY - 3), C
  177.     LINE (CX - 4, CY - 2)-(CX + 4, CY + 2), C, BF
  178.     LINE (CX - 3, CY + 3)-(CX + 3, CY + 3), C
  179.     LINE (CX - 2, CY + 4)-(CX + 2, CY + 4), C
  180.  
  181.  
  182. 'ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
  183.  
  184. SUB CircleFillDia10 (CX AS INTEGER, CY AS INTEGER, C AS _UNSIGNED LONG)
  185.  
  186.     ' CX = center x coordinate
  187.     ' CY = center y coordinate
  188.     '  C = fill color
  189.     '
  190.     ' Output: A fast filled circle of diameter 10
  191.     '
  192.     '          ÛÛÛÛ
  193.     '        ÛÛÛÛÛÛÛÛ
  194.     '        ÛÛÛÛÛÛÛÛ
  195.     '       ÛÛÛÛÛÛÛÛÛÛ
  196.     '       ÛÛÛÛ±ÛÛÛÛÛ
  197.     '       ÛÛÛÛÛÛÛÛÛÛ
  198.     '       ÛÛÛÛÛÛÛÛÛÛ
  199.     '        ÛÛÛÛÛÛÛÛ
  200.     '        ÛÛÛÛÛÛÛÛ
  201.     '          ÛÛÛÛ
  202.  
  203.     LINE (CX - 1, CY - 4)-(CX + 2, CY - 4), C
  204.     LINE (CX - 3, CY - 3)-(CX + 4, CY - 2), C, BF
  205.     LINE (CX - 4, CY - 1)-(CX + 5, CY + 2), C, BF
  206.     LINE (CX - 3, CY + 3)-(CX + 4, CY + 4), C, BF
  207.     LINE (CX - 1, CY + 5)-(CX + 2, CY + 5), C
  208.  
  209.  
  210. 'ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
  211.  
  212. SUB CircleFillDia11 (CX AS INTEGER, CY AS INTEGER, C AS _UNSIGNED LONG)
  213.  
  214.     ' CX = center x coordinate
  215.     ' CY = center y coordinate
  216.     '  C = fill color
  217.     '
  218.     ' Output: A fast filled circle of diameter 11
  219.     '
  220.     '         ÛÛÛÛÛ
  221.     '        ÛÛÛÛÛÛÛ
  222.     '       ÛÛÛÛÛÛÛÛÛ
  223.     '      ÛÛÛÛÛÛÛÛÛÛÛ
  224.     '      ÛÛÛÛÛÛÛÛÛÛÛ
  225.     '      ÛÛÛÛÛ±ÛÛÛÛÛ
  226.     '      ÛÛÛÛÛÛÛÛÛÛÛ
  227.     '      ÛÛÛÛÛÛÛÛÛÛÛ
  228.     '       ÛÛÛÛÛÛÛÛÛ
  229.     '        ÛÛÛÛÛÛÛ
  230.     '         ÛÛÛÛÛ
  231.  
  232.  
  233.     LINE (CX - 2, CY - 5)-(CX + 2, CY - 5), C
  234.     LINE (CX - 3, CY - 4)-(CX + 3, CY - 4), C
  235.     LINE (CX - 4, CY - 3)-(CX + 4, CY - 3), C
  236.     LINE (CX - 5, CY - 2)-(CX + 5, CY + 2), C, BF
  237.     LINE (CX - 4, CY + 3)-(CX + 4, CY + 3), C
  238.     LINE (CX - 3, CY + 4)-(CX + 3, CY + 4), C
  239.     LINE (CX - 2, CY + 5)-(CX + 2, CY + 5), C
  240.  
  241.  
  242. 'ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
  243.  
  244. SUB CircleFillDia12 (CX AS INTEGER, CY AS INTEGER, C AS _UNSIGNED LONG)
  245.  
  246.     ' CX = center x coordinate
  247.     ' CY = center y coordinate
  248.     '  C = fill color
  249.     '
  250.     ' Output: A fast filled circle of diameter 12
  251.     '
  252.     '          ÛÛÛÛ
  253.     '        ÛÛÛÛÛÛÛÛ
  254.     '       ÛÛÛÛÛÛÛÛÛÛ
  255.     '       ÛÛÛÛÛÛÛÛÛÛ
  256.     '      ÛÛÛÛÛÛÛÛÛÛÛÛ
  257.     '      ÛÛÛÛÛ±ÛÛÛÛÛÛ
  258.     '      ÛÛÛÛÛÛÛÛÛÛÛÛ
  259.     '      ÛÛÛÛÛÛÛÛÛÛÛÛ
  260.     '       ÛÛÛÛÛÛÛÛÛÛ
  261.     '       ÛÛÛÛÛÛÛÛÛÛ
  262.     '        ÛÛÛÛÛÛÛÛ
  263.     '          ÛÛÛÛ
  264.  
  265.     LINE (CX - 1, CY - 5)-(CX + 2, CY - 5), C
  266.     LINE (CX - 3, CY - 4)-(CX + 4, CY - 4), C
  267.     LINE (CX - 4, CY - 3)-(CX + 5, CY - 2), C, BF
  268.     LINE (CX - 5, CY - 1)-(CX + 6, CY + 2), C, BF
  269.     LINE (CX - 4, CY + 3)-(CX + 5, CY + 4), C, BF
  270.     LINE (CX - 3, CY + 5)-(CX + 4, CY + 5), C
  271.     LINE (CX - 1, CY + 6)-(CX + 2, CY + 6), C
  272.  
  273.  
  274.  
  275.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Rain Storm Screensaver coding.
« Reply #12 on: January 24, 2022, 10:11:24 am »
Yeah I remember trying circle fills with a square fill in middle and doing 1 hump calc and repeating the lines across the other 3 tips of axis cross.