Author Topic: Solar System (Kinda)  (Read 3697 times)

0 Members and 1 Guest are viewing this topic.

Offline Prithak

  • Newbie
  • Posts: 56
  • Life itself is a Programming Language!
    • View Profile
    • My Programming Language
Solar System (Kinda)
« on: March 31, 2019, 11:16:22 pm »
Yay! I made a solar system!
Not the best way to do it but still, it's really cool.

Try clicking somewhere and see what happens :P

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. x = _WIDTH / 2
  3. y = _HEIGHT / 2
  4. y1 = y - 100
  5. mx = x
  6. my = y
  7. DIM SHARED r, g, b
  8.     FOR i = 0 TO 360
  9.         WHILE _MOUSEINPUT: WEND
  10.         mb = _MOUSEBUTTON(1)
  11.         IF mb THEN
  12.             mx = _MOUSEX: my = _MOUSEY
  13.         END IF
  14.         r = 135: g = 135: b = 79
  15.         rotate x, y, i, 50
  16.         r = 135: g = 79: b = 79
  17.         rotate x, y, i, 100
  18.         r = 100: g = 150: b = 255
  19.         rotate x, y, i, 150
  20.         r = 109: g = 43: b = 43
  21.         CIRCLE (x, y), 20, _RGB32(255, 150, 100)
  22.         IF mx < x THEN
  23.             x = x - 1
  24.         ELSEIF mx > x THEN
  25.             x = x + 1
  26.         END IF
  27.         IF my < y THEN
  28.             y = y - 1
  29.         ELSEIF my > y THEN
  30.             y = y + 1
  31.         END IF
  32.  
  33.         _DISPLAY
  34.         CLS
  35.     NEXT i
  36.  
  37. SUB rotate (X, y, i, l)
  38.     x2 = X + COS(_D2R(i)) * l
  39.     y2 = y + SIN(_D2R(i)) * l / 2
  40.     CIRCLE (x2, y2), 10, _RGB32(r, g, b)
CLS
IF computer$ = "ON" THEN
me$ = "Happy!"
ELSE
me$ = "Time To Draw!"
END IF
END

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Solar System (Kinda)
« Reply #1 on: March 31, 2019, 11:21:36 pm »
Nice! You turned the mouse into God's U-Haul.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Solar System (Kinda)
« Reply #2 on: April 01, 2019, 10:01:54 am »
Hi Prithak,

Nice playing God! I mod your Solar System with stuff learned with david_uwi :
https://www.qb64.org/forum/index.php?topic=1184.0

Code: QB64: [Select]
  1. _TITLE "Prithak's Solor Mouse mod B+"
  2. SCREEN _NEWIMAGE(700, 700, 32)
  3. _SCREENMOVE 300, 20
  4.  
  5. TYPE planetType 'all info needed to draw a planet
  6.     pName AS STRING
  7.     distanceFromSun AS SINGLE
  8.     radius AS SINGLE
  9.     oneDayAngleChange AS SINGLE
  10.     kolor AS _UNSIGNED LONG
  11.  
  12. 'setup solar center
  13. DIM SHARED sunX, sunY
  14. sunX = _WIDTH / 2
  15. sunY = _HEIGHT / 2
  16.  
  17. 'setup planets  array
  18. DIM SHARED planets(4) AS planetType
  19.  
  20. 'load the planets array data
  21. '' newPlanet (index, planetName$, distFromSun,  radius, Kolr AS _UNSIGNED LONG)
  22. newPlanet 0, "Sun", 0, 43, 1, _RGB32(255, 255, 160)
  23. newPlanet 1, "Mercury", 57.9, 2, 87.97, _RGB32(255, 120, 150)
  24. newPlanet 2, "Venus", 108.2, 4, 224.7, _RGB32(0, 200, 255)
  25. newPlanet 3, "Earth", 149.6, 4, 365.26, _RGB32(0, 50, 180)
  26. newPlanet 4, "Mars", 227.9, 2, 686.98, _RGB32(200, 0, 0)
  27. 'DATA "Mercury",57.9,87.97 radius   1.5+   thousands of miles
  28. 'DATA "Venus",108.2,224.7           3.7
  29. 'DATA "Earth",149.6,365.26          3.9
  30. 'DATA "Mars",227.9,686.98           2.1
  31. '                                    432 sun  so take 10 x's less
  32.  
  33. 'see SUB planetXY for locating the planet and SUB drawPlanet
  34.  
  35.  
  36. 'y1 = y - 100 'not used
  37. mx = sunX
  38. my = sunY
  39. 'DIM SHARED r, g, b
  40. 'CLS
  41. DIM SHARED days
  42.     days = days + 1
  43.     'FOR degreeAngle = 0 TO 360
  44.     mb = _MOUSEBUTTON(1)
  45.     IF mb THEN
  46.         mx = _MOUSEX: my = _MOUSEY
  47.     END IF
  48.     'r = 135: g = 135: b = 79
  49.     'rotate x, y, i, 50
  50.     'r = 135: g = 79: b = 79
  51.     'rotate x, y, i, 100
  52.     'r = 100: g = 150: b = 255
  53.     'rotate x, y, i, 150
  54.     'r = 109: g = 43: b = 43
  55.     'CIRCLE (x, y), 20, _RGB32(255, 150, 100)
  56.     FOR i = 0 TO 4
  57.         drawPlanet i
  58.     NEXT
  59.     IF mx < sunX THEN
  60.         sunX = sunX - 1
  61.     ELSEIF mx > sunX THEN
  62.         sunX = sunX + 1
  63.     END IF
  64.     IF my < sunY THEN
  65.         sunY = sunY - 1
  66.     ELSEIF my > sunY THEN
  67.         sunY = sunY + 1
  68.     END IF
  69.  
  70.     _DISPLAY
  71.     _LIMIT 20
  72.     CLS
  73.     'NEXT
  74.  
  75. 'SUB rotate (X, y, i, l)
  76. '    x2 = X + COS(_D2R(i)) * l
  77. '    y2 = y + SIN(_D2R(i)) * l / 2
  78. '    CIRCLE (x2, y2), 10, _RGB32(r, g, b)
  79. 'END SUB
  80.  
  81. SUB drawPlanet (planetIndex)
  82.     planetXY planetIndex, setX, setY
  83.     CIRCLE (setX, setY), planets(planetIndex).radius, planets(planetIndex).kolor
  84.     PAINT (setX, setY), planets(planetIndex).kolor, planets(planetIndex).kolor
  85.  
  86. 'load a planet's data in a single call
  87. SUB newPlanet (index, planetName$, distFromSun, radius, oneYearInEarthDays, Kolr AS _UNSIGNED LONG) 'all info needed to draw a planet
  88.     planets(index).pName = planetName$
  89.     planets(index).distanceFromSun = distFromSun
  90.     planets(index).radius = radius
  91.     planets(index).oneDayAngleChange = _PI(2) / oneYearInEarthDays
  92.     planets(index).kolor = Kolr
  93.  
  94. ' locate the planets current position in relation to sun center
  95. SUB planetXY (planetIndex, pX, pY)
  96.     pX = sunX + planets(planetIndex).distanceFromSun * COS(days * planets(planetIndex).oneDayAngleChange)
  97.     pY = sunY + planets(planetIndex).distanceFromSun * SIN(days * planets(planetIndex).oneDayAngleChange)
  98.  
  99.  

EDIT: did not need the inner FOR loop for degreeAngle but then had to reset _LIMIT 20 for main loop.
« Last Edit: April 01, 2019, 02:42:52 pm by bplus »