Author Topic: Plotting / erasing points on a circle  (Read 3937 times)

0 Members and 1 Guest are viewing this topic.

Offline Statsman1

  • Newbie
  • Posts: 36
  • I'm just a jerk, but a hero is what I want to be.
    • View Profile
Plotting / erasing points on a circle
« on: September 28, 2021, 09:38:12 pm »
Hey everyone!

I hope you are all doing well. 

Here's the scenario...

Starting at the top of a circle and going counter-clockwise, I would like to...

Plot a filled dot at the top of the circle (using a radius of 1, then on an X-Y plane, center of circle at (0,0) that dot would be centered at (0,1)).

Determine at random how far along the circle the new dot will go, counter-clockwise.

Erase the previously drawn dot.

Plot the new dot.

Continue until the dot has passed through (-1,-1) and reached (0,-1).

Sort of like drawing a ball on a roulette wheel, but only one-half of a complete rotation, starting at the 12-o'clock position and going backwards to the 6-o'clock position.

I realize that the CIRCLE and PSET commands are in order here, and while I can determine the start and stop coordinates, I am having a heck of a time wrapping my head around the rest of it.  SIN and COS are long-forgotten trig functions, and I suspect I am using them to solve this...

Anybody have an idea here?

Thank you in advance!

Edited -

Using this...

Screen 12

Const Pi = 3.1415926

Circle (325, 225), 180, 6
Line (325, 225)-(x, y), 0

For j = 1 To 360
    Input "Enter value for point:"; s
    x = Int(Sin(s / 180 * Pi) * 180) + 325
    y = Int(Cos(s / 180 * Pi) * 180) + 225
    Line (325, 225)-(x, y), 15
Next j

- I bulldozed my way to learn that if s = 90, that code will draw a line from (0,0) to (1,0)

So, when s = 180, the result is a line from (0,0) to (0,1).  Yay.
And, when s = 0 or 360, the result is a line from (0,0) to (0,-1). Yay.

Accordingly, tomorrow, I have something to work on.  Any suggestions are welcome, but I think I figured out one route.

All the best, everyone!
« Last Edit: September 28, 2021, 10:13:37 pm by Statsman1 »
Good decisions come from experience.
Experience comes from bad decisions.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #1 on: September 28, 2021, 10:25:49 pm »
Here's an idea. Post the code you have so far. Honestly, this sounds like some kind of a homework assignment, rather than a personal project, but I may be wrong. In any event, for homework, we encourage posting code and giving help at the point where a coder is stuck. If we post complete solutions, nothing is really leaned. You could also check out what others have done for similar circle related projects. The latest circle related thread is here: https://www.qb64.org/forum/index.php?topic=4189.0

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

Offline Statsman1

  • Newbie
  • Posts: 36
  • I'm just a jerk, but a hero is what I want to be.
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #2 on: September 28, 2021, 10:32:22 pm »
Actually, I am 51 years old, and gave up homework a LONG time ago.

I am working on a particular game idea that is just to make myself happy, that’s all, not an assignment or anything. Just a racing program, and trying to get the cars around the curves is proving a challenge.

Hope this clarifies the requirements.
Good decisions come from experience.
Experience comes from bad decisions.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #3 on: September 28, 2021, 10:49:42 pm »
Ah, another youngster on the forum! Well, alrighty then....

So this depends a lot on if you will be requiring collision detection, in other words a player is driving the car, or if it is more of a simulation, where the car is just following the track.

Anyway, thank you for posting the code, and have a look t this: https://www.qb64.org/forum/index.php?topic=2710.msg119274#msg119274

It may give you some more ideas of how to work with circular movement.

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

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #4 on: September 28, 2021, 11:00:35 pm »
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: Plotting / erasing points on a circle
« Reply #5 on: September 28, 2021, 11:05:42 pm »
Welcome @Statsman1

I modified your code a bits to help clarify circles and angles:
Code: QB64: [Select]
  1.  
  2. Const Pi = 3.1415926
  3. Const Radius = 180
  4. Const Xcenter = 325
  5. Const Ycenter = 225
  6.     Cls
  7.     Circle (Xcenter, 225), Radius, 6
  8.     Print "For Degrees: 0 = east, 90 = south, 180 = west, 270 = north"
  9.     Input "Enter Degree Angle for point  > ", s
  10.     RadianAngle = _D2R(s) ' _D2R converts Degrees 2 (to) Radians which is what Sin and Cos process
  11.     x = Radius * Cos(RadianAngle) + Xcenter
  12.     y = Radius * Sin(RadianAngle) + Ycenter
  13.     Line (Xcenter, Ycenter)-(x, y), 15
  14.     Locate 28, 40: Print "ZZZ...";
  15.     Sleep
  16. Loop Until _KeyDown(27) ' user presses escape
  17.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #6 on: September 28, 2021, 11:18:09 pm »
And here is a yellow square traveling that circle:
Code: QB64: [Select]
  1.  
  2. Const Pi = 3.1415926
  3. Const Radius = 180
  4. Const Xcenter = 325
  5. Const Ycenter = 225
  6. While _KeyDown(27) = 0
  7.     Cls
  8.     s = s + 1 ' increase 1 degree
  9.     Circle (Xcenter, Ycenter), Radius, 6
  10.     'Print "For Degrees: 0 = east, 90 = south, 180 = west, 270 = north"
  11.     'Input "Enter Degree Angle for point  > ", s
  12.     RadianAngle = _D2R(s) ' _D2R converts Degrees 2 (to) Radians which is what Sin and Cos process
  13.     x = Radius * Cos(RadianAngle) + Xcenter
  14.     y = Radius * Sin(RadianAngle) + Ycenter
  15.     Line (x - 5, y - 5)-Step(10, 10), 14, BF ' yellow square 10x10 at point x, y
  16.     _Display ' stop flicker
  17.     _Limit 60 ' loops per sec
  18.     'Locate 28, 40: Print "ZZZ...";
  19.     'Sleep
  20.  

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #7 on: September 28, 2021, 11:46:06 pm »
Nice, Mark, but applying some of my mad SCREEN 0 skills, and once again, I wind up running circles around you...

Code: QB64: [Select]
  1.  
  2. CONST Pi = 3.1415926
  3. CONST Radius = 180
  4. CONST Xcenter = 325
  5. CONST Ycenter = 225
  6. WHILE _KEYDOWN(27) = 0
  7.     CLS
  8.     s = s + 1 ' increase 1 degree
  9.     CIRCLE (Xcenter, Ycenter), Radius, 6
  10.     LOCATE 14, 40: PRINT "YOU"
  11.     'Print "For Degrees: 0 = east, 90 = south, 180 = west, 270 = north"
  12.     'Input "Enter Degree Angle for point  > ", s
  13.     RadianAngle = _D2R(s) ' _D2R converts Degrees 2 (to) Radians which is what Sin and Cos process
  14.     x = Radius * COS(RadianAngle) + Xcenter
  15.     y = Radius * SIN(RadianAngle) + Ycenter
  16.     LINE (x - 5, y - 5)-STEP(10, 10), 14, BF ' yellow square 10x10 at point x, y
  17.     _DISPLAY ' stop flicker
  18.     _LIMIT 60 ' loops per sec
  19.     'Locate 28, 40: Print "ZZZ...";
  20.     'Sleep
  21.  
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: Plotting / erasing points on a circle
« Reply #8 on: September 29, 2021, 12:22:51 am »
I started a blue and white car:
Code: QB64: [Select]
  1.  
  2. Const Pi = 3.1415926
  3. Const Radius = 180
  4. Const Xcenter = 325
  5. Const Ycenter = 225
  6. While _KeyDown(27) = 0
  7.     Cls
  8.     s = s + 1 ' increase 1 degree
  9.     Circle (Xcenter, Ycenter), Radius, 6
  10.     'Print "For Degrees: 0 = east, 90 = south, 180 = west, 270 = north"
  11.     'Input "Enter Degree Angle for point  > ", s
  12.     RadianAngle = _D2R(s) ' _D2R converts Degrees 2 (to) Radians which is what Sin and Cos process
  13.     x = Radius * Cos(RadianAngle) + Xcenter
  14.     y = Radius * Sin(RadianAngle) + Ycenter
  15.     'Line (x - 5, y - 5)-Step(10, 10), 14, BF ' yellow square 10x10 at point x, y
  16.     drawRect x, y, 20, 40, RadianAngle + _Pi / 2, 9
  17.     drawRect x, y, 15, 15, RadianAngle + _Pi / 2, 15
  18.     _Display ' stop flicker
  19.     _Limit 60 ' loops per sec
  20.     'Locate 28, 40: Print "ZZZ...";
  21.     'Sleep
  22.  
  23. Sub drawRect (x, y, w, h, raHeading, c As _Unsigned Long)
  24.     ' from x,y draw midY h/2 towards raHeading
  25.     x1 = x + h / 2 * Cos(raHeading)
  26.     y1 = y + h / 2 * Sin(raHeading)
  27.     x2 = x1 + w / 2 * Cos(raHeading + _Pi / 2)
  28.     y2 = y1 + w / 2 * Sin(raHeading + _Pi / 2)
  29.     x3 = x1 + w / 2 * Cos(raHeading - _Pi / 2)
  30.     y3 = y1 + w / 2 * Sin(raHeading - _Pi / 2)
  31.  
  32.     x4 = x + h / 2 * Cos(raHeading - _Pi)
  33.     y4 = y + h / 2 * Sin(raHeading - _Pi)
  34.     x5 = x4 + w / 2 * Cos(raHeading + _Pi / 2)
  35.     y5 = y4 + w / 2 * Sin(raHeading + _Pi / 2)
  36.     x6 = x4 + w / 2 * Cos(raHeading - _Pi / 2)
  37.     y6 = y4 + w / 2 * Sin(raHeading - _Pi / 2)
  38.  
  39.     Line (x2, y2)-(x3, y3), c
  40.     Line (x3, y3)-(x6, y6), c
  41.     Line (x6, y6)-(x5, y5), c
  42.     Line (x5, y5)-(x2, y2), c
  43.     Paint (x, y), c, c
  44.  
  45.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #9 on: September 29, 2021, 12:28:32 am »
