QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Statsman1 on September 28, 2021, 09:38:12 pm

Title: Plotting / erasing points on a circle
Post by: Statsman1 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!
Title: Re: Plotting / erasing points on a circle
Post by: Pete 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
Title: Re: Plotting / erasing points on a circle
Post by: Statsman1 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.
Title: Re: Plotting / erasing points on a circle
Post by: Pete 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
Title: Re: Plotting / erasing points on a circle
Post by: Pete on September 28, 2021, 11:00:35 pm
Oh, and if you ever want to go linear: https://www.tapatalk.com/groups/qbasic/viewtopic.php?p=212867#p212867
Title: Re: Plotting / erasing points on a circle
Post by: bplus 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.  
Title: Re: Plotting / erasing points on a circle
Post by: bplus 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.  
Title: Re: Plotting / erasing points on a circle
Post by: Pete 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.  
Title: Re: Plotting / erasing points on a circle
Post by: bplus 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.  
Title: Re: Plotting / erasing points on a circle
Post by: bplus 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.  
Title: Re: Plotting / erasing points on a circle
Post by: Pete 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
Title: Re: Plotting / erasing points on a circle
Post by: Statsman1 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.
Title: Re: Plotting / erasing points on a circle
Post by: Cobalt 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.  
Title: Re: Plotting / erasing points on a circle
Post by: bplus 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.  
Title: Re: Plotting / erasing points on a circle
Post by: Cobalt on September 29, 2021, 01:50:18 pm
Halfway there:

Nice.

though why is Mars bigger than Earth?
Title: Re: Plotting / erasing points on a circle
Post by: bplus on September 29, 2021, 01:57:09 pm
Why is Mars bigger than Earth?

Good question.

Radius was same as planet index in the drawing. I guess that was not considered as important in this problem.
Code: QB64: [Select]
  1.     Circle (CX, CY), 6, _RGB32(255, 255, 0)
  2.     For i = 1 To 4
  3.         Circle (planet(i).x, planet(i).y), i, &HFFFFFFFF
  4.         Select Case i
  5.             Case 1: c~& = &HFFFF0000
  6.             Case 2: c~& = &HFF00FFFF
  7.             Case 3: c~& = &HFF0000AA
  8.             Case 4: c~& = &HFFAA6600
  9.         End Select
  10.         Paint (planet(i).x, planet(i).y), c~&, &HFFFFFFFF
  11.     Next
  12.  

Oh Hey! @Cobalt nice little drawing of Earth! :)
Title: Re: Plotting / erasing points on a circle
Post by: Petr on September 29, 2021, 02:35:50 pm
Hi guys. I see that the thread is moving on with its life for the time being ... this fascinated me (the cars), so I tried to add a straight forward and backward movement. Yeah, it works ... but I can't complete the drive to turn right. Does anyone want to deal with this? The center of rotation must change - move in the X axis, the S position must change by 180 degrees ... Because of that, I didn't add anything to my program again today, it happens to me all the time, something interests me here and then time goes crazy...

But really, very good theme, this!

use arrows

