Hi Paul,
I found some old code you wrote to rotate an image. It was short and sweet which is why I am bit embarassed that I cannot convert it for my needs. Your code is below. I basically need to rotate a portion of an image within a larger image.
The total image is just an rgbtriple that is 320x240. I want to rotate a box in the center of that image around its own center within the larger image. This box is 176 pixels on each side. Its upper left coordinate is then 44,16 and its lower right is 220,192.
I am trying to understand how you picked your constants and after trying several variations I thought I would just ask if you had any suggestions.
I found some old code you wrote to rotate an image. It was short and sweet which is why I am bit embarassed that I cannot convert it for my needs. Your code is below. I basically need to rotate a portion of an image within a larger image.
The total image is just an rgbtriple that is 320x240. I want to rotate a box in the center of that image around its own center within the larger image. This box is 176 pixels on each side. Its upper left coordinate is then 44,16 and its lower right is 220,192.
I am trying to understand how you picked your constants and after trying several variations I thought I would just ask if you had any suggestions.
Code:
#COMPILE EXE #DIM ALL %xWindowSize = 480 %yWindowSize = 480 %xRotateOffset=140 %yRotateOffset=140 FUNCTION PBMAIN () AS LONG LOCAL hInitialBMP,hWindow, hThread AS DWORD LOCAL InitialBMPstring, RotatedBMPstring AS STRING LOCAL x,y,a,xSize,ySize,t1,t2, Oldx,Oldy, QuitAll, lResult AS LONG LOCAL Angle,sina, cosa AS EXT LOCAL file AS STRING LOCAL initial(), rotated() AS LONG file$="rose.bmp" x = FREEFILE OPEN file$ FOR BINARY AS x GET #x, 19, xSize GET #x, 23, ySize CLOSE x GRAPHIC WINDOW "Rotation test",200,200, %xWindowSize,%yWindowSize TO hWindow GRAPHIC ATTACH hWindow,0 GRAPHIC GET BITS TO RotatedBMPstring GRAPHIC DETACH GRAPHIC BITMAP LOAD file$, xSize&, ySize& TO hInitialBMP GRAPHIC ATTACH hInitialBMP,0 GRAPHIC GET BITS TO InitialBMPstring GRAPHIC DETACH THREAD CREATE RedrawGraphics (hWindow) TO hThread DIM initial&(1 TO xSize&,1 TO ySize&) AT STRPTR(InitialBMPstring)+8 DIM rotated&(1 TO %xWindowSize,1 TO %yWindowSize) AT STRPTR(RotatedBMPstring)+8 LOCAL tc, ts AS EXT t1&=TIMER*100 DO FOR a& = 0 TO 360 'degrees angle##=a&/(180/3.141592653589) cosa=COS(angle##) sina=SIN(angle##) FOR x&=1 TO %xWindowSize tc = (x& - %xRotateOffset) *cosa + %xRotateOffset -40 ts = -(x& - %xRotateOffset)*sina + %yRotateOffset -70 FOR y& = 1 TO %yWindowSize oldx& =tc + (y& - %yRotateOffset)*sina oldy& =(y& - %yRotateOffset) *cosa + ts IF oldx&>0 AND oldx& < xSize& AND oldy&>0 AND oldy&< ySize& THEN Rotated&(x&,y&) = Initial&(oldx& ,oldy&) ELSE Rotated&(x&,y&) = %WHITE END IF NEXT NEXT SLEEP 500 GRAPHIC ATTACH hWindow,0 ,REDRAW GRAPHIC SET BITS RotatedBMPstring GRAPHIC DETACH SLEEP 0 NEXT LOOP t2&=TIMER*100 'PRINT "Time Taken = "(t2&-t1&)/100 'PRINT "Frames per second ="; 360/((t2&-t1&)/100 ) QuitAll& =1 THREAD CLOSE hThread TO lResult MSGBOX "dfg" END FUNCTION 'This is a flag intended to cause all otherwise non-terminating threads to quit GLOBAL QuitAll& 'This routine and the main program must use GRAPHIC ATTACH WindowID,0,REDRAW but the main program shouldn't 'issue a GRAPHIC REDRAW command in normal use. Leave that up to this thread. FUNCTION RedrawGraphics(BYVAL WinID AS DWORD) AS DWORD GRAPHIC ATTACH WinID,0,REDRAW DO GRAPHIC REDRAW SLEEP 1 LOOP UNTIL QuitAll& END FUNCTION
Comment