' Solar System 2D: code developed following this tutorial
'[youtube]https://www.youtube.com/watch?v=l8SiJ-RmeHU&list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH[/youtube]&index=7
CONST WScreen
= 900, HScreen
= 600, True
= -1, False
= 0 CONST r
= 50, MaxPlanet
= 5, MaxMoon
= 5
Setup
Draws
MovePlanets
FOR w
= 1 TO MaxPlanet
+ MaxMoon
IF Planets
(w
).Radius
> 0 THEN Planets
(w
).Angle
= Planets
(w
).Angle
+ Planets
(w
).Speed
Sun.Radius = 0
Sun.Angle = 0
Sun.Distance = 0
Sun.Names = "SUN"
Sun.Parent = 0
Sun.Colors
= _RGBA32(222, 194, 61, 255) distance
= INT(RND * 3 * r
) + (3 * r
) ' Index, radius, distance from parent, parent
MakePlanet w, radius, distance, 0
RandomMoon w
ShowName = False
' index moon, 1/2 radius, Parent
MakePlanet z
+ MaxPlanet
, INT(Planets
(Index
).Radius
/ 2), INT(RND * 20) + 10, Index
CircleFill WScreen / 2, HScreen / 2, 100, Sun.Colors
DrawSun
FOR w
= 1 TO MaxPlanet
+ MaxMoon
IF Planets
(w
).Radius
> 0 THEN ShowPlanet w
Planets(Index).Radius = r
Planets
(Index
).Angle
= INT(RND * 360) Planets(Index).Distance = d
Planets
(Index
).Names
= STR$(Index
) Planets(Index).Parent = p
Planets
(Index
).Speed
= 0.01 + (RND * 0.03) IF p
= 0 THEN Planets
(Index
).Colors
= _RGBA(0, 100 + (RND * 150), 100 + (RND * 150), 255) ELSE Planets
(Index
).Colors
= _RGBA(100 + (RND * 150), 100 + (RND * 150), 100 + (RND * 150), 255)
Sinus
= SIN(Planets
(Index
).Angle
) Cosinus
= COS(Planets
(Index
).Angle
) ' parent is an important Flag both to choose X,y of circle
' both to understand if it is a planet around the sun or a moon around a planet
IF Planets
(Index
).Parent
= 0 THEN Xcircle = (WScreen / 2) + Sun.Radius
Ycircle = (HScreen / 2) + Sun.Radius
Sinus2
= SIN(Planets
(Planets
(Index
).Parent
).Angle
) Cosinus2
= COS(Planets
(Planets
(Index
).Parent
).Angle
) Xcircle = ((Planets(Planets(Index).Parent).Distance * Cosinus2) + (WScreen / 2) + Sun.Radius)
Ycircle = ((Planets(Planets(Index).Parent).Distance * Sinus2) + (HScreen / 2) + Sun.Radius)
Rcircle = Planets(Index).Radius
Xcircle = Xcircle + (Planets(Index).Distance * Cosinus)
Ycircle = Ycircle + (Planets(Index).Distance * Sinus)
CircleFill Xcircle, Ycircle, Rcircle, Planets(Index).Colors
' CX = center x coordinate
' CY = center y coordinate
' R = radius
' C = fill color
RadiusError = -Radius
X = Radius
Y = 0
LINE (CX
- X
, CY
)-(CX
+ X
, CY
), C
, BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), C
, BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), C
, BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
LINE (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), C
, BF
LINE (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), C
, BF