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 › Changing size and color.
Page Index Toggle Pages: 1
Changing size and color. (Read 933 times)
Changing size and color.
Nov 11th, 2009, 7:24pm
 
Hi all,

I'm working on a simple program.  It is an eye.  I got the pupil to follow the mouse, which wasn't too hard, but I want it to get bigger and also for the iris to get darker with a mouse click.  With today being my first foray into processing, any help would be much obliged.

Here's my code:

void setup() {
size(500, 500); //sets the size of the background

background(255); //sets the background color to white
smooth();
}

void draw() {
eye(width/2, height/2);
}

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

noStroke();
fill(0);
ellipse(x, y, 300, 150); //this is the sclera (black part of the eye)

fill(255);
ellipse(x, y, 100, 100); //this is the iris

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

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

}
Re: Changing size and color.
Reply #1 - Nov 11th, 2009, 7:43pm
 
create 2 variables, that add 1 whenever the mouse is clicked
and use them for the size of the ellipse and the other one for the color of the iris/eyeball.

use http://processing.org/reference/constrain_.html to keep it witin your value range.
Re: Changing size and color.
Reply #2 - Nov 12th, 2009, 10:25am
 
I can't get it to work.  I don't know how to change color or size.

I have if(mousePressed == true and thats about it.
Re: Changing size and color.
Reply #3 - Nov 12th, 2009, 11:15am
 
i actually dont know what to explain further...
create 2 variables... for example. int gray = 255;
int size = 10;
now use these to set the color and the size.
if that is working use your mousePressed() to set the size and gray variabe to another value like this size = 20;
so everytime the mouse is pressed. the size is 20 not 10...

Try to implement it, and if it is still not working post the whole code.


Re: Changing size and color.
Reply #4 - Nov 13th, 2009, 10:43am
 
Ok, so i got it to change size, but is there a way to do it gradually?

if (mousePressed == true)  {
fill(0);
ellipse(x + pX, y + pY, 30, 30);
 triangle(x+150,y,x+100,y,x+75,y-200); //right ear
 triangle(x-150,y,x-100,y,x-75,y-200); //left ear
} else  {
fill(0);
ellipse(x + pX, y + pY, 10, 10);
 triangle(x+150,y,x+100,y,x+75,y-200); //right ear
 triangle(x-150,y,x-100,y,x-75,y-200); //left ear
}
}
Re: Changing size and color.
Reply #5 - Nov 13th, 2009, 2:51pm
 
you dont have to make it that complicated.
like i said. define a variable.
and use it like this

ellipse(x,y,size,size)
now change the size when the mouse is pressed.
you can either say, size is 40, else its 20.
or you can say, everytime the mouse is pressed. size = size +1;
that scales it everytime the mouse is pressed.
Page Index Toggle Pages: 1