I have a sprite that I need to rotate 90 degrees. I know about the math.random function, but how would I use that to make a sprite rotate by 90 degrees?
@bfisher Check the reference for translate and rotate.
function setup()
end
function draw()
background(40, 40, 50)
translate(300,300)
rotate(90)
sprite("Planet Cute:Character Horn Girl",0,0)
end
Short, to give you understanding this code: the basic of x and y is 0 so if you will draw a line with line(x, y, x2, y2)
it will draw an line from x,y to x2,y2 but if you set translate(newX, newY)
, the usuall line will be like (x+newX, y+newY, ...)
So the rotate()
tag will rotate all the tags after rotate against the clock. In the brackets I would prefer to use instead 90
to use ElapsedTime * 90
because its better I think. The background is also needed because if you want that the sprite don’t has to paste allways a new picture and new… Just do background
@bfisher - Codea rotates around (0,0), so you need to translate to the centre of your sprite before using rotate
Is there a way you can stop the translation so only one drawing is translated and rotated and then the following drawings are not?
Use pushMatrix and popMatrix.
function setup()
r=0
end
function draw()
background(40, 40, 50)
pushMatrix()
translate(300,300)
rotate(r)
sprite("Planet Cute:Character Boy",0,0)
popMatrix()
r=r+1
sprite("Planet Cute:Character Cat Girl",100,100)
end