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

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #15 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! :)

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #16 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.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #17 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.  
« Last Edit: September 29, 2021, 09:04:08 pm by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #18 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.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #19 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

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 #20 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.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #21 on: September 29, 2021, 05:19:44 pm »
And a purse is just a really BIG wallet, with a strap.

Pete :D
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 #22 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.

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 #23 on: September 29, 2021, 10:08:56 pm »
I feel like my inquiry really started something.....
Good decisions come from experience.
Experience comes from bad decisions.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #24 on: September 29, 2021, 10:55:34 pm »
I feel like my inquiry really started something.....

Yeah maybe, how are you coming along?

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 #25 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

…so why not?
Good decisions come from experience.
Experience comes from bad decisions.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Plotting / erasing points on a circle
« Reply #26 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.