Difference between revisions of "image.rotate"

From Inspired-Lua Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ image.'''rotate''' is a function that is part of the image library. Returns a copy of the input image rotated counterclockwise by the amount of d...")
 
 
(4 intermediate revisions by the same user not shown)
Line 3: Line 3:
  
  
Returns a copy of the input image rotated counterclockwise by the amount of degrees given.
+
Returns a copy of the input image rotated counterclockwise by the amount of degrees given.<br />
 +
<br />
  
 
{{Since|3.2}}
 
{{Since|3.2}}
Line 21: Line 22:
  
 
== Example  ==
 
== Example  ==
<syntaxhighlight>local imw = earth:width()
+
<syntaxhighlight>local sc = 0.15
    local imh = earth:height()
+
local imw = earth:width()
    local im = earth:copy(sc*imw, sc*imh)
+
local imh = earth:height()
    im = im:rotate(-tilt)
+
local im = earth:copy(sc*imw, sc*imh)
    local midx = im:width()/2 -- this is the important bit for having the right coordinates
+
im = im:rotate(-tilt)
    local midy = im:height()/2
+
local midx = im:width()/2 -- this is the important bit for having the right coordinates
    local x = w/4 - midx
+
local midy = im:height()/2
    local y = h/2 - midy
+
local x = w/4 - midx
    gc:drawImage(im, x, y) -- we must be in a gc-passed function (like [[on.paint]](gc))
+
local y = h/2 - midy
    imw, imh = im:width(), im:height()</syntaxhighlight>
+
gc:drawImage(im, x, y) -- we must be in a gc-passed function (like on.paint(gc))
 +
imw, imh = im:width(), im:height()</syntaxhighlight>
  
 
== Good to know ==
 
== Good to know ==

Latest revision as of 21:30, 6 June 2012

image.rotate is a function that is part of the image library.


Returns a copy of the input image rotated counterclockwise by the amount of degrees given.

This has been introduced in TI-Nspire OS 3.2 (Changes).


Syntax

image.rotate(yourImage, angle) ( or yourImage:rotate(angle) )

Parameter Type Description
yourImage
TI.Image Image you want to rotate, created with image.new()
angle
number the angle in degrees you want to rotate your image by.

Example

local sc = 0.15
local imw = earth:width()
local imh = earth:height()
local im = earth:copy(sc*imw, sc*imh)
im = im:rotate(-tilt)
local midx = im:width()/2 -- this is the important bit for having the right coordinates
local midy = im:height()/2
local x = w/4 - midx
local y = h/2 - midy
gc:drawImage(im, x, y) -- we must be in a gc-passed function (like on.paint(gc))
imw, imh = im:width(), im:height()

Good to know

The image changes size when you rotate it. So you need to figure where to draw it based on the middle of its rotated size. By experimenting with it, you'll quickly notice that need ;)

See also