Processing Examples - Random Walks

Moderator: BenChang

Processing Examples - Random Walks

Postby BenChang » Tue Nov 11, 2014 7:25 pm

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);
 
}
User avatar
BenChang
 
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm

Growth

Postby BenChang » Tue Nov 11, 2014 7:25 pm

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);
 
}
User avatar
BenChang
 
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm

Random walk, growth, mouse

Postby BenChang » Tue Nov 11, 2014 7:27 pm

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);
 
}
User avatar
BenChang
 
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm

Random walk, growth, mouse event

Postby BenChang » Tue Nov 11, 2014 7:29 pm

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);
 
}
User avatar
BenChang
 
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm


Return to Art and Animation

Who is online

Users browsing this forum: No registered users and 1 guest

cron