We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi, i’ve searched online but i couldn’t find anything good for me.
There’s a PImage which has to follow the coordinates of the mouse, without moving. This gif is pretty much what i’d like to do
look at help for command rotate
float angle; void setup() { size (600, 600); background(0); } void draw() { background(0); translate (333, 333); rotate(angle); rect(-20, -20, 40, 40); angle+=.07; }
to use mouse look at mouseX and use map() to map the value of mouseX to the angle you need (which is in radians)
mouseX
map()
see
https://processing.org/reference/map_.html
https://processing.org/reference/rotate_.html
https://processing.org/tutorials/transform2d/
I assume that you want the image to face the mouse position in which case you can calculate the rotation angle with
float angle = atan2(mouseY - imgY, mouseX - imgX);
Where imgX and `imgY' is the position of the centre of the image on the screen.
imgX
In draw() you can then use rotate(angle); followed by image(img, imgX, imgY); where img is the PImage you want to rotate.
draw()
rotate(angle);
image(img, imgX, imgY);
img
Answers
look at help for command rotate
to use mouse look at
mouseX
and usemap()
to map the value of mouseX to the angle you need (which is in radians)see
https://processing.org/reference/map_.html
https://processing.org/reference/rotate_.html
https://processing.org/tutorials/transform2d/
I assume that you want the image to face the mouse position in which case you can calculate the rotation angle with
float angle = atan2(mouseY - imgY, mouseX - imgX);
Where
imgX
and `imgY' is the position of the centre of the image on the screen.In
draw()
you can then userotate(angle);
followed byimage(img, imgX, imgY);
whereimg
is the PImage you want to rotate.