Posts: 562
Threads: 97
Joined: Apr 2022
Reputation:
45
02-08-2025, 06:24 AM
(This post was last modified: 02-08-2025, 07:09 PM by SierraKen.)
Here's my screen saver.  It's not snowflakes, but it's as close as I can get to them.
Plus this is mostly code from my Asteroids game (the math from ChatGPT), but I added the lines between the crystals and also made the sides the same angles myself. I'm learning!
Code removed because of one useless loop. Scroll down to the next post to get the new one, thanks.
Posts: 562
Threads: 97
Joined: Apr 2022
Reputation:
45
02-08-2025, 07:09 PM
(This post was last modified: 02-08-2025, 07:26 PM by SierraKen.)
Sorry, had to remove it again. The big fix is the next post.
Posts: 562
Threads: 97
Joined: Apr 2022
Reputation:
45
02-08-2025, 07:26 PM
(This post was last modified: 02-08-2025, 07:35 PM by SierraKen.)
Here is a big fix on it. Some of the inner lines didn't connect to all the points when the points were an uneven number, so to fix it all it needed was a INT on line 66.
I also removed a couple of not-used DIM statements.
Code: (Select All)
'Ken's Crystals Screen Saver
'Feb. 8, 2025
_Title "Crystals Screen Saver - Space Bar To Restart - Esc To Quit"
Screen _NewImage(800, 600, 32)
start:
Clear
go:
Cls
Print: Print: Print
Input "Number of crystals (1-100): ", num
If num < 1 Or num > 100 Or num <> Int(num) Then GoTo go:
Input "Number of points (1-30): ", points
If points < 1 Or points > 30 Or points <> Int(points) Then GoTo go:
Input "Radius (1-100): ", radius
If radius < 1 Or radius > 100 Or radius <> Int(radius) Then GoTo go:
Dim cx2(num), cy2(num), dx(num), dy(num)
Dim x2(num, points), y2(num, points)
Dim angle2(num), xrot(num, points), yrot(num, points)
Cls
' Initialize crystals
For a = 0 To num - 1
cx2(a) = Int(Rnd * 680) + 55 ' Random start X
cy2(a) = Int(Rnd * 480) + 55 ' Random start Y
angle2(a) = Rnd * 360 ' Random starting rotation
dx(a) = (Rnd - 0.5) * 2 ' Random speed X (-1 to 1)
dy(a) = (Rnd - 0.5) * 2 ' Random speed Y (-1 to 1)
' Generate random crystal shape
For i = 0 To points
ang = i * (360 / points)
rOffset = radius + Int(.5 * 15 - 7) ' Vary radius randomly
x2(a, i) = Cos(ang * _Pi / 180) * rOffset
y2(a, i) = Sin(ang * _Pi / 180) * rOffset
Next
Next
Do
_Limit 20
a$ = InKey$
If a$ = " " Then GoTo start:
If a$ = Chr$(27) Then End
' Update and draw each crystal
For a = 0 To num - 1
angle2(a) = angle2(a) + 1 ' Rotate
If angle2(a) >= 360 Then angle2(a) = 0
' Rotate crystal points
rad = angle2(a) * _Pi / 180
For i = 0 To points
xrot(a, i) = cx2(a) + (x2(a, i) * Cos(rad) - y2(a, i) * Sin(rad))
yrot(a, i) = cy2(a) + (x2(a, i) * Sin(rad) + y2(a, i) * Cos(rad))
Next
' Draw crystal
For i = 0 To points
j = (i + 1) Mod points
jj = (i + Int(points / 2)) Mod points
Line (xrot(a, i), yrot(a, i))-(xrot(a, j), yrot(a, j)), _RGB32(255, 255, 255)
Line (xrot(a, i), yrot(a, i))-(xrot(a, jj), yrot(a, jj)), _RGB32(255, 255, 255)
Next
' Move crystal
cx2(a) = cx2(a) + dx(a)
cy2(a) = cy2(a) + dy(a)
' Wrap around screen edges
If cx2(a) < 0 Then cx2(a) = 800
If cx2(a) > 800 Then cx2(a) = 0
If cy2(a) < 0 Then cy2(a) = 600
If cy2(a) > 600 Then cy2(a) = 0
Next
_Display
Cls
Loop
Posts: 4,132
Threads: 185
Joined: Apr 2022
Reputation:
242
A couple of mods
Code: (Select All) 'Ken's Crystals Screen Saver
'Feb. 8, 2025
_Title "Crystals Screen Saver - Space Bar To Restart - Esc To Quit"
Screen _NewImage(800, 600, 32)
start:
Clear
go:
'Cls
'Print: Print: Print
'Input "Number of crystals (1-100): ", num
'If num < 1 Or num > 100 Or num <> Int(num) Then GoTo go:
'Input "Number of points (1-30): ", points
'If points < 1 Or points > 30 Or points <> Int(points) Then GoTo go:
'Input "Radius (1-100): ", radius
'If radius < 1 Or radius > 100 Or radius <> Int(radius) Then GoTo go:
num = 1000
points = 6
radius = 5
Dim cx2(num), cy2(num), dx(num), dy(num)
Dim x2(num, points), y2(num, points)
Dim angle2(num), xrot(num, points), yrot(num, points)
Cls
' Initialize crystals
For a = 0 To num - 1
more:
cx2(a) = Int(Rnd * 800) ' Random start X
cy2(a) = Int(Rnd * 600) ' Random start Y
'If cx2(a) > 250 And cx2(a) < 550 And cy2(a) > 150 And cy2(a) < 450 Then GoTo more:
angle2(a) = Rnd * 360 ' Random starting rotation
dx(a) = (Rnd - 0.5) * 3 ' Random speed X (-1 to 1)
dy(a) = (Rnd - 0.05) * 3 ' Random speed Y (-1 to 1)
' Generate random crystal shape
For i = 0 To points
ang = i * (360 / points)
rOffset = radius + Int(.5 * 15 - 7) ' Vary radius randomly
x2(a, i) = Cos(ang * _Pi / 180) * rOffset
y2(a, i) = Sin(ang * _Pi / 180) * rOffset
Next
Next
Do
_Limit 20
a$ = InKey$
If a$ = " " Then GoTo start:
If a$ = Chr$(27) Then End
' Update and draw each crystal
For a = 0 To num - 1
angle2(a) = angle2(a) + 1 ' Rotate
If angle2(a) >= 360 Then angle2(a) = 0
' Rotate crystal points
rad = angle2(a) * _Pi / 180
For i = 0 To points
xrot(a, i) = cx2(a) + (x2(a, i) * Cos(rad) - y2(a, i) * Sin(rad))
yrot(a, i) = cy2(a) + (x2(a, i) * Sin(rad) + y2(a, i) * Cos(rad))
Next
' Draw crystal
For i = 0 To points
j = (i + 1) Mod points
jj = (i + Int(points / 2)) Mod points
'Line (xrot(a, i), yrot(a, i))-(xrot(a, j), yrot(a, j)), _RGB32(255, 255, 255)
Line (xrot(a, i), yrot(a, i))-(xrot(a, jj), yrot(a, jj)), _RGB32(255, 255, 255)
Next
' Move crystal
cx2(a) = cx2(a) + dx(a)
cy2(a) = cy2(a) + dy(a)
' Wrap around screen edges
If cx2(a) < 0 Then cx2(a) = 800
If cx2(a) > 800 Then cx2(a) = 0
If cy2(a) < 0 Then cy2(a) = 600
If cy2(a) > 600 Then cy2(a) = 0
Next
_Display
Cls
Loop
b = b + ...
Posts: 562
Threads: 97
Joined: Apr 2022
Reputation:
45
02-08-2025, 08:09 PM
(This post was last modified: 02-08-2025, 08:44 PM by SierraKen.)
LOL that's neat, thanks B+.
Posts: 562
Threads: 97
Joined: Apr 2022
Reputation:
45
I know what I'll do, I'll change the GOTOs to change the variables to the highest or lowest instead.
Posts: 562
Threads: 97
Joined: Apr 2022
Reputation:
45
02-08-2025, 08:36 PM
(This post was last modified: 02-08-2025, 08:44 PM by SierraKen.)
OK, I removed all the GOTO statements, I even put the whole thing in another DO/LOOP so when you press the Space Bar, it just does Exit Do and goes back to the beginning.
Code: (Select All)
'Ken's Crystals Screen Saver
'Feb. 8, 2025
_Title "Crystals Screen Saver - Space Bar To Restart - Esc To Quit"
Screen _NewImage(800, 600, 32)
Do
Clear
go:
Cls
Print: Print: Print
Input "Number of crystals (1-100): ", num
If num < 1 Then num = 1: Print "Amount changed to 1."
If num > 100 Then num = 100: Print "Amount changed to 100."
If num <> Int(num) Then num = Int(num): Print "Amount changed to " + Str$(num) + "."
Input "Number of points (2-30): ", points
If points < 2 Then points = 2: Print "Points changed to 2."
If points > 30 Then points = 30: Print "Points changed to 30."
If points <> Int(points) Then points = Int(points): Print "Amount changed to " + Str$(points) + "."
Input "Radius (2-100): ", radius
If radius < 2 Then
radius = 2
Print "Radius changed to 2."
Print
Input "Press Enter to start.", a$
End If
If radius > 100 Then
radius = 100
Print "Radius changed to 100."
Print
Input "Press Enter to start.", a$
End If
If radius <> Int(radius) Then
radius = Int(radius)
Print "Radius changed to " + Str$(radius) + "."
Print
Input "Press Enter to start.", a$
End If
Dim cx2(num), cy2(num), dx(num), dy(num)
Dim x2(num, points), y2(num, points)
Dim angle2(num), xrot(num, points), yrot(num, points)
Cls
' Initialize crystals
For a = 0 To num - 1
cx2(a) = Int(Rnd * 680) + 55 ' Random start X
cy2(a) = Int(Rnd * 480) + 55 ' Random start Y
angle2(a) = Rnd * 360 ' Random starting rotation
dx(a) = (Rnd - 0.5) * 2 ' Random speed X (-1 to 1)
dy(a) = (Rnd - 0.5) * 2 ' Random speed Y (-1 to 1)
' Generate random crystal shape
For i = 0 To points
ang = i * (360 / points)
rOffset = radius + Int(.5 * 15 - 7) ' Vary radius randomly
x2(a, i) = Cos(ang * _Pi / 180) * rOffset
y2(a, i) = Sin(ang * _Pi / 180) * rOffset
Next
Next
Do
_Limit 20
a$ = InKey$
If a$ = " " Then Exit Do
If a$ = Chr$(27) Then End
' Update and draw each crystal
For a = 0 To num - 1
angle2(a) = angle2(a) + 1 ' Rotate
If angle2(a) >= 360 Then angle2(a) = 0
' Rotate crystal points
rad = angle2(a) * _Pi / 180
For i = 0 To points
xrot(a, i) = cx2(a) + (x2(a, i) * Cos(rad) - y2(a, i) * Sin(rad))
yrot(a, i) = cy2(a) + (x2(a, i) * Sin(rad) + y2(a, i) * Cos(rad))
Next
' Draw crystal
For i = 0 To points
j = (i + 1) Mod points
jj = (i + Int(points / 2)) Mod points
Line (xrot(a, i), yrot(a, i))-(xrot(a, j), yrot(a, j)), _RGB32(255, 255, 255)
Line (xrot(a, i), yrot(a, i))-(xrot(a, jj), yrot(a, jj)), _RGB32(255, 255, 255)
Next
' Move crystal
cx2(a) = cx2(a) + dx(a)
cy2(a) = cy2(a) + dy(a)
' Wrap around screen edges
If cx2(a) < 0 Then cx2(a) = 800
If cx2(a) > 800 Then cx2(a) = 0
If cy2(a) < 0 Then cy2(a) = 600
If cy2(a) > 600 Then cy2(a) = 0
Next
_Display
Cls
Loop
Loop
|