Week 1 Modular Composition

I am back. It’s been a few months since I last coded in Processing and this represents a new opportunity for me to delve right back into particle systems.

This semester, however, I would like to take it to the next level by making Processing compositions that are “architectural” in nature. In any case, I needed to do some review of the major concepts of object-oriented programming.  The majority of the week I spent watching Daniel Shiffman’s very recent YouTube channel where he provides supplementary lectures to the two books I used in the Fall to learn Processing.

So I wanted my first script to be somewhat angular and modular. Modularity will be a big theme this summer during this study as I set out to model expansive urban sceneries. The best way to accomplish this is through the use of module set pieces that are then arranged, repeated and combined to create buildings. This technique is used to create the diverse open worlds of popular videogames like Fallout and Grand Theft Auto.

To do this, I thought of a random walker example in the beginning of Shiffman’s the Nature of Code. We can set a variable to be randomly chosen and have that variable determine whether the walker makes a step up, or down, left or right. In order to constrain the direction, I made this small function

void changeDir(){
    float r = random(0, 1);
    float newAngle = angle;
    if(r > 0.5){
      newAngle+=90;
    }else{
      newAngle-=90;
    }

Depending on the value of ‘r’, we can set the velocity direction of each new particle to be determined by sin(x) and cos(y)

velocity = new PVector(sin(radians(newAngle)), cos(radians(newAngle)));
    angle = newAngle;
  }

This confined the trace of the particles to be linear and in one of the 4 cardinal directions, so you end up with particles tracing a network of squares. Pretty neat!

You can see my script here http://www.openprocessing.org/sketch/361605

See you in another post this week.