Pete's the red (of course) and yellow car ;-))

Code: QB64: [Select]
  1.  
  2. Const Pi = 3.1415926
  3. Const Radius = 180
  4. Const Xcenter = 325
  5. Const Ycenter = 225
  6. While _KeyDown(27) = 0
  7.     Cls
  8.     s = s + 2 ' increase 1 degree
  9.     Circle (Xcenter, Ycenter), Radius, 6
  10.     'Print "For Degrees: 0 = east, 90 = south, 180 = west, 270 = north"
  11.     'Input "Enter Degree Angle for point  > ", s
  12.     RadianAngle = _D2R(s) ' _D2R converts Degrees 2 (to) Radians which is what Sin and Cos process
  13.     x = Radius * Cos(RadianAngle) + Xcenter
  14.     y = Radius * Sin(RadianAngle) + Ycenter
  15.     'Line (x - 5, y - 5)-Step(10, 10), 14, BF ' yellow square 10x10 at point x, y
  16.     drawRect x, y, 20, 40, RadianAngle + _Pi / 2, 9
  17.     drawRect x, y, 15, 15, RadianAngle + _Pi / 2, 15
  18.  
  19.     p = p + 1
  20.     RadianAngle = _D2R(p) ' _D2R converts Degrees 2 (to) Radians which is what Sin and Cos process
  21.     x = Radius * Cos(RadianAngle) + Xcenter
  22.     y = Radius * Sin(RadianAngle) + Ycenter
  23.     'Line (x - 5, y - 5)-Step(10, 10), 14, BF ' yellow square 10x10 at point x, y
  24.     drawRect x, y, 20, 40, RadianAngle + _Pi / 2, 4
  25.     drawRect x, y, 15, 15, RadianAngle + _Pi / 2, 14
  26.  
  27.     _Display ' stop flicker
  28.     _Limit 60 ' loops per sec
  29.     'Locate 28, 40: Print "ZZZ...";
  30.     'Sleep
  31.  
  32. Sub drawRect (x, y, w, h, raHeading, c As _Unsigned Long)
  33.     ' from x,y draw midY h/2 towards raHeading
  34.     x1 = x + h / 2 * Cos(raHeading)
  35.     y1 = y + h / 2 * Sin(raHeading)
  36.     x2 = x1 + w / 2 * Cos(raHeading + _Pi / 2)
  37.     y2 = y1 + w / 2 * Sin(raHeading + _Pi / 2)
  38.     x3 = x1 + w / 2 * Cos(raHeading - _Pi / 2)
  39.     y3 = y1 + w / 2 * Sin(raHeading - _Pi / 2)
  40.  
  41.     x4 = x + h / 2 * Cos(raHeading - _Pi)
  42.     y4 = y + h / 2 * Sin(raHeading - _Pi)
  43.     x5 = x4 + w / 2 * Cos(raHeading + _Pi / 2)
  44.     y5 = y4 + w / 2 * Sin(raHeading + _Pi / 2)
  45.     x6 = x4 + w / 2 * Cos(raHeading - _Pi / 2)
  46.     y6 = y4 + w / 2 * Sin(raHeading - _Pi / 2)
  47.  
  48.     Line (x2, y2)-(x3, y3), c
  49.     Line (x3, y3)-(x6, y6), c
  50.     Line (x6, y6)-(x5, y5), c
  51.     Line (x5, y5)-(x2, y2), c
  52.     Paint (x, y), c, c
  53.  
  54.  

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #10 on: September 29, 2021, 12:42:50 am »
Ouch! My tailpipe hurts!

