PDA

View Full Version : Bitmap Rotation



peter
18-10-2012, 18:02
Hi,


Uses "ui","math"


DWord hdc,hwin
hwin=Canvas_Window("Rotation",1,1,640,480)
Canvas_Attach(hwin,0,%TRUE)
Canvas_Font("arial",16,%CANVAS_FONTSTYLE_BOLD)


Type TPoint
x As Single
y As Single
End Type


Dim point As TPoint
Dim pepper(4096) As Long


Long x,y,z,col
Single a


Canvas_BitmapRender("renold.bmp",0,0,64,64)
For x=1 To 63
For y=1 To 63
z=y*64+x
pepper(z)=Canvas_Pixel(x,y)
Next
Next
Canvas_Clear(0)


While IsWindow(hwin)
Canvas_BitmapRender("easter.bmp",0,0)
For x=1 To 63
For y=1 To 63
z=y*64+x
RotateBitmap(x,y,a)
col=pepper(z)
If col >0 Then
Canvas_SetPixel 300+point.x,224+point.y *.2,col
Canvas_SetPixel 100+point.x,224+point.y *.6,col
Canvas_SetPixel 500+point.x*.4,224+point.y *.8,col
End If
Next
Next


Canvas_Redraw
a += .09
If a>=360 Then a=-360


If GetAsyncKeyState(27) Then Exit While
Wend
Canvas_Window End


Sub SetText(x,y As Long, txt As String, xkol,ykol As Long)
Canvas_Color(xkol,ykol)
Canvas_SetPos(x,y)
Canvas_Print(txt)
End Sub


Sub RotateBitmap(x,y As Long,av As Single)
Local x0,y0 As Single
Local x1,y1 As Long
x1=64 /2
y1=64 /2
x0=(x-x1)*Cos(a)-(y-y1)*Sin(a)
y0=(x-x1)*Sin(a)+(y-y1)*Cos(a)
point.x=x0
point.y=y0
End Sub