Code: QB64: [Select]
  1.  
  2. DIM SHARED Xcenter, Ycenter, Radius
  3. CONST Pi = 3.1415926
  4. Radius = 80
  5. Xcenter = 325
  6. Ycenter = 225
  7.  
  8. WHILE _KEYDOWN(27) = 0
  9.     CarAngleGAS = RadianAngle + _D2R(270)
  10.     CarAngleBRAKE = RadianAngle + _D2R(90)
  11.     K& = _KEYHIT
  12.     SELECT CASE K&
  13.         CASE 18432 'arrow UP is gas
  14.             Xcenter = 2 * COS(CarAngleGAS) + Xcenter
  15.             Ycenter = 2 * SIN(CarAngleGAS) + Ycenter
  16.             X = 2 * COS(CarAngleGAS) + X
  17.             Y = 2 * SIN(CarAngleGAS) + Y
  18.             GOTO dr
  19.  
  20.         CASE 20480 'arrow DOWN is brake
  21.             Xcenter = 2 * COS(CarAngleBRAKE) + Xcenter
  22.             Ycenter = 2 * SIN(CarAngleBRAKE) + Ycenter
  23.             X = 2 * COS(CarAngleBRAKE) + X
  24.             Y = 2 * SIN(CarAngleBRAKE) + Y
  25.             GOTO dr
  26.  
  27.         CASE 19712
  28.             S = S + 1 'to right
  29.             GOTO dr
  30.  
  31.         CASE 19200
  32.             S = S - 1 'to left
  33.     END SELECT
  34.  
  35.  
  36.  
  37.     CLS
  38.     'S = S + 1 ' increase 1 degree
  39.     'CIRCLE (Xcenter, Ycenter), Radius, 6
  40.  
  41.     'Print "For Degrees: 0 = east, 90 = south, 180 = west, 270 = north"
  42.     'Input "Enter Degree Angle for point  > ", s
  43.     RadianAngle = _D2R(S) ' _D2R converts Degrees 2 (to) Radians which is what Sin and Cos process
  44.  
  45.     X = Radius * COS(RadianAngle) + Xcenter
  46.     Y = Radius * SIN(RadianAngle) + Ycenter
  47.  
  48.     dr:
  49.     RadianAngle = _D2R(S)
  50.     LINE (X - 5, Y - 5)-STEP(10, 10), 14, BF ' yellow square 10x10 at point x, y
  51.     drawRect X, Y, 20, 40, RadianAngle + _PI / 2, 9
  52.     drawRect X, Y, 15, 15, RadianAngle + _PI / 2, 15
  53.     _DISPLAY ' stop flicker
  54.     _LIMIT 60 ' loops per sec
  55.     'Locate 28, 40: Print "ZZZ...";
  56.     'Sleep
  57.  
  58. SUB drawRect (x, y, w, h, raHeading, c AS _UNSIGNED LONG)
  59.     ' from x,y draw midY h/2 towards raHeading
  60.     X1 = x + h / 2 * COS(raHeading)
  61.     Y1 = y + h / 2 * SIN(raHeading)
  62.     X2 = X1 + w / 2 * COS(raHeading + _PI / 2)
  63.     Y2 = Y1 + w / 2 * SIN(raHeading + _PI / 2)
  64.     x3 = X1 + w / 2 * COS(raHeading - _PI / 2)
  65.     y3 = Y1 + w / 2 * SIN(raHeading - _PI / 2)
  66.  
  67.     x4 = x + h / 2 * COS(raHeading - _PI)
  68.     y4 = y + h / 2 * SIN(raHeading - _PI)
  69.     x5 = x4 + w / 2 * COS(raHeading + _PI / 2)
  70.     y5 = y4 + w / 2 * SIN(raHeading + _PI / 2)
  71.     x6 = x4 + w / 2 * COS(raHeading - _PI / 2)
  72.     y6 = y4 + w / 2 * SIN(raHeading - _PI / 2)
  73.  
  74.     LINE (X2, Y2)-(x3, y3), c
  75.     LINE (x3, y3)-(x6, y6), c
  76.     LINE (x6, y6)-(x5, y5), c
  77.     LINE (x5, y5)-(X2, Y2), c
  78.     PAINT (x, y), c, c
  79.  
Title: Re: Plotting / erasing points on a circle
Post by: bplus on September 29, 2021, 03:59:00 pm
So Petr, you want to drive a car? Hope you like Blue and white :)

When you hit the border of screen your speed will be stopped, just turn and hit gas again.

Think of blue.ra as the current heading or direction the car is going 0 = east, 90 = south ...
but just drive the car with left and right arrows as steering wheel. The white edge is the front end.

Code: QB64: [Select]
  1. _Title "Drive Car" 'b+ 2021-09-29
  2. Type car
  3.     As Single x, y, w, h, ra, speed
  4.     As _Unsigned Long c
  5.  
  6. Dim blue As car
  7. blue.x = _Width / 2: blue.y = _Height / 2
  8. blue.w = 20: blue.h = 40
  9. blue.ra = _Pi / 2: blue.speed = 2
  10. blue.c = 9
  11.  
  12. While _KeyDown(27) = 0
  13.     CarAngle = CarAngle + _D2R(s)
  14.     K& = _KeyHit
  15.     Select Case K&
  16.         Case 18432 'arrow UP is gas
  17.             blue.speed = blue.speed + .1
  18.             If blue.speed > 5 Then blue.speed = 5
  19.         Case 20480 'arrow DOWN slow down
  20.             blue.speed = blue.speed - .1
  21.             If blue.speed < 0 Then blue.speed = 0
  22.         Case 19712
  23.             s = s + 2 'to right
  24.         Case 19200
  25.             s = s - 2 'to left
  26.     End Select
  27.     Cls
  28.     blue.ra = _D2R(s)
  29.     blue.x = blue.x + blue.speed * Cos(blue.ra)
  30.     blue.y = blue.y + blue.speed * Sin(blue.ra)
  31.     If blue.x < 10 Or blue.x > _Width - 10 Then blue.speed = 0
  32.     If blue.y < 10 Or blue.y > _Height - 10 Then blue.speed = 0
  33.     drawCar blue
  34.     _Display ' stop flicker
  35.     _Limit 30 ' loops per sec
  36.  
  37. Sub drawCar (a As car)
  38.     ' code not optimized for speed  just proff of concept
  39.     X1 = a.x + a.h / 2 * Cos(a.ra)
  40.     Y1 = a.y + a.h / 2 * Sin(a.ra)
  41.     X2 = X1 + a.w / 2 * Cos(a.ra + _Pi / 2)
  42.     Y2 = Y1 + a.w / 2 * Sin(a.ra + _Pi / 2)
  43.     X3 = X1 + a.w / 2 * Cos(a.ra - _Pi / 2)
  44.     Y3 = Y1 + a.w / 2 * Sin(a.ra - _Pi / 2)
  45.  
  46.     x4 = a.x + a.h / 2 * Cos(a.ra - _Pi)
  47.     y4 = a.y + a.h / 2 * Sin(a.ra - _Pi)
  48.     x5 = x4 + a.w / 2 * Cos(a.ra + _Pi / 2)
  49.     y5 = y4 + a.w / 2 * Sin(a.ra + _Pi / 2)
  50.     x6 = x4 + a.w / 2 * Cos(a.ra - _Pi / 2)
  51.     y6 = y4 + a.w / 2 * Sin(a.ra - _Pi / 2)
  52.  
  53.     Line (X2, Y2)-(X3, Y3), a.c
  54.     Line (X3, Y3)-(x6, y6), a.c
  55.     Line (x6, y6)-(x5, y5), a.c
  56.     Line (x5, y5)-(X2, Y2), a.c
  57.     Paint (a.x, a.y), a.c, a.c
  58.     Line (X2, Y2)-(X3, Y3), 15 ' give car a front
  59.  
  60.     ' white top  for all cars for future numbers maybe
  61.     X1 = a.x + a.h / 4 * Cos(a.ra)
  62.     Y1 = a.y + a.h / 4 * Sin(a.ra)
  63.     X2 = X1 + (a.w / 2 - 3) * Cos(a.ra + _Pi / 2)
  64.     Y2 = Y1 + (a.w / 2 - 3) * Sin(a.ra + _Pi / 2)
  65.     X3 = X1 + (a.w / 2 - 3) * Cos(a.ra - _Pi / 2)
  66.     Y3 = Y1 + (a.w / 2 - 3) * Sin(a.ra - _Pi / 2)
  67.  
  68.     x4 = a.x + a.h / 4 * Cos(a.ra - _Pi)
  69.     y4 = a.y + a.h / 4 * Sin(a.ra - _Pi)
  70.     x5 = x4 + (a.w / 2 - 3) * Cos(a.ra + _Pi / 2)
  71.     y5 = y4 + (a.w / 2 - 3) * Sin(a.ra + _Pi / 2)
  72.     x6 = x4 + (a.w / 2 - 3) * Cos(a.ra - _Pi / 2)
  73.     y6 = y4 + (a.w / 2 - 3) * Sin(a.ra - _Pi / 2)
  74.  
  75.     Line (X2, Y2)-(X3, Y3), 15
  76.     Line (X3, Y3)-(x6, y6), 15
  77.     Line (x6, y6)-(x5, y5), 15
  78.     Line (x5, y5)-(X2, Y2), 15
  79.     Paint (a.x, a.y), 15, 15
  80.  
  81.  
  82.  
