Author Topic: ArcRings  (Read 4384 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
ArcRings
« on: December 23, 2021, 01:33:08 pm »
I saw on Discord today someone wanted Thick Circles, I call them Rings soon you will want thick Arcs too. We'll do ArcRings you will have both and they will work with transparent colors too.

Well here's all that, for raStart and raEnd, ra stands for Radian Angle (not degrees) Radian Angles are expressed in fractions of Pi eg Pi = 180 degrees and whole circle is 2*Pi so 1/10 of circle is 2*pi / 10 equivalent to 36 degrees.

Now I use Basic trig Sin(RadianAngle) and Cos(RadianAngle) that go around circle Clockwise as Radian Angle increases unlike Basic's Circle which goes opposite. So between the trig mention and Radian Angle mention I have probably lost most my audience ;-))

Anyway, it will be handy if you want a transparent color arc or ring and you understand what I am calling raStart and raEnd, I hope the rest is self explanatory:
Code: QB64: [Select]
  1. _Title "ArcRings  test" 'B+ 2019-02-21  for Raceman Sequence graphing
  2. ' 2021-12-23 reviewed remove confusing comments and test code then rewrote again for Option _Explicit
  3.  
  4. Screen _NewImage(1000, 700, 32)
  5. _ScreenMove 180, 20
  6.  
  7. While _KeyDown(27) = 0
  8.     i = i + 1
  9.     If i Mod 50 = 0 Then Cls: i = 0
  10.     ro = Rnd * 100 + 50: ri = ro - ro * Rnd - 10
  11.     ArcRing Rnd * 800 + 100, Rnd * 500 + 100, ro, ri, Rnd * _Pi(2), Rnd * _Pi(2), _RGBA32(255 * Rnd, 255 * Rnd, 255 * Rnd, 255 * Rnd)
  12.     _Display
  13.     _Limit 10
  14.  
  15. Sub ArcRing (x0, y0, outerR, innerR, raStart, raEnd, colr As _Unsigned Long)
  16.     Dim Pi2, Pi32, PiH, P, raS, raE, ck1, y, x, d, ra
  17.     Pi2 = _Pi(2)
  18.     Pi32 = _Pi(1.5)
  19.     PiH = _Pi(.5)
  20.     P = _Pi
  21.     raS = raStart ' checking raStart and raEnd to behave as expected
  22.     While raS >= Pi2
  23.         raS = raS - Pi2
  24.     Wend
  25.     While raS < 0
  26.         raS = raS + Pi2
  27.     Wend
  28.     raE = raEnd
  29.     While raE < 0
  30.         raE = raE + Pi2
  31.     Wend
  32.     While raE >= Pi2
  33.         raE = raE - Pi2
  34.     Wend
  35.     If raE > raS Then ck1 = -1
  36.     For y = y0 - outerR To y0 + outerR
  37.         For x = x0 - outerR To x0 + outerR
  38.             d = Sqr((x - x0) * (x - x0) + (y - y0) * (y - y0))
  39.             If d >= innerR And d <= outerR Then 'within 2 radii
  40.                 'angle of x, y to x0, y0
  41.                 If x - x0 <> 0 And y - y0 <> 0 Then
  42.                     ra = _Atan2(y - y0, x - x0)
  43.                     If ra < 0 Then ra = ra + Pi2
  44.                 ElseIf x - x0 = 0 Then
  45.                     If y >= y0 Then ra = _Pi / 2 Else ra = Pi32
  46.                 ElseIf y - y0 = 0 Then
  47.                     If x >= x0 Then ra = 0 Else ra = PI
  48.                 End If
  49.                 If ck1 Then 'raEnd > raStart
  50.                     If ra >= raS And ra <= raE Then
  51.                         PSet (x, y), colr
  52.                     End If
  53.                 Else 'raEnd < raStart, raEnd is falls before raStart clockwise so fill through 2 * PI
  54.                     If ra >= raS And ra < Pi2 Then
  55.                         PSet (x, y), colr
  56.                     Else
  57.                         If ra >= 0 And ra <= raE Then
  58.                             PSet (x, y), colr
  59.                         End If
  60.                     End If
  61.                 End If
  62.             End If
  63.         Next
  64.     Next
  65.  

 
ArcRing Test.PNG
« Last Edit: December 23, 2021, 01:40:50 pm by bplus »

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: ArcRings
« Reply #1 on: December 24, 2021, 12:37:21 am »
Nice party simulation, but why would Pac Men, Commodore enthusiasts, and Communists hang out together?
It works better if you plug it in.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: ArcRings
« Reply #2 on: December 24, 2021, 12:44:52 am »
Nice party simulation, but why would Pac Men, Commodore enthusiasts, and Communists hang out together?

Russian Retro C64 Pacman Championships, of course!
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: ArcRings
« Reply #3 on: December 24, 2021, 12:49:23 am »
Quote
but why would Pac Men, Commodore enthusiasts, and Communists hang out together?

To see the Olympics:
 
Ring and Arc Demo.PNG


If you don't need transparent colors, here is much simpler code for Rings and Thick Arcs:
Code: QB64: [Select]
  1.  
  2. _Title "Ring and Arc by Circle Demo" 'b+ 2021-12-23
  3. Const ORadius = 100, IRadius = 80, Margin = 10
  4. Const Red = &HFFFF1946
  5. Const Green = &HFF00A748
  6. Const Yellow = &HFFFFBE1C
  7. Const Blue = &HFF645AFF
  8. Dim sw, sh
  9.  
  10.  
  11. sw = ORadius * 3 * 2 + 4 * Margin: sh = ORadius * 3 + 2 * Margin
  12.  
  13. Screen _NewImage(sw, sh, 32)
  14. _ScreenMove 300, 200
  15. Color , &HFFFFFFFF
  16. Ring Margin + ORadius, Margin + ORadius, IRadius, ORadius, Blue
  17. Ring 1.5 * Margin + 2 * ORadius, Margin + 2 * ORadius, IRadius, ORadius, Yellow
  18.  
  19. Ring 2 * Margin + 3 * ORadius, Margin + ORadius, IRadius, ORadius, &HFF000000
  20. Ring 2.5 * Margin + 4 * ORadius, Margin + 2 * ORadius, IRadius, ORadius, Green
  21.  
  22. Ring 3 * Margin + 5 * ORadius, Margin + ORadius, IRadius, ORadius, Red
  23.  
  24. ' overlap arcs
  25. ' blue over yellow
  26. ArcRing Margin + ORadius, Margin + ORadius, IRadius, ORadius, _Pi(1.75), 0, Blue
  27. ' yellow over black
  28. ArcRing 1.5 * Margin + 2 * ORadius, Margin + 2 * ORadius, IRadius, ORadius, _Pi(.25), _Pi(.5), Yellow
  29. ' black over green
  30. ArcRing 2 * Margin + 3 * ORadius, Margin + ORadius, IRadius, ORadius, _Pi(1.75), _Pi(0), &HFF000000
  31. ' green over red
  32. ArcRing 2.5 * Margin + 4 * ORadius, Margin + 2 * ORadius, IRadius, ORadius, _Pi(.25), _Pi(.5), Green
  33.  
  34. Sub Ring (cx, cy, innerRadius, outerRadius, colr~&) ' wont work well with alpha's < 255
  35.     Dim r
  36.     For r = innerRadius To outerRadius Step .25
  37.         Circle (cx, cy), r, colr~&
  38.     Next
  39.  
  40. 'ra's here go Counter Clockwise from East
  41. Sub ArcRing (cx, cy, innerRadius, outerRadius, raStart, raEnd, colr~&) ' ra's 0 to <2*pi (almost)
  42.     Dim r
  43.     For r = innerRadius To outerRadius Step .25
  44.         Circle (cx, cy), r, colr~&, raStart, raEnd
  45.     Next
  46.  

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: ArcRings
« Reply #4 on: December 24, 2021, 01:25:49 am »
I threw in a _DELAY .01 after the last circle to be able to follow the action.  What I
learned  from this, mainly, is the _PI multiplier.   Super demo of that function.
It works better if you plug it in.

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: ArcRings
« Reply #5 on: December 25, 2021, 04:47:40 pm »
Next step: Anaglyph red-cyan

240 KB =1000x1000

 
Don-Davis-3d-anaglyph-of-Saturn-Rings-3d-photo-3d-.jpg


+ en.wikipedia.org/wiki/Anaglyph_3D

https://en.wikipedia.org/wiki/Anaglyph_3D
« Last Edit: December 25, 2021, 10:57:06 pm by DANILIN »
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: ArcRings
« Reply #6 on: December 25, 2021, 07:35:06 pm »
OK ArcRing of Ellipse:
Code: QB64: [Select]
  1.  
  2. _Title "Arc of Ellisps" 'b+ 2021-12-25
  3.  
  4. Dim sw, sh
  5. sw = 600: sh = 600
  6.  
  7. Screen _NewImage(sw, sh, 32)
  8. _ScreenMove 300, 200
  9.  
  10. ArcRingOfEllipse sw / 2, sh / 2, 120, 200, _Pi(0), _Pi(1), .25, &HFFAAAAFF
  11. Ring sw / 2, sh / 2, 0, 85, &HFF880088
  12. ArcRingOfEllipse sw / 2, sh / 2, 120, 200, _Pi(1), _Pi(1.999), .25, &HFFAAAAFF
  13.  
  14. Sub Ring (cx, cy, innerRadius, outerRadius, colr~&) ' wont work well with alpha's < 255
  15.     Dim r
  16.     For r = innerRadius To outerRadius Step .25
  17.         Circle (cx, cy), r, colr~&
  18.     Next
  19.  
  20. 'ra's here go Counter Clockwise from East
  21. Sub ArcRing (cx, cy, innerRadius, outerRadius, raStart, raEnd, colr~&) ' ra's 0 to <2*pi (almost)
  22.     Dim r
  23.     For r = innerRadius To outerRadius Step .25
  24.         Circle (cx, cy), r, colr~&, raStart, raEnd
  25.     Next
  26.  
  27. 'ra's here go Counter Clockwise from East
  28. Sub ArcRingOfEllipse (cx, cy, innerRadius, outerRadius, raStart, raEnd, aspect, colr~&) ' ra's 0 to <2*pi (almost)
  29.     Dim r
  30.     For r = innerRadius To outerRadius Step .25
  31.         Circle (cx, cy), r, colr~&, raStart, raEnd, aspect
  32.     Next
  33.  
  34.  
  35.  



Arc of Ellipse.PNG
* Arc of Ellipse.PNG (Filesize: 6.23 KB, Dimensions: 602x600, Views: 104)