Ooops
October 28, 2020, 11:47:53 PM

### Author Topic: [bmx] ARC by Jesse [ 1+ years ago ]  (Read 1489 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bmx] ARC by Jesse [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : ARC
Author : Jesse
Posted : 1+ years ago

Description : draws an arc, a pie piece or a circle segment by plotting pixels as efficiently as possible. The arc is draw clockwise from starting angle to ending angle up to the maximum of 360 degrees. If the starting angle is greater the the ending angle, the angles are swapped.

Code :
Code: BlitzMax
1. SuperStrict
2. Function arc(x:Float, y:Float, startAngle:Float, endAngle:Float, radius:Float,closed:Int = False,pie:Int = False)
3.         Local fx:Float,fy:Float 'first x,y
4.         Local lx:Float,ly:Float 'last x,y
5.         Const RATE:Float = Pi/180.0
6.         If startAngle = endAngle Then Return
7.         If startAngle > endAngle
8.                 Local ta:Float = endAngle
9.                 endAngle = startAngle
10.                 startAngle = ta
11.         EndIf
12.         Local angle:Float = endAngle - StartAngle
13.         If angle > 360.0 angle = 360.0
14.
15.         Local Stp:Float = 1/(RATE * radius)
16.         Local AccumAngle:Float = StartAngle
17.         If closed = True
18.                 fx = Cos(accumAngle) * radius
19.                 fy = Sin(accumAngle) * radius
20.         EndIf
21.         While accumAngle < (StartAngle+Angle)
22.
23.                         lx:Float = Cos((accumAngle)) * radius
24.                         ly:Float = Sin((accumAngle)) * radius
25.                         Plot x + lx, y + ly
26.                         AccumAngle :+ stp
27.         Wend
28.
29.         If closed = True
30.                 If pie = True
31.                         DrawLine x, y, x + fx, y + fy,False
32.                         DrawLine x, y, x + lx, y + ly,False
33.                 Else
34.                         DrawLine x+fx,y+fy,x+lx,y+ly,False
35.                 EndIf
36.         EndIf
37. End Function
38.
39.
40. Graphics 800,600
41.
42. Repeat
43.         Cls
44.         arc(400,300,0,90,200,True,True)
45.         arc(380,280,90,360,200,True,True)
46.         Flip
47. Until KeyDown(key_escape)