### Author Topic: Rotate an image  (Read 713 times)

#### unatic

• God looks after small children and old fools!
##### Rotate an image
« on: June 16, 2018, 06:41:08 PM »
Using the sample program,  I have been able to flip an image in both directions, but I am unable to figure out how to rotate the image by 90 degrees.  I am using the _PUTIMAGE but have not been able to figure this out.  Any help would be appreciated.
I'm the one that has to die when it's time for me to die, so let me live my life, the way I want to.

Jimi Hendrix

#### Ashish

• The joy of coding is endless.
##### Re: Rotate an image
« Reply #1 on: June 17, 2018, 12:21:37 AM »
Hi unatic!
See Example #1 of this page - http://qb64.org/wiki/MAPTRIANGLE
if (Me.success) {Me.improve()} else {Me.tryAgain()}

My Projects - https://github.com/AshishKingdom?tab=repositories

#### bplus

##### Re: Rotate an image
« Reply #2 on: June 17, 2018, 11:10:31 AM »
Here is my test code for RotoZoom2 with independent scales for X and Y:
« Last Edit: June 17, 2018, 11:20:38 AM by bplus »
B = B + ...

#### Petr

• The best code is the DNA of the hops.
##### Re: Rotate an image
« Reply #3 on: June 17, 2018, 01:06:46 PM »
Good work Bplus, so now just add background shift in Y axis and enemies and game is done :-D

#### bplus

##### Re: Rotate an image
« Reply #4 on: June 17, 2018, 02:54:39 PM »
To make the sub even easier to use I have written up some notes for it:
Code: QB64 [Select]
1. 'notes: X, Y is the place where you want the center of the image to go
2. ' image is the image handle number
3. ' xScale and yScale: if you want the image the same size as file image use 1, half the size use .5
4. ' twice the size use 2... this allows you to stretch/shrink an image into a rectangle area any size
5. ' Rotation is an angle in Degrees units: 0 degrees is due East (as file image) 270 degrees is due North....
6. SUB RotoZoom2 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale AS SINGLE, Rotation AS SINGLE)
7.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
8.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
9.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
10.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
11.     sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
12.     FOR i& = 0 TO 3
13.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * xScale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * yScale + Y
14.         px(i&) = x2&: py(i&) = y2&
15.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
16.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
17.

EDIT: forgot to make yScale as Single
« Last Edit: June 17, 2018, 02:59:40 PM by bplus »
B = B + ...

#### unatic

• God looks after small children and old fools!
##### Re: Rotate an image
« Reply #5 on: June 17, 2018, 08:37:27 PM »
Thanks for the information and pointers!  I just did not look deep enough at the image functions in QB64.  I will study these samples and after I understand them, I will incorporate the functionality into my program.  Again, thank you!!
I'm the one that has to die when it's time for me to die, so let me live my life, the way I want to.

Jimi Hendrix

#### bplus

##### Re: Rotate an image
« Reply #6 on: June 18, 2018, 09:10:05 AM »
Ha, yeah, I remember the first time I looked at RotoZoom sub... yikes! a head scratcher until you realize it draws a rectangular image by drawing two triangles: 2 edges and the diagonal, then the other 2 edges and same diagonal. To do that, it calculates the (x, y) points at corners for the triangles at drawing surface. The mapping then takes all points in triangle of image and translates them to triangle on drawing surface.
B = B + ...