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 › question about random color!
Page Index Toggle Pages: 1
question about random color! (Read 522 times)
question about random color!
May 10th, 2009, 3:15pm
 
Hey guys! im new in this forum, and im new into programming.
i started today and after playing a little with the drawing tools i started programing random appearing of ellipses and stuff and then i wanted to make a random color change to every ellipse and i got to this code
import processing.video.*;
MovieMaker mm;



//------ random color -----
float hUE = random(50, 280)/5;
float sAT = random(50,100);
float bRT= random(40,80);

float Rincrement = hUE;
float Gincrement = sAT;
float Bincrement = bRT;

//---- random position
float xoff = random(20, 255);
float yoff = random(10, 255);
float aoff = random(1, 255);
float boff = random(10, 255);
float xincrement = yoff*2000;
float yincrement = xoff*2000;
//---- ----- ------- ------


void setup(){
 size(720,576);
  colorMode(HSB);
  mm = new MovieMaker(this, width, height, "randomcores7.mov",
                      30);  
 background(255);
 smooth();
 

 
}
void draw(){

 fill(hUE,sAT,bRT,90);
   noStroke();
     mm.addFrame();
 



 float a = random(10,100);
 float b = random(100,500);

 float d = noise(xoff,yoff)*1000;    
 float e = noise(yoff,xoff)*800;
   ellipse(d,e, a,a);


 xoff += xincrement;
 yoff+= yincrement;
 hUE += Rincrement/5;
 sAT += Gincrement*2;
 bRT += Bincrement*2;

 

}

void keyPressed() {
 if (key == ' ') {
   mm.finish();  // Finish the movie if space bar is pressed!
 }
}
which i found that it doesn't work that bad, but instead of going completly random, i get kind of random but going towards red.... so i fugure i would divide the float .... but i can't get it to not stay in red once it gets there...

sorry if my english isn't that good and don't mind the names like hUE or Rincrement ( it was because i was working with rgb before, and it was an increment in red.... :s)

if somebody could help me it would be great Cheesy thanks in advanced
Re: question about random color!
Reply #1 - May 10th, 2009, 3:38pm
 
there are some things messed up.
First you have all your random stuff at the beginning. That doesnt work, cause its only called once. So you only get one random color you start with. From then on you just count it up until it reaches red(360) and stays red. Same with your positions.

As long as you only want some random colors. You dont need the noise and "increments" just use some random in your draw method :




void setup(){
size(720,576);
 colorMode(HSB,360,100,100);
background(360);
smooth();
}
void draw(){
float hUE = random(0, 360);
float sAT = random(50,100);
float bRT= random(50,100);

fill(hUE,sAT,bRT,190);
  noStroke();
float a = random(10,100);
float d = random(width);    
float e = random(height);
 ellipse(d,e, a,a);
}
Re: question about random color!
Reply #2 - May 10th, 2009, 3:44pm
 
thanks a lot! like i said, i just started learning today and never programmed nothing before, so im going through trial and lots of errors...
Re: question about random color!
Reply #3 - May 10th, 2009, 3:51pm
 
thats how you learn it Smiley Good luck and come back for more questions...
Page Index Toggle Pages: 1