Page 1 of 1

Processing Examples - Random Walks

PostPosted: Tue Nov 11, 2014 7:25 pm
by BenChang
Code: Select all
/* jitter */

float x;
float y;

float dx;
float dy;

void setup ()
{
   size(800,600);
   x=400;
   y=100;
}

void draw ()
{
   //background(128);
   dx = random(-5,5);
   dy = random(-5,5);
   
   x=x+dx;
   y=y+dy;
   
   ellipse(x,y,20,20);
 
}

Growth

PostPosted: Tue Nov 11, 2014 7:25 pm
by BenChang
Code: Select all
float x;
float y;

float dx;
float dy;

float radius;
float dr;    // radius change

void setup ()
{
   size(800,600);
   x=400;
   y=300;
   
   radius = 20;
   dr=.5;
}

void draw ()
{
   
   dx = random(-5,5);
   dy = random(-5,5);
   
   x=x+dx;
   y=y+dy;
   
   radius += dr;
   
   ellipse(x,y,radius,radius);
 
}

Random walk, growth, mouse

PostPosted: Tue Nov 11, 2014 7:27 pm
by BenChang
Code: Select all
/* jitter */

float x;
float y;

float dx;
float dy;

float radius;
float dr;    // radius change

void setup ()
{
   size(800,600);
   x=400;
   y=300;
   
   radius = 20;
   dr=.5;
}

void draw ()
{
   
   dx = random(-5,5);
   dy = random(-5,5);
   
   x=x+dx;
   y=y+dy;
   
   if (mousePressed)
   {
     dr=.5;
   } 
   else
   {
      dr=-.5;
   }
   
   radius += dr;
   
   if (radius<1)
   {
      radius=1;
   }
   
   ellipse(x,y,radius,radius);
 
}

Random walk, growth, mouse event

PostPosted: Tue Nov 11, 2014 7:29 pm
by BenChang
Code: Select all
/* jitter */

float x;
float y;

float dx;
float dy;

float radius;
float dr;    // radius change

void setup ()
{
   size(800,600);
   x=400;
   y=300;
   
   radius = 20;
   dr=-.5;
}

void mousePressed()
{
   radius=200;
   x=mouseX;
   y=mouseY;
}
void draw ()
{
   
   dx = random(-5,5);
   dy = random(-5,5);
   
   x=x+dx;
   y=y+dy;
   
   radius += dr;
   
   if (radius<1)
   {
      radius=1;
   }
   
   ellipse(x,y,radius,radius);
 
}