Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
'http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Button
IDC_Graphic
End Enum
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Draw", 10,10,100,20
Control Add Graphic, hDlg, %IDC_Graphic,"", 10,30,150,150, %WS_Border
Graphic Attach hDlg, %IDC_Graphic
Graphic Set Overlap
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
DrawCircle 75,75,20,%Red
Graphic Ellipse (55,55)-(95,95),%Green
End Select
End Select
End Function
Sub DrawCircle(cx As Long, cy As Long, Radius As Long, clr As Long)
Local E,x,y As Long
E = -radius : x = radius : y = 0
While x > y
plot4points cx, cy, x, y, clr
plot4points cx, cy, y, x, clr
E += y : Incr y : E += y
If E >=0 Then E -= x : Decr x : E -= x
Wend
plot4points cx,cy,y,x,clr
End Sub
Sub plot4points(cx As Long, cy As Long, x As Long, y As Long, clr As Long)
Graphic Set Pixel (cx + x, cy + y), clr
If x Then Graphic Set Pixel (cx - x, cy + y), clr
If y Then Graphic Set Pixel (cx + x, cy - y), clr
If (x) AND (y) Then Graphic Set Pixel (cx - x, cy - y), clr 'test not needed if Radius > 1
End Sub
'gbs_01287
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm