DrawRegularPolygon() 2D function:
Code: Select all
Procedure DrawRegularPolygon(x.f,y.f,r.f,n.l,fase.f,color.l)
; 'x,y' <- center of polygon
; 'r' <- radius
; 'n' <- number of sides
; 'fase' <- first vertex angle position
Protected a.f=2*#PI/n,t.l,d0.f,d.f=fase
For t.l=1 To n
d0=d
d=t*a+fase
LineXY(x+r*Cos(d0),y+r*Sin(d0),x+r*Cos(d),y+r*Sin(d),color)
Next
EndProcedure
Code: Select all
InitMouse():InitSprite():InitKeyboard()
OpenScreen(GetSystemMetrics_(#SM_CXSCREEN),GetSystemMetrics_(#SM_CYSCREEN),32,"Draw Regular Polygon")
Procedure DrawRegularPolygon(x.f,y.f,r.f,n.l,fase.f,color.l)
; 'x,y' <- center of polygon
; 'r' <- radius
; 'n' <- number of sides
; 'fase' <- first vertex angle position
Protected a.f=2*#PI/n,t.l,d0.f,d.f=fase
For t.l=1 To n
d0=d
d=t*a+fase
LineXY(x+r*Cos(d0),y+r*Sin(d0),x+r*Cos(d),y+r*Sin(d),color)
Next
EndProcedure
r1.f=170:p.l=3
MouseLocate(333,333)
Repeat
ClearScreen(0)
ExamineKeyboard()
ExamineMouse():x.l=MouseX():y.l=MouseY()
StartDrawing(ScreenOutput())
DrawRegularPolygon(x,y,r1.f,p,fa.f,$aaaaaa)
If MouseButton(#PB_MouseButton_Middle)
fa+MouseWheel()*0.1
Else
r1+MouseWheel()*10
EndIf
If MouseButton(#PB_MouseButton_Right):While MouseButton(#PB_MouseButton_Right):Delay(16):ExamineMouse():Wend
p+1:If p>80:p=80:EndIf
ElseIf MouseButton(#PB_MouseButton_Left):While MouseButton(#PB_MouseButton_Left):Delay(16):ExamineMouse():Wend
p-1:If p<2:p=2:EndIf
EndIf
StopDrawing()
FlipBuffers():Delay(16)
Until KeyboardPushed(#PB_Key_Escape)