• Welcome to Dark Bit Factory & Gravity.
 

Sector Drawing Function[BB2D]

Started by mike_g, March 04, 2007

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

mike_g

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.


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

Paul

well done, love seeing these small blitz snippets.
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

mike_g


Shockwave

Thanks Mike for posting the source :) Appreciated! K+
Shockwave ^ Codigos
Challenge Trophies Won:

JumpMan

I Like it Mike. great job!