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 › Random circles movement & generating
Page Index Toggle Pages: 1
Random circles movement & generating (Read 493 times)
Random circles movement & generating
Apr 12th, 2008, 1:45pm
 
here i have the code for the program...i want to genereate random circle with diffent color and move them across screen randomly...i just can't break thru with logic....
i m trying my best to do it myself but really cracking my mind....

float r = random(50);
void setup()
{
 size(550,400);
 background(#FFFFFF);
fill(0, 102, 153, 204);
smooth();
noLoop();
}

void draw() {
 circles(40, 80);
 circles(90, 70);
}

void circles(int x, int y) {
 ellipse(x, y, 50, 50);
 ellipse(x*r,y*r,100,120);
}


please let me know if this can be done...addyour suggestion to baove code...

thanks in advance...
Re: Random circles movement & generating
Reply #1 - Apr 12th, 2008, 1:54pm
 
Have a look at this example from the Learning section :
http://processing.org/learning/topics/bouncybubbles.html

The main logic is here : declaring an array of objects (circles) or coordinates ; filling this array in setup() ; iterate the array and move each object in draw().
Re: Random circles movement & generating
Reply #2 - Apr 12th, 2008, 11:18pm
 
if you want motion, remove the noLoop(); expression
if you want different circle colors, add a third parameter to your circle function:
--
void circles(int x, int y, color c){
 fill(c);
--

Quote:


float x = 200;
float y = 200;
float Size;

void setup()
{
 size(550,400);
 background(#FFFFFF);
fill(0, 102, 153, 204);
smooth();

}

void draw() {
float randX = random(-3,3);
float randY = random(-3,3);
float randSize = random(-3,3);
color randCol = color(random(255),random(255),random(255));
 x = x+randX;
 y = y+randY;
  Size = Size + randSize;
 circles(x, y,Size,randCol);
}

void circles(float x, float y, float size, color c) {
 fill(c);
 ellipse(x, y, size, size);
}



try my edit of your code, not sure if this is what you mean, but have a look,

if you want to have "smoother" randomness, take a look at http://processing.org/reference/noise_.html

if you want only one circle, add a background(#FFFFFF); expression to the draw() function.
Page Index Toggle Pages: 1