Title: Re: Plotting / erasing points on a circle
Post by: Petr on September 29, 2021, 04:14:55 pm
Thanks a lot, BPlus. I thought that the previous example would like to modify a lot for this purpose. Great work again. Thank you.
Title: Re: Plotting / erasing points on a circle
Post by: Pete on September 29, 2021, 04:29:29 pm
Nice.

though why is Mars bigger than Earth?

A better question would be, "Where did Saturn get it's rings? At previous engagements, but I digress. Of course Mark would make Mars bigger than Earth. It's a point of pride. Did you guys forget about his previous Marvin the Martian avatar? I still can't understand why Marvin chose to wear a skirt, especially with those legs, but hey, again it's all about ego. Martian, Martian, Martian.

I liked it better when the planets were all gas powered, you know, the era before they were converted to a Solar System.

Pete

Title: Re: Plotting / erasing points on a circle
Post by: bplus on September 29, 2021, 04:43:34 pm
One of the first things I ever did with an image was a cartoon with Marvin. It was called. "Marvin has a ball". Maybe johnno remembers it.

@Pete it's called a Pteruges
Quote
Pteruges formed a defensive skirt of leather or multi-layered fabric (linen) strips or lappets worn dependant from the waists of Roman and Greek cuirasses of warriors and soldiers, defending the hips and thighs.
Title: Re: Plotting / erasing points on a circle
Post by: Pete on September 29, 2021, 05:19:44 pm
And a purse is just a really BIG wallet, with a strap.

Pete :D
Title: Re: Plotting / erasing points on a circle
Post by: bplus on September 29, 2021, 09:00:24 pm
Nah a really big wallet is a bank.

And I am getting ideas for cars navigating tracks, maybe with some banks.
Title: Re: Plotting / erasing points on a circle
Post by: Statsman1 on September 29, 2021, 10:08:56 pm
I feel like my inquiry really started something.....
Title: Re: Plotting / erasing points on a circle
Post by: bplus on September 29, 2021, 10:55:34 pm
I feel like my inquiry really started something.....

Yeah maybe, how are you coming along?
Title: Re: Plotting / erasing points on a circle
Post by: Statsman1 on October 02, 2021, 10:30:23 am
Yeah maybe, how are you coming along?

Well, I got away from it for a few days with other stuff to do (bought an Apple III, 6 Apple IIe and a II+), and chores and the like, but got back to it last night and things seem to be coming together.

I have decided, though, to use the framework I have created and instead of auto racing (which would involve collision detection and user inputs, and an AI I am prepared for just yet), I am going to make this a horse racing program.  Wagering model, stable management, etc.

One of my favorite games ever was Sport of Kings by Omni-Play (later Virgin)…

https://www.myabandonware.com/game/sport-of-kings-19p (https://www.myabandonware.com/game/sport-of-kings-19p)

…so why not?
Title: Re: Plotting / erasing points on a circle
Post by: bplus on October 02, 2021, 12:37:42 pm
Yes good to start with clear goal in mind. Then you learn allot as you work your way to it, even if you don't make it right away it remains in back burner cooking, ripening.

Here is handy collision Function for 2 boxes, returns -1 = True they overlap or 0 = False no overlap:
Code: QB64: [Select]
  1. 'very handy function to detect if 2 boxes will overlap, given their top left corner and width and height, Thanks Johnno
  2. Function collision% (b1x, b1y, b1w, b1h, b2x, b2y, b2w, b2h)
  3.     ' yes a type smaller than integer might be used
  4.     ' x, y represent the box left most x and top most y
  5.     ' w, h represent the box width and height which is the usual way sprites / tiles / images are described
  6.     ' such that boxbottom = by + bh
  7.     '        and boxright = bx + bw
  8.     'so the specific gosub above is gerealized to a function procedure here!
  9.     If (b1y + b1h < b2y) Or (b1y > b2y + b2h) Or (b1x > b2x + b2w) Or (b1x + b1w < b2x) Then
  10.         collision% = 0
  11.     Else
  12.         collision% = -1
  13.     End If
  14.  

Assuming these are boxes that align with x and y axis ie what Line command draws with B or BF option and what _PutImage uses.