Difference between revisions of "image.rotate"
Jump to navigation
Jump to search
Line 23: | Line 23: | ||
== Example == | == Example == | ||
<syntaxhighlight>local imw = earth:width() | <syntaxhighlight>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()</syntaxhighlight> | |
== Good to know == | == Good to know == |
Revision as of 21:19, 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 |
---|---|---|
TI.Image | Image you want to rotate, created with image.new() | |
number | the angle in degrees you want to rotate your image by. |
Example
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