Visual Experiment 15 (Processing)

Tags:

For this code experiment, I used the code from the Processing website as a reference.

Example

/**
 * Embedding Iteration. 
 * 
 * Embedding "for" structures allows repetition in two dimensions. 
 *
 */


size(640, 360); 
background(0); 

int gridSize = 40;

for (int x = gridSize; x <= width - gridSize; x += gridSize) {
  for (int y = gridSize; y <= height - gridSize; y += gridSize) {
    noStroke();
    fill(255);
    rect(x-1, y-1, 3, 3);
    stroke(255, 100);
    line(x, y, width/2, height/2);
  }
}

As the pattern looked very eye appealing, I though on adding some dynamism by creating a variable angle and make it iterate through the x1 and y1 of the line.

void setup() {
  size(900, 600);
  background(0);

  int gridSize = 10;
  float angle = 0.10;
  int time = 0;

  for (int x = gridSize; x <= width - gridSize; x += gridSize) {
    for (int y = gridSize; y <= height - gridSize; y += gridSize) {
      time = y;
      noStroke();
      fill(255);
      rect(x - 1, y - 1, 3, 3);
      stroke(255, 50);

      float x1 = width/2 * sin(angle * x) * 100*time;
      float y1 = height/2 * cos(angle * y) * 100*time;

      line(x, y, x1, y1);
    }
  }
}

It’s important to mention that the code should be run in the setup() function and not in draw(), because otherwise, it would execute continuously, generating a completely different geometry.

I think it’s also worth mentioning that the discovery of this code was a coincidence, but it generated an interesting pattern by not being run in the draw() function.