Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Button
IDC_Graphic
IDC_Label
End Enum
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,300,250,250, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Push", 10,10,100,20
Control Add Label, hDlg, %IDC_Label,"",120,10,100,20, %WS_Border
Control Add Graphic, hDlg, %IDC_Graphic, "", 10,50,150,150, %WS_Border
Graphic Attach hDlg, %IDC_Graphic
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
Local i,Ang As Long, x,y As Single
X = 50 : Y = 0
For i = 1 To 220
RotateAboutZAxis x,y, 0.03
Graphic Set Pixel (x+75,y+75)
Ang = Atn(y/x) * 180 / 3.14159
If x < 0 Then
Ang = Ang + 180
ElseIf y < 0 Then
Ang = Ang + 360
End If
Control Set Text hDlg, %IDC_Label, Format$(ang,"0.0")
Sleep 50
Next i
End Select
End Select
End Function
Sub RotateAboutZAxis(X As Single, Y As Single, Ang As Single)
Local i As Long, NewX, NewY As Single
NewX = X * Cos(Ang) - Y * Sin(Ang) 'Z rotation
NewY = X * Sin(Ang) + Y * Cos(Ang) 'Z rotation
X = NewX : Y = NewY
End Sub
'gbs_01295
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm