Random Walkers + Vectors

I used the random walker as a template to simulate some real-world “natural” motion. The class in the sketch is an ellipse that moves randomly and changes its radius over time, creating the shape for each crawling worm. The array of worms create a visual composition as they move through the screen.



Processing code:

Worm [] worm= new Worm[50]; void setup() { size(800, 800); background(0, 25, 50); smooth(); frameRate(30); for (int i=0; i< worm.length; i++) { worm[i] =new Worm(int(random(0, 1))); } } void draw() { noStroke(); fill(100, 200, 250, 30); for (int i=0; i< worm.length; i++) { worm[i].move(); worm[i].display(); } } class Worm { float radius, topspeed, resize; PVector location, velocity, acceleration; Worm(int _resize) { radius=random(3, 10); resize=_resize; topspeed=2; location=new PVector(random(width), random(height)); velocity=new PVector(0, 0); } void display() { ellipse(location.x, location.y, radius, radius); if (radius > 9) { resize = 0; } else if (radius < 0) { resize = 1; } if (resize == 1) { radius += random(.2, .25); } else if ( resize== 0) { radius -=random(.2, .25); } } void move() { acceleration=new PVector(random(-5, 5), random(-5, 5)); velocity.limit(topspeed); acceleration.normalize(); acceleration.mult(.25); velocity.add(acceleration); location.add(velocity); } }

Leave a Reply