Try my new website:
www.urcho.com
- the new SIMPLE social network
Sign up
|
358
members |
125
snippets
Search for:
ALL
POPULAR
File Controls
Multiplayer Code
2D Effects
3D Effects
Oldskool demos
Basic Functions
Maths/Physics
Sound
Tutorials
Misc
Username:
Password:
Sign up
Bresenham like circles
[
back
]
Author:
Andy_A
| Viewed:
386
times | Language:
BlitzPlus
| Category:
2D Effects
;Source: ; http://homepage.smc.edu/kennedy_john/papers.htm ; http://homepage.smc.edu/kennedy_john/bcircle.pdf ; A Fast Bresenham Type Algorithm For Drawing Circles ; by ; John Kennedy ; Blitzplus port by Andy_A AppTitle "Bresenham Circle" Graphics 800,600,32,2 SetBuffer BackBuffer() numIterations% = 100 LockBuffer GraphicsBuffer() st = MilliSecs() For i = 1 To numIterations PlotCircle(400, 300, 290, $FFE020, 0) Next et1# = MilliSecs()-st st = MilliSecs() For i = 1 To numIterations Oval 110, 10, 580, 580, 0 Next et2# = MilliSecs()-st UnlockBuffer Text 5, 5,"Avg/Circle: "+(et1/Float(numIterations))+"ms" Text 5,20," Avg/Oval: "+(et2/Float(numIterations))+"ms" Flip WaitMouse() End Function PlotCircle(CX%, CY%, R%, colr%, fill% = 0) Local X%, Y% Local XChange%, YChange% Local RadiusError% Color (colr And $FF0000) Shr 16, (colr And $FF00) Shr 8, colr And $FF X = R Y = 0 XChange = 1 - (R + R) YChange = 1 RadiusError = 0 While X >= Y If fill <> 0 Then Line(CX-X, CY+Y, CX+X, CY+Y) ;used calc'd values to draw Line(CX-X, CY-Y, CX+X, CY-Y) ;scan lines from points Line(CX-Y, CY+X, CX+Y, CY+X) ;in opposite octants Line(CX-Y, CY-X, CX+Y, CY-X) Else WritePixelFast(CX+X, CY+Y, colr) ; {point in octant 1} WritePixelFast(CX-X, CY+Y, colr) ; {point in octant 4} WritePixelFast(CX-X, CY-Y, colr) ; {point in octant 5} WritePixelFast(CX+X, CY-Y, colr) ; {point in octant 8} WritePixelFast(CX+Y, CY+X, colr) ; {point in octant 2} WritePixelFast(CX-Y, CY+X, colr) ; {point in octant 3} WritePixelFast(CX-Y, CY-X, colr) ; {point in octant 6} WritePixelFast(CX+Y, CY-X, colr) ; {point in octant 7} End If Y = Y + 1 RadiusError = RadiusError + YChange YChange = YChange + 2 If RadiusError + RadiusError + XChange > 0 Then X = X - 1 RadiusError = RadiusError + XChange XChange = XChange + 2 End If Wend End Function
Author Comments:
Bresenhams circle drawing algorithm. Has optional parameter to fill circle.
Login or
create an account
to comment on this snippet