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 & HelpSyntax Questions › Helped with mouseMoved please!
Page Index Toggle Pages: 1
Helped with mouseMoved please! (Read 1149 times)
Helped with mouseMoved please!
Nov 12th, 2009, 12:49pm
 
Hey guys,
I am in need of a little more assistance as I have been experimenting with codes in all different manners for the last few hours and I can't get my pupil of the monster to move with the mouse within the sclera. I am aware of the mouseMoved function on the processing website but the program says there is no such phrase. I have also tried to assign variables to the pupil and there is no luck there. Please be aware that I am trying to learn and am not trying to mooch off other's coding experience. Here is a copy of my coding as to what I have so far.

void setup() {
 size(600, 600);//This is the size of the box holding the monster
 smooth();
}

void draw() {
background(225, 225, 225);//This makes the background white//
monster();//This sets up the coding for what is considered the monster
mouth();//This sets up the coding for when the mouth needs to be mouse reactive
eye(width, height);
}

void monster (){
 
fill(0);
stroke(0);
ellipse(300, 300, 300, 300);//This is the black circle body of the monster//

fill(0);
stroke(0);
triangle(190, 200, 250, 200, 220, 90);//Monster ear left//

fill(0);
stroke(0);
triangle(350, 200, 410, 200, 380, 90);//Monster ear right//

fill(225);
stroke(225);
ellipse(300, 250, 50, 75);//This is the sclera of the monster eye//

fill(0);
stroke(0);
ellipse(300, 275, 20, 20);//This is the pupil of the monster eye//

fill(225);
stroke(225);
triangle(280, 300, 320, 300, 300, 320);//This is the nose of the monster//

fill(225);
stroke(225);
line(310, 310, 350, 310);//Right Whisker pointing straight//
fill(225);
stroke(225);
line(310, 310, 340, 340);//Right Whisker pointing down//
fill(225);
stroke(225);
line(310, 310, 360, 330);//Right Whisker in-between//
fill(225);
stroke(225);
line(290, 310, 250, 310);//Left Whisker pointing straight//
fill(225);
stroke(225);
line(290, 310, 260, 340);//Left Whisker pointing down//
fill(225);
stroke(225);
line(290, 310, 240, 330);//Left Whisker in-between//

fill(0);
stroke(0);
ellipse(300, 500, 100, 150);//Monster body//

fill(225);
stroke(225);
ellipse(330, 475, 20, 20);//Monster paw right//
fill(225);
stroke(225);
ellipse(270, 475, 20, 20);//Monster paw left//

fill(0);
stroke(0);
rect(330, 550, 60, 10);//Monster tail//

fill(0);
stroke(0);
ellipse(390, 550, 30, 30);//Monster tail end//
}

void mouth(){
if(mousePressed == true && dist(300, 375, mouseX, mouseY)<30){//When the mouse is pressed the monster mouth will close and "eat the mouse"//
fill(225);
stroke(225);
noCursor();
ellipse(300, 375, 70, 1);//Mouth closed//
}
 else{//When the mouse is released the monster mouth opens again for more food//
cursor(ARROW);
fill(225);
stroke(225);
ellipse(300, 375, 70, 70);//Mouth opened//
 }
}

void eye(int x, int y){
if(mouseMoved == true);
int pX = (int) map(mouseX, 0, width, -50, 50); //allows the pupil to follow the mouse
int pY = (int) map(mouseY, 0, height, -50, 50); //allows the pupil to follow the mouse
noCursor();
}
 else{
cursor(ARROW);
fill(225);
stroke(225);
ellipse(x, y, 300, 250);//This is the sclera of the monster eye//

fill(0);
stroke(0);
ellipse(x, y, 300, 275);//This is the pupil of the monster eye//
 }
}
Re: Helped with mouseMoved please!
Reply #1 - Nov 12th, 2009, 2:12pm
 
Look again at the reference page.
You can see that mousePressed can be either a variable or a function.
But mouseMoved is only a function, which is called when the mouse moves. You cannot use it as a variable.
You can just use the mouseX information. Or if you need to detect movement, check mouseX against pmouseX (previous value) and see if it has changed.
Re: Helped with mouseMoved please!
Reply #2 - Nov 12th, 2009, 2:29pm
 
maybe you can team up Smiley

http://processing.org/discourse/yabb2/num_1257996280.html#3

create one huge monster... or at least take a look at his code.
Re: Helped with mouseMoved please!
Reply #3 - Nov 12th, 2009, 8:14pm
 
haha yeah he is actually my friend
but yeah i tried to use his code with no avail and i looked at the reference page and since im new to this whole thing it is hard for me to comprehend how to make this work for my specific code. i have been working on this for hours so i dont mean to come off like i am not looking up things and just asking for help, it is just hard for me to understand.
Re: Helped with mouseMoved please!
Reply #4 - Nov 12th, 2009, 10:06pm
 
His code is not really long. try to find out what part is responsible for the eye movement. Try to remove everything that is not needed. Then copy the code that is left to your sketch. if that is working, try do adjust it by changing the position of the eye and make a second one. As they eyes is following the mouse, you can at least assume that one of the important lines has mouseX,mouseY in it.
Re: Helped with mouseMoved please!
Reply #5 - Nov 13th, 2009, 10:17am
 
