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 › beginer question
Page Index Toggle Pages: 1
beginer question (Read 885 times)
beginer question
Aug 30th, 2007, 12:32pm
 
Hello,

I m a beginner in processing and i ve question about two programs and their color.

The first progams is "storing input" in the learning:
How can i make the circle change color from the x position?
i try the colormode and the fill but the color is static and dont change with the position of the mouse.

The seconde program is in "miliseconde" in learning:
How can i do the same with color? i would like to do the same but replace black and white by rgb.

thank you very much,i hope you can help me.
Re: beginer question
Reply #1 - Aug 30th, 2007, 5:21pm
 
put this in front of the ellipse function in the "storing input" example
fill(color((mouseX/width)*255));
that gives you black on the left side, and white on the right side..

To explain:
mouseX is a value between 0 and width, (unless it is outside, but then you'll have to click and drag)
dividing mouseX by width, gives you a decimal value between 0 and 1, multiplying this with 255, (which is the max value for the color function) gives you a value between 0 and 255, which is black and white..

good luck Smiley

Try playing with other numbers, and minus, plus, multiply etc to see something change.. should give you some ideas on what should be changed, and what shouldn't.

Also.. colorMode is for setting RGB, or HSB, which is different ways to use a color.
Re: beginer question
Reply #2 - Aug 30th, 2007, 6:08pm
 
Thank you very much!
i do that you tell me but i ve to clik on the mouse to execute the action, i dont know if it is true?

i would like to do the thing that beyes do on this website

http://210.188.206.96/editwall/

i try but not succed...
maybe you have the solution?

thanks
Re: beginer question
Reply #3 - Sep 14th, 2007, 3:34pm
 
try by modifying this...



void setup()
{
 size(200, 200);
 background(0);
 smooth();
 colorMode(RGB,255,255,255,100);
}

void draw()
{
 // Call the variableEllipse() method and send it the
 // parameters for the current mouse position
 // and the previous mouse position
 variableEllipse(mouseX, mouseY, pmouseX, pmouseY);
}


// The simple method variableEllipse() was created specifically
// for this program. It calculates the speed of the mouse
// and draws a small ellipse if the mouse is moving slowly
// and draws a large ellipse if the mouse is moving quickly

void variableEllipse(int x, int y, int px, int py)
{
 float speed = abs(x-px) + abs(y-py);
 stroke(speed);
 fill(speed*15,speed*3,255,100);
 ellipse(x, y, speed, speed);
}

Page Index Toggle Pages: 1