We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › rotatable cursor
Page Index Toggle Pages: 1
rotatable cursor (Read 706 times)
rotatable cursor
Apr 10th, 2007, 10:31pm
 
I was wondering how one would go about making a cursor that rotated so as to look in the direction the mouse is moving.

I also have code here that is like an unfolding of the cursor() function, if it would be easier to add something in this form:


void setup() {
 size(400,400);
 background(174);
 noCursor();
};

void draw () {
   fill(174,174,174);
   stroke(174,174,174);
   ellipse(pmouseX,pmouseY, 30, 30);
//erases what was previously drawn
   fill(255,255,0);
   stroke(0,0,0);
   arc(mouseX,mouseY, 20, 20, PI, PI/2);
//draws the image for the cursor where the mouse is
 
 
};
Re: rotatable cursor
Reply #1 - Apr 11th, 2007, 12:34am
 
What you are looking for is ATAN.  This example will get you close:

http://processing.org/reference/atan2_.html
Re: rotatable cursor
Reply #2 - Apr 11th, 2007, 3:25am
 
Thanks. after playing around some, I figured it out. It isn't perfect but this is the code:


void setup() {
 size(400,400);
 background(174);
};
void draw () {
 if(mousePressed) {
   delay(10);
   translate(mouseX, mouseY);
   fill(174,174,174);
   stroke(174,174,174);
   ellipse(mouseX-pmouseX,mouseY-pmouseY, 80, 80);
//to erase previous

   fill(255,255,0);
   stroke(0,0,0);
   float a = atan2(mouseY-pmouseY, mouseX-pmouseX);
   rotate(a + 9*PI/8);
//determines how much to rotate
   arc(0,0, 20, 20, PI, PI/2);
//draws pac-man
   noCursor();
 };
 
};
//when mouse is let go switch back

void mouseReleased () {
   fill(174,174,174);
   stroke(174,174,174);
   arc(mouseX-pmouseX,mouseY-pmouseY, 30, 30, PI, PI/2);
   cursor(ARROW);
 };
Page Index Toggle Pages: 1