Thank you =D
I for the pupil to move within the sclera so that was a bit of an accomplishment but now the rest of my monster doesn't show...it just has the eye..?
Re: Helped with mouseMoved please!
Reply #6 - Nov 13th, 2009, 11:05am
 
Okay I think i might know why the monster doesnt show up and I also want to know the reason for this coding...

in order to get the eye to work (as in scoota's post) under void draw it needs to be like this

void draw() {
background(225, 225, 225);//This makes the background white//
monster();//This sets up the coding for what is considered the monster
mouth();//This sets up the coding for when the mouth needs to be mouse reactive
eye(width/2, height/2);
}

When I try to make eye like the monster and mouth with nothing within the parenthesis it does not work and when I don't put any number after the / the eye is completely off center and does not show the monster body...

what is the reason for putting (width/2, height/2) and how do i fix it so my monster shows....this is my current coding with the eye following the mouse but does not show the monster for some reason

void setup() {
 size(600, 600);//This is the size of the box holding the monster
 smooth();
}

void draw() {
background(225, 225, 225);//This makes the background white//
monster();//This sets up the coding for what is considered the monster
mouth();//This sets up the coding for when the mouth needs to be mouse reactive
eye(width/2, height/2);
}

void monster (){
 
fill(0);
stroke(0);
ellipse(300, 300, 300, 300);//This is the black circle body of the monster//

fill(0);
stroke(0);
triangle(190, 200, 250, 200, 220, 90);//Monster ear left//

fill(0);
stroke(0);
triangle(350, 200, 410, 200, 380, 90);//Monster ear right//

fill(225);
stroke(225);
ellipse(300, 250, 50, 75);//This is the sclera of the monster eye//

fill(0);
stroke(0);
ellipse(300, 275, 20, 20);//This is the pupil of the monster eye//

fill(225);
stroke(225);
triangle(280, 300, 320, 300, 300, 320);//This is the nose of the monster//

fill(225);
stroke(225);
line(310, 310, 350, 310);//Right Whisker pointing straight//
fill(225);
stroke(225);
line(310, 310, 340, 340);//Right Whisker pointing down//
fill(225);
stroke(225);
line(310, 310, 360, 330);//Right Whisker in-between//
fill(225);
stroke(225);
line(290, 310, 250, 310);//Left Whisker pointing straight//
fill(225);
stroke(225);
line(290, 310, 260, 340);//Left Whisker pointing down//
fill(225);
stroke(225);
line(290, 310, 240, 330);//Left Whisker in-between//

fill(0);
stroke(0);
ellipse(300, 500, 100, 150);//Monster body//

fill(225);
stroke(225);
ellipse(330, 475, 20, 20);//Monster paw right//
fill(225);
stroke(225);
ellipse(270, 475, 20, 20);//Monster paw left//

fill(0);
stroke(0);
rect(330, 550, 60, 10);//Monster tail//

fill(0);
stroke(0);
ellipse(390, 550, 30, 30);//Monster tail end//
}

void mouth(){
if(mousePressed == true && dist(300, 375, mouseX, mouseY)<30){//When the mouse is pressed the monster mouth will close and "eat the mouse"//
fill(225);
stroke(225);
noCursor();
ellipse(300, 375, 70, 1);//Mouth closed//
}
 else{//When the mouse is released the monster mouth opens again for more food//
cursor(ARROW);
fill(225);
stroke(225);
ellipse(300, 375, 70, 70);//Mouth opened//
 }
}

void eye(int x, int y) {
background(225);

fill(225);
stroke(225);
ellipse(300, 250, 50, 75);//This is the sclera of the monster eye//


int pX = (int) map(mouseX, 0, width, -10, 10); //allows the pupil to follow the mouse
int pY = (int) map(mouseY, 0, height, -60, -25); //allows the pupil to follow the mouse

fill(0);
ellipse(x + pX, y + pY, 20, 20); //this is the pupil

}
Re: Helped with mouseMoved please!
Reply #7 - Nov 13th, 2009, 1:12pm
 
prister wrote on Nov 13th, 2009, 11:05am:
When I try to make eye like the monster and mouth with nothing within the parenthesis it does not work and when I don't put any number after the / the eye is completely off center and does not show the monster body...

what is the reason for putting (width/2, height/2)

The stuff between the parentheses are called "parameters".
In the eye call, it defines the variables x and y, which are used as base of the position of the pupil.
The width/2 and height/2 are common idiom to compute the center (half width and half height) of the sketch's area.

Quote:
and how do i fix it so my monster shows....this is my current coding with the eye following the mouse but does not show the monster for some reason

The background() call at the start of eye just erase everything on the sketch, including the stuff drawn by the monster() and mouth() calls.
Also note: you can remove all fill() and stroke() calls that are identical to the preceding one: these values persist until they are changed.
Re: Helped with mouseMoved please!
Reply #8 - Nov 13th, 2009, 2:26pm
 
Goodness THANK YOU SO MUCH.
Page Index Toggle Pages: 1