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 › PLEASE HELP!! URGENT!! Moving Curves with MouseX
Page Index Toggle Pages: 1
PLEASE HELP!! URGENT!! Moving Curves with MouseX (Read 969 times)
PLEASE HELP!! URGENT!! Moving Curves with MouseX
Apr 21st, 2010, 8:31am
 
Hi there,
I have an assessment due and I can't figure out how to move/reflect a curve using the MouseX function (I'm very amateur!)

What I'm trying to do is go from a smiley face to a frown face as I move the cursor from left to right.

for example going from this smiley face:


 size(700,400);
 smooth();
 background(255);
strokeWeight(5);
ellipse (350,150,200,200); // face
fill (0);
ellipse (320, 120, 15, 30); //left eye
ellipse (380, 120, 15, 30); //right eye

noFill(); // Smile
beginShape();
vertex(300, 180);
bezierVertex(310, 220, 390, 220, 400, 180);
endShape();

and then changing the smile to this in a smooth, continual motion (so the curve is bending as you move):

noFill(); // Smile
beginShape();
vertex(300, 180);
bezierVertex(310, 150, 390, 150, 400, 180);
endShape();



ANY suggestions would be hugely appreciated! Thank you!!
Re: PLEASE HELP!! URGENT!! Moving Curves with MouseX
Reply #1 - Apr 21st, 2010, 10:37am
 
ok, first of all you need a little clean up with your program format. When you are setting things up (like stroke color, background, size etc) you should put it in a a function called setup.

and when you want to draw things, you should put them in a function called draw.

what this does is it will keep running draw over and over again, which allows you to work with mouse input.

all i did was make the functions i mentioned, and put mouseY in for the Y position of your bezier. I assume you meant the Y axiz

X is across
Y is up and down


void setup(){
 size(700,400);
 smooth();
 background(255);
 strokeWeight(5);
}
void draw(){
 background(255);
 ellipse (350,150,200,200); // face
 fill (0);
 ellipse (320, 120, 15, 30); //left eye
 ellipse (380, 120, 15, 30); //right eye
 noFill(); // Smile
 beginShape();
 vertex(300, 180);
 bezierVertex(310, mouseY, 390, mouseY, 400, 180);
 endShape();
}

now, if you want to put limits on your mouth you can. Either by using a variable, or adding a scale to the mouse position.

Good luck
Re: PLEASE HELP!! URGENT!! Moving Curves with MouseX
Reply #2 - Apr 21st, 2010, 10:53am
 
Wow. Thank you SO very much. This was a giant help!
Re: PLEASE HELP!! URGENT!! Moving Curves with MouseX
Reply #3 - Apr 21st, 2010, 10:54am
 
Would you mind telling me how I use a vairable or add a scale to the mouse position? I'm so sorry!!
Re: PLEASE HELP!! URGENT!! Moving Curves with MouseX
Reply #4 - Apr 21st, 2010, 11:04am
 
you could change "mouseY" to something like "mouseY/4+100" (random numbers you'd have to mess with it)

or you can make a variable:

int a=mouseY //this declares a variable named a with a value of mouseY
bezierVertex(310, a, 390, a, 400, 180);//puts in mouseY where a is

you could then do some if statements. so if a>(whatever you want as a max) set a=(that max). and the same for a min

if(a<100){
a=100
}

if(a>200){
a=200
}

you can mess around with that until you get the right numbers
Re: PLEASE HELP!! URGENT!! Moving Curves with MouseX
Reply #5 - Apr 21st, 2010, 11:08am
 
Champion. Thank you eternally!
Re: PLEASE HELP!! URGENT!! Moving Curves with MouseX
Reply #6 - Apr 21st, 2010, 1:20pm
 
I'm so sorry to be a nuisance!!  I'm having quite a few problems... first of all my text isn't displaying.....secondly I have been playing around with numbers for ages and whilst I've got the happy face restricted, I can't get the sad face restricted!! Plus I have one eyebrow -I'm trying to add the other one:
float angle = map(mouseX-100, 0, width, 0, PI/-5);
translate(300, 90);
rotate(angle);
line(0, 0, 30, 0);

but it won't let me do that either. I must be formatting wrong again. Im so sorry to do this to you...

void setup(){
size(700,400);
smooth();
background(255);
strokeWeight(5);
PFont font;
font = loadFont ("Arial-Black-12.vlw");
textFont(font);
fill (0);
text("AFTER Processing entered my life...", 10,370);
text("... BEFORE Processing entered my life", 450,370);



}
void draw(){
background(255); //white background
fill(255,230,0); //yellow face colour
ellipse (350,150,200,200); // face
fill (0);
ellipse (320, 120, 15, 30); //left eye
ellipse (380, 120, 15, 30); //right eye
noFill(); // Smile
beginShape();
vertex(300, 190);
bezierVertex(310, mouseX/2-100, 390, mouseX/2-100, 400, 190);
endShape();
float angle = map(mouseX-100, 0, width, 0, PI/5);// Brow
translate(370, 90);
rotate(angle);
line(0, 0, 30, 0);
}
Re: PLEASE HELP!! URGENT!! Moving Curves with MouseX
Reply #7 - Apr 21st, 2010, 2:13pm
 
SORTED EVERYTHING OUT!! Thanks anyway!!!
Page Index Toggle Pages: 1