Author Topic: Sector Drawing Function[BB2D]  (Read 3881 times)

0 Members and 1 Guest are viewing this topic.

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Sector Drawing Function[BB2D]
« 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
« Last Edit: July 21, 2007 by Shockwave »

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Sector Drawing Function
« Reply #1 on: March 04, 2007 »
well done, love seeing these small blitz snippets.
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: Sector Drawing Function
« Reply #2 on: March 04, 2007 »
Cheers :)

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17427
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: Sector Drawing Function
« Reply #3 on: March 04, 2007 »
Thanks Mike for posting the source :) Appreciated! K+
Shockwave ^ Codigos
Challenge Trophies Won:

Offline JumpMan

  • C= 64
  • **
  • Posts: 45
  • Karma: 11
    • View Profile
Re: Sector Drawing Function
« Reply #4 on: March 05, 2007 »
I Like it Mike. great job!