Well, it may be my car, but why is your wife driving?

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

Offline Statsman1

  • Newbie
  • Posts: 36
  • I'm just a jerk, but a hero is what I want to be.
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #11 on: September 29, 2021, 09:25:45 am »
You guys are awesome.  :)

Thank you so much for the help and the laughs, first thing in the morning.
Good decisions come from experience.
Experience comes from bad decisions.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #12 on: September 29, 2021, 01:30:51 pm »
Nice @bplus, now you just need 9 circles with smaller circles moving along and you can have a simulated Sol system! Add a yellow circle in the center for the sun and presto!

like so.. sorta
Code: QB64: [Select]
  1.  
  2. CONST Pi = 3.1415926
  3. CONST Radius = 180
  4. CONST Xcenter = 325
  5. CONST Ycenter = 225
  6. WHILE _KEYDOWN(27) = 0
  7.  CLS
  8.  s = s + 1 ' increase 1 degree
  9.  CIRCLE (Xcenter, Ycenter), Radius, 6
  10.  LOCATE 14, 40: PRINT "YOU"
  11.  'Print "For Degrees: 0 = east, 90 = south, 180 = west, 270 = north"
  12.  'Input "Enter Degree Angle for point  > ", s
  13.  RadianAngle = _D2R(s) ' _D2R converts Degrees 2 (to) Radians which is what Sin and Cos process
  14.  x = Radius * COS(RadianAngle) + Xcenter
  15.  y = Radius * SIN(RadianAngle) + Ycenter
  16.  'LINE (x - 5, y - 5)-STEP(10, 10), 14, BF ' yellow square 10x10 at point x, y
  17.  'Earth.... well sorta
  18.  CIRCLE (x, y), 10, 1 '_RGB32(12, 64, 224)
  19.  PAINT (x - 2, y - 2), 1, 1
  20.  PSET (x + 3, y + 3), 2: DRAW "ullurl3urulllur7duurl8ur9url10ur5drrurrullddllulul5ddululur"
  21.  PSET (x + 3, y + 3), 2: DRAW "dr2ur3dldldlddldluurururu"
  22.  _DISPLAY ' stop flicker
  23.  _LIMIT 60 ' loops per sec
  24.  'Locate 28, 40: Print "ZZZ...";
  25.  'Sleep
  26.  
  27.  
« Last Edit: September 29, 2021, 01:42:53 pm by Cobalt »
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #13 on: September 29, 2021, 01:39:46 pm »
Nice @bplus, now you just need 9 circles with smaller circles moving along and you can have a simulated Sol system! Add a yellow circle in the center for the sun and presto!

