rotateImage ?

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Julu Julu
Posts: 9
Joined: Tue Nov 01, 2005 8:57 am
Location: Germany

rotateImage ?

Post by Julu Julu »

Hi.

I found this function here.

Code: Select all

function rotateImage(theImage) 
   newImage = Image.createEmpty(theImage:height(), theImage:width()) 
   for x = 1, theImage:width() do 
      for y = 1, theImage:height() do 
         newImage:blit(y, x, theImage, x, y, 1, 1) 
      end 
   end 
   return newImage 
end -- rotateImage

I do not understand this function.
The picture turns always 90 degrees.
How can I turn the picture differently?

For example 50 degrees.
Zenurb
Posts: 106
Joined: Fri Sep 30, 2005 8:33 am
Location: United Kingdom
Contact:

Re: rotateImage ?

Post by Zenurb »

Julu Julu wrote:Hi.

I found this function here.

Code: Select all

function rotateImage(theImage) 
   newImage = Image.createEmpty(theImage:height(), theImage:width()) 
   for x = 1, theImage:width() do 
      for y = 1, theImage:height() do 
         newImage:blit(y, x, theImage, x, y, 1, 1) 
      end 
   end 
   return newImage 
end -- rotateImage

I do not understand this function.
The picture turns always 90 degrees.
How can I turn the picture differently?

For example 50 degrees.
You can use sin/cos functions to work out the position of each new pixel.
Proud Dvorak User
US 1.5 PSP (Original)
Julu Julu
Posts: 9
Joined: Tue Nov 01, 2005 8:57 am
Location: Germany

Post by Julu Julu »

Where I must set sin/cos ?

Code: Select all


function rotateImage(theImage) 
   newImage = Image.createEmpty(theImage:height(), theImage:width()) 
   for x = 1, theImage:width() do 
      for y = 1, theImage:height() do 



         newImage:blit(   here -> ??? cos , here -> ??? sin   x, theImage, x, y, 1, 1) 
      end 
   end 
   return newImage 
end -- rotateImage
Zenurb
Posts: 106
Joined: Fri Sep 30, 2005 8:33 am
Location: United Kingdom
Contact:

Post by Zenurb »

sin and cos are mathematic functions which describe a wave pattern, sine and cosine. cosine is at a 90 degree angle to sine.

here is some code for making something move in a circle (i don't know lua very well)

Code: Select all

x = 130
y = 130
aimage = Image.createEmpty(100, 100)
aimage:print("lol")
while(true)
  screen.clear()
  a = a + 1
  x = x + (sin(a) * 10)
  y = y + (cos(a) * 10)
  screen:blit(x, y, aimage, 0, 0, 100, 100)
end
I think that works but probably not =)

the basic maths will work if you can fix it, to move something in a circle.

the radians value (a) goes from 0 to pi/2+pi (i think) pi=3.14152..etc and you can just divide the highest radian value by 360 then times by the angle you want to find the new position of a singular pixel.
Proud Dvorak User
US 1.5 PSP (Original)
Julu Julu
Posts: 9
Joined: Tue Nov 01, 2005 8:57 am
Location: Germany

Post by Julu Julu »

Thanks :)
Post Reply