Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Blitz => Topic started by: mike_g on March 04, 2007

Title: Sector Drawing Function[BB2D]
Post by: mike_g on March 04, 2007
I havent been coding for quite some time now. I plan on getting back into it. Anyway heres something I came up with last night. Its nothing amazing, it just draws sectors of circles.

Code: [Select]
Graphics 640, 480, 32, 2
SetBuffer BackBuffer()
While Not KeyHit(1)
Cls
DRAW_SECTOR(200, 200, 20, 100, 60, i, $ffffff)
DRAW_SECTOR(200, 200, 20, 100, 60, i+120, $ffffff)
DRAW_SECTOR(200, 200, 20, 100, 60, i+240, $ffffff)

DRAW_SECTOR(500, 200, 70, 100, 300, i, $ffffff)
DRAW_SECTOR(500, 200, 20, 50, 300, 360-i, $ffffff)

i=i+1
If i = 360 Then i = 0
Flip
Wend

Function DRAW_SECTOR(cx, cy, start_rad, end_rad, sector_deg, start_deg, col)
LockBuffer
;DRAW OUTER CURVE
inc# = Float(sector_deg/(end_rad*Pi*2))
steps = sector_deg/inc#
deg# = start_deg
For i = 1 To steps
x = (cx - end_rad * Cos(deg#))
y = (cy - end_rad * Sin(deg#))
If x >= 0 And x < GraphicsWidth() And y >= 0 And y < GraphicsHeight()
WritePixelFast x, y, col
EndIf
deg# = deg# + inc#
Next

;DRAW INNER CURVE
inc# = Float(sector_deg/(start_rad*Pi*2))
steps = sector_deg/inc#
deg# = start_deg
For i = 1 To steps
x = (cx - start_rad * Cos(deg#))
y = (cy - start_rad * Sin(deg#))
If x >= 0 And x < GraphicsWidth() And y >= 0 And y < GraphicsHeight()
WritePixelFast x, y, col
EndIf
deg# = deg# + inc#
Next

;DRAW LINES
x1 = (cx - start_rad * Cos(start_deg))
y1 = (cy - start_rad * Sin(start_deg))
x2 = (cx - end_rad * Cos(start_deg))
y2 = (cy - end_rad * Sin(start_deg))
Line x1, y1, x2, y2
x1 = (cx - start_rad * Cos(start_deg+sector_deg))
y1 = (cy - start_rad * Sin(start_deg+sector_deg))
x2 = (cx - end_rad * Cos(start_deg+sector_deg))
y2 = (cy - end_rad * Sin(start_deg+sector_deg))
Line x1, y1, x2, y2
UnlockBuffer
End Function
Title: Re: Sector Drawing Function
Post by: Paul on March 04, 2007
well done, love seeing these small blitz snippets.
Title: Re: Sector Drawing Function
Post by: mike_g on March 04, 2007
Cheers :)
Title: Re: Sector Drawing Function
Post by: Shockwave on March 04, 2007
Thanks Mike for posting the source :) Appreciated! K+
Title: Re: Sector Drawing Function
Post by: JumpMan on March 05, 2007
I Like it Mike. great job!