Author Topic: First attempt for a solar system 2D  (Read 5836 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: First attempt for a solar system 2D
« Reply #15 on: June 04, 2019, 06:34:14 am »
@Richard Frost

You have fascinated me!

I like demo!
I like precision of data!
I like old Basic coding style!

but the other face of the medal is that I loose my mind in these variables with one or two letters as name!
Yes only this let me have an urticaria  attach! I'm going to have a cortisone pill or to be stinged by a bee!
But this is a my problem.

Thanks to share Frost
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: First attempt for a solar system 2D
« Reply #16 on: June 04, 2019, 06:45:34 am »
@Bplus

Cool!
Chakras Bplus Solas System.jpg

Hey but have you tried to draw Indian Chakras? https://en.wikipedia.org/wiki/Chakra

Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: First attempt for a solar system 2D
« Reply #17 on: June 24, 2019, 04:10:35 pm »
Hi another little step towards solar system maker

 
A Solar System2D own planet its features.jpg

each planet has its speed, dimension, color and can have its moons that have their speed, dimension and color.

but the screen is too little to see all the system! :-)

I must rethink how to output the data on the screen using a different basis!

Here code:
Code: QB64: [Select]
  1. ' Solar System 2D: code developed following this tutorial
  2. '[youtube]https://www.youtube.com/watch?v=l8SiJ-RmeHU&list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH[/youtube]&index=7
  3. TYPE Planet
  4.     Radius AS SINGLE
  5.     Angle AS SINGLE
  6.     Distance AS SINGLE
  7.     Names AS STRING * 3
  8.     Parent AS INTEGER
  9.     Speed AS SINGLE
  10.     Colors AS _UNSIGNED LONG
  11.  
  12. CONST WScreen = 900, HScreen = 600, True = -1, False = 0
  13. CONST r = 35, MaxPlanet = 8, MaxMoon = 10
  14.  
  15. CONST Black = _RGBA32(0, 0, 0, 255)
  16. CONST NameColor = _RGBA32(255, 255, 255, 255)
  17.  
  18. DIM SHARED A AS LONG, Sun AS Planet, Planets(1 TO MaxPlanet * MaxMoon) AS Planet
  19. DIM SHARED ShowName AS INTEGER, PDistance AS INTEGER
  20.  
  21. Setup
  22.     k = _KEYHIT
  23.     IF k = 8 THEN Setup
  24.     Draws
  25.     MovePlanets
  26.     IF k = 13 THEN ShowName = NOT ShowName
  27.     _DISPLAY
  28.     _LIMIT 15
  29. LOOP UNTIL k = 32
  30.  
  31. SUB MovePlanets
  32.     DIM w AS INTEGER
  33.     FOR w = 1 TO MaxPlanet + MaxMoon
  34.         IF Planets(w).Radius > 0 THEN Planets(w).Angle = Planets(w).Angle + Planets(w).Speed
  35.     NEXT w
  36.  
  37. SUB Setup
  38.     DIM w AS INTEGER, radius AS INTEGER, distance AS INTEGER
  39.     A = _NEWIMAGE(WScreen, HScreen, 32)
  40.     IF A < -1 THEN SCREEN A ELSE PRINT "Error handle image": EXIT SUB
  41.     _TITLE "Solar System 2D"
  42.     _SCREENMOVE 10, 10
  43.     Sun.Radius = 50
  44.     Sun.Angle = 0
  45.     Sun.Distance = 0
  46.     Sun.Names = "SUN"
  47.     Sun.Parent = 0
  48.     Sun.Colors = _RGBA32(222, 194, 61, 255)
  49.     PDistance = 0
  50.     FOR w = 1 TO MaxPlanet STEP 1
  51.         radius = INT(RND * 15) + 10
  52.         distance = INT(RND * 2 * r) + (2 * r)
  53.  
  54.         PDistance = PDistance + distance
  55.         '          Index, radius, distance from parent, parent
  56.         MakePlanet w, radius, PDistance, 0
  57.         RandomMoon w
  58.     NEXT w
  59.     ShowName = False
  60.  
  61. SUB RandomMoon (Index AS INTEGER)
  62.     DIM z AS INTEGER, newR AS INTEGER
  63.     IF INT(RND * 3) + 1 > 1 THEN
  64.         FOR z = 1 TO INT(RND * (MaxMoon - 1)) + 1
  65.             ' index moon, 1/2 radius, Parent
  66.             newR = INT(RND * INT(Planets(Index).Radius / 3)) + 1
  67.             MakePlanet z + MaxPlanet, newR, INT(Planets(Index).Radius) + (2 * newR), Index
  68.         NEXT
  69.     END IF
  70.  
  71. SUB DrawSun
  72.     CircleFill WScreen / 2, HScreen / 2, Sun.Radius, Sun.Colors
  73.     IF ShowName = True THEN COLOR NameColor: _PRINTSTRING (WScreen / 2, HScreen / 2), Sun.Names
  74.  
  75. SUB Draws
  76.     DIM w AS INTEGER
  77.     CLS , Black
  78.     DrawSun
  79.     FOR w = 1 TO MaxPlanet + MaxMoon
  80.         IF Planets(w).Radius > 0 THEN ShowPlanet w
  81.     NEXT w
  82.  
  83. SUB MakePlanet (Index AS INTEGER, r AS SINGLE, d AS SINGLE, p AS INTEGER)
  84.     Planets(Index).Radius = r
  85.     Planets(Index).Angle = INT(RND * 360)
  86.     Planets(Index).Distance = d
  87.     Planets(Index).Names = STR$(Index)
  88.     Planets(Index).Parent = p
  89.     Planets(Index).Speed = 0.01 + (RND * 0.05)
  90.     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)
  91.  
  92. SUB ShowPlanet (Index AS INTEGER)
  93.     DIM Sinus AS SINGLE, Cosinus AS SINGLE
  94.     DIM Xcircle AS SINGLE, Ycircle AS SINGLE, Rcircle AS INTEGER
  95.     DIM Cosinus2 AS SINGLE, Sinus2 AS SINGLE
  96.     Sinus = SIN(Planets(Index).Angle)
  97.     Cosinus = COS(Planets(Index).Angle)
  98.     ' parent is an important Flag both to choose X,y of circle
  99.     ' both to understand if it is a planet around the sun or a moon around a planet
  100.  
  101.     IF Planets(Index).Parent = 0 AND Planets(Index).Names <> "SUN" THEN
  102.         Xcircle = (WScreen / 2)
  103.         Ycircle = (HScreen / 2)
  104.     ELSEIF Planets(Index).Parent > 0 THEN
  105.         Sinus2 = SIN(Planets(Planets(Index).Parent).Angle)
  106.         Cosinus2 = COS(Planets(Planets(Index).Parent).Angle)
  107.         Xcircle = ((Planets(Planets(Index).Parent).Distance * Cosinus2) + (WScreen / 2))
  108.         Ycircle = ((Planets(Planets(Index).Parent).Distance * Sinus2) + (HScreen / 2))
  109.     END IF
  110.     Rcircle = Planets(Index).Radius
  111.     Xcircle = Xcircle + (Planets(Index).Distance * Cosinus)
  112.     Ycircle = Ycircle + (Planets(Index).Distance * Sinus)
  113.     CircleFill Xcircle, Ycircle, Rcircle, Planets(Index).Colors
  114.     IF ShowName = True THEN COLOR NameColor: _PRINTSTRING (Xcircle, Ycircle), Planets(Index).Names
  115.  
  116.  
  117. SUB CircleFill (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  118.     ' CX = center x coordinate
  119.     ' CY = center y coordinate
  120.     '  R = radius
  121.     '  C = fill color
  122.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  123.     DIM X AS INTEGER, Y AS INTEGER
  124.     Radius = ABS(R)
  125.     RadiusError = -Radius
  126.     X = Radius
  127.     Y = 0
  128.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  129.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  130.     WHILE X > Y
  131.         RadiusError = RadiusError + Y * 2 + 1
  132.         IF RadiusError >= 0 THEN
  133.             IF X <> Y + 1 THEN
  134.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  135.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  136.             END IF
  137.             X = X - 1
  138.             RadiusError = RadiusError - X * 2
  139.         END IF
  140.         Y = Y + 1
  141.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  142.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  143.     WEND

Thanks to see
Your MOD are welcome! I like to learn! But I go on my way because also direct experience does knowledge.
Programming isn't difficult, only it's  consuming time and coffee

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: First attempt for a solar system 2D
« Reply #18 on: June 25, 2019, 09:06:56 am »
I have been into Astronomy since I was about 15. Not so much now as my eyesight isn't what it used to be.... lol

My suggestion when trying to scale size AND distance in a computer simulation.... Don't. There is nothing wrong with a system that is scaled to your desktop resolution and you are using a standard size discs for each object. Just to give you an idea... If you placed a model of the Sun (1 metre diameter) in London, using the same scale, Pluto would be here in Melbourne Australia. Scale the Sun down to 1 cm and you would be lucky to fit Mercury on the same screen... Just to see the relative movement of the planets, small discs, work just fine.  This is my opinion. Different colours are a great idea...

I had an old Amstrad CPC464 back in 1985. Max screen resolution of 640x400. I had to display the system in two screens. The inner planets out to Mars and the outer planets. Watching it draw the orbits then the planet was tiresome. Poor machine only had a CPU speed of 4mhz. But the wait was worth it...

I think you have done a great job. Makes me wish I had my scope, and eyesight, back again.... Thank you.
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: First attempt for a solar system 2D
« Reply #19 on: June 25, 2019, 10:55:37 am »
I watched the videos. That guy is one strange presenter. He knows his stuff but I think he has a few kangaroos loose in his top paddock.

His 2D videos made a little sense - there were times he lost me - but it seemed to make sense. I know absolutely nothing about the language he was using but it was fun watching him trying to explain 2D orbits etc... But when he moved to 3D.... I really tried to follow along but that stuff was WAY over my head... It was interesting, but almost all of the 3D stuff, was so hard to follow I just couldn't cope... The results were amazing but how he got there just baked the old noodle... lol

I would still like to make a relatively accurate (movement anyway) model of the Solar System at least once before I "shuffle off"... I am still looking for a tutorial etc in 'basic'... I'm going to study your example and see if there is any way to incorporate some 'real' data... I'm not sure if my skill level is up to it, but it might be fun to try... lol
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: First attempt for a solar system 2D
« Reply #20 on: June 25, 2019, 05:47:18 pm »
I finally got to bed at about 2am.... I managed to get all nine planets on the screen - almost - and no, I will not get into the discussion of Pluto's downgrading to a dwarf planet... lol

I modified my resolution to 1920x1080 (sorry Laptops...). Used the maximum Y axis for Pluto's orbit which is about 40 Astronomical Units from the Sun. Converted all the other planetary orbits accordingly. At this point, including the Sun, everything is a small disc. I am currently working on the velocity of each planet. In this model ALL orbits are assumed circular. Calculating the circumference of each orbit, factoring the length of time it takes for each planet to complete a single orbit, the relative velocity of each planet can be roughly calculated. All I have to do now is to translate those velocities to a figure that your model can use.... My brain hurts... I need coffee....
Logic is the beginning of wisdom.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: First attempt for a solar system 2D
« Reply #21 on: June 27, 2019, 07:43:01 am »
This is good stuff that I'm going to have to study. I want to incorporate something like this into my vector plotter. That way my ships would have to be careful not to smack a celestial body while doing their maneuvers.

https://www.qb64.org/forum/index.php?topic=1429.0