Halfway there:
Code: QB64: [Select]
  1. _Title "Checkout Which Planet Closet to Earth Most of the Time" 'B+ mod started 2019-03-25
  2. ' inspired by david_uwi post: https://www.qb64.org/forum/index.php?topic=1184.0
  3.  
  4. Const xmax = 700
  5. Const ymax = 700
  6. Const CX = 350
  7. Const CY = 350
  8. Screen _NewImage(xmax, ymax, 32)
  9.  
  10. Type planetType
  11.     x As Single '             track position after so many Earth Days
  12.     y As Single
  13.     name As String '          data
  14.     radius As Single '        millions of KM  data
  15.     edy As Single '           earth day year data
  16.     oneDayAngle As Single '   calc 2 * PI / edy
  17.     distFromEarth As Single ' calc when run model
  18.     closest As Integer '      calc when run model
  19.     cum As Single '           calc when run model
  20.  
  21. 'load planet data from Internet
  22. Dim planet(1 To 4) As planetType
  23. For i = 1 To 4
  24.     Read planet(i).name
  25.     Read planet(i).radius
  26.     Read planet(i).edy
  27.     planet(i).oneDayAngle = _Pi(2 / planet(i).edy)
  28. 'review data check load
  29. For i = 1 To 4
  30.     Print planet(i).name; " is "; planet(i).radius; " million KM from sun and covers an radian angle of"; planet(i).oneDayAngle; " in one Earth day."
  31. Input "<Enter> Model of Solar System", wate$
  32.  
  33. 'run model
  34. For days = 1 To 365.26 * 1000
  35.  
  36.     For i = 1 To 4
  37.         planet(i).x = CX + planet(i).radius * Cos(planet(i).oneDayAngle * days)
  38.         planet(i).y = CY + planet(i).radius * Sin(planet(i).oneDayAngle * days)
  39.     Next
  40.     For i = 1 To 4
  41.         planet(i).distFromEarth = Sqr((planet(i).x - planet(3).x) ^ 2 + (planet(i).y - planet(3).y) ^ 2)
  42.         planet(i).cum = planet(i).cum + planet(i).distFromEarth
  43.     Next
  44.  
  45.     If planet(1).distFromEarth < planet(2).distFromEarth And planet(1).distFromEarth < planet(4).distFromEarth Then planet(1).closest = planet(1).closest + 1
  46.     If planet(2).distFromEarth < planet(1).distFromEarth And planet(2).distFromEarth < planet(4).distFromEarth Then planet(2).closest = planet(2).closest + 1
  47.     If planet(4).distFromEarth < planet(1).distFromEarth And planet(4).distFromEarth < planet(2).distFromEarth Then planet(4).closest = planet(4).closest + 1
  48.  
  49.     'display
  50.     Cls
  51.     Print "Days:"; days
  52.  
  53.     Print "average distances ", "Mercury", "Venus", "Mars"
  54.     Print Space$(22); planet(1).cum / days, planet(2).cum / days, planet(4).cum / days
  55.  
  56.     Print "fraction of time closest", "Mercury", "Venus ", "Mars"
  57.     Print Space$(22), planet(1).closest / days, planet(2).closest / days, planet(4).closest / days
  58.     Circle (CX, CY), 6, _RGB32(255, 255, 0)
  59.     For i = 1 To 4
  60.         Circle (planet(i).x, planet(i).y), i, &HFFFFFFFF
  61.         Select Case i
  62.             Case 1: c~& = &HFFFF0000
  63.             Case 2: c~& = &HFF00FFFF
  64.             Case 3: c~& = &HFF0000AA
  65.             Case 4: c~& = &HFFAA6600
  66.         End Select
  67.         Paint (planet(i).x, planet(i).y), c~&, &HFFFFFFFF
  68.     Next
  69.     _Display
  70.     _Limit 30
  71.  
  72.  
  73. Data "Mercury",57.9,87.97
  74. Data "Venus",108.2,224.7
  75. Data "Earth",149.6,365.26
  76. Data "Mars",227.9,686.98
  77.  
  78.  

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #14 on: September 29, 2021, 01:50:18 pm »
Halfway there:

Nice.

though why is Mars bigger than Earth?
Granted after becoming radioactive I only have a half-life!