;XIncludeFile "E:\pbi\getAngle.pbi" ;{ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\ E:\pbi\getAngle.pbi ; getAngle.pbi Procedure.f getAngle(mx,my, px,py, mode.l=1) ; returns the angle of a line going from point ; [mx,my] to point [px,py] in radian ; mode=1 (default): ; pointing to the right means 0 degrees ; pointing to the top means 90 degrees, ect ; [math y-axis] ; mode=-1: ; pointing to the right means 0 degrees ; pointing to the bottom means 90 degrees, ect ; [screen y-axis.] Static xd.l, yd.l, alpha.f xd=px-mx yd=py-my If xd>0 If yd<0 :: alpha= ATan(-yd / xd ) ElseIf yd>=0 :: alpha= 2*#PI - ATan( yd / xd ) EndIf ElseIf xd<0 If yd<0 :: alpha= #PI - ATan(-yd /-xd ) ElseIf yd>=0 :: alpha= #PI + ATan( yd /-xd ) EndIf ElseIf xd=0 If yd>0 : alpha= #PI*1.5 ElseIf yd<0 : alpha= #PI*0.5 EndIf EndIf If mode=-1 alpha = 2*#PI-alpha EndIf ; If Not Random(200) ; Debug Str(xd) + " | " + Str(yd) + " | " + StrF(alpha) ; EndIf ProcedureReturn alpha EndProcedure ; [...] ;} ; ________________________________/ [end] E:\pbi\getAngle.pbi Procedure rotateSprite(spr,aspr.d) Static xmax,ymax, x,y Static a.d, d.d Static i.l, k.l xmax=SpriteWidth(spr)-1 ymax=SpriteHeight(spr)-1 Dim p.l(xmax,ymax) StartDrawing(SpriteOutput(spr)) For i=0 To xmax For k=0 To ymax a=getangle(xmax/2,ymax/2,i,k,-1)-aspr d=Sqr( (i-xmax/2)*(i-xmax/2) + (k-ymax/2)*(k-ymax/2) ) x=xmax/2 + d*Cos(a) y=ymax/2 + d*Sin(a) If x>=0 And y>=0 And x<=xmax And y<=ymax p(i,k)=Point(x,y) EndIf Next Next For i=0 To xmax For k=0 To ymax Plot(i,k,p(i,k)) Next Next StopDrawing() EndProcedure ; InitSprite() ; ww=1100 ; wh=800 ; style | #PB_Window_ScreenCentered ; style | #PB_Window_SystemMenu ; style | #PB_Window_MinimizeGadget ; hWin=OpenWindow(0, 50,100,ww,wh, "",style) ; AddKeyboardShortcut(0,#PB_Shortcut_Escape,10) ; AddKeyboardShortcut(0,#PB_Shortcut_R,11) ; OpenWindowedScreen( hWin, 0,0,ww,wh, 0,0,0) ; ; ; ;LoadSprite(0,"E:\mo.bmp") ; UseJPEGImageDecoder() ; LoadSprite(0,"E:\GUCK\fractal-dd.jpg") ; CopySprite(0,1) ; ; ; Repeat ; event=WaitWindowEvent(80) ; em=EventMenu() ; Select event ; Case #PB_Event_CloseWindow ; quit=1 ; Case #PB_Event_Menu ; Select em ; Case 10 ; quit=1 ; Case 11 ; EndSelect ; EndSelect ; CopySprite(0,1) ; rotateSprite(1,getangle(0,0,WindowMouseX(0)-ww/2,WindowMouseY(0)-wh/2,-1)) ; DisplaySprite( 1, (ww-SpriteWidth(1))/2,(wh-SpriteHeight(1))/2 ) ; FlipBuffers() ; ClearScreen($333333) ; Until quit ; IDE Options = PureBasic 4.20 Beta 3 (Windows - x86) ; CursorPosition = 16 ; Folding = - ; HideErrorLog ; CompileSourceDirectory