Assignment: Order & Disorder

Create a static black and white composition using only lines that incorporates an element of order (elements drawn with for loops) and an element of chaos – or to be more precise – randomness (random and noise function).

.You have to use for loops, possibly embedded.
.You have to add some variation, either parametrically or by adding randomness or Perlin noise (see below).
.Beside posting your code on openprocessing you have to produce a PDF and deliver a print of your pattern/composition (see below).

Bonus:
.Try to use 2D transformations like rotate.

PDF OUTPUT

import processing.pdf.*;
 
void setup() {
 
  //use this function in combination with exit() below to produce a pdf file 
  size(1024, 768, PDF, "wallpaper.pdf");
 
  /*
  Alternatively use this function to test your output on screen so you can actually see what you are doing.
  DON' FORGET TO COMMENT THE exit(); down below if you are printing on screen.
   size(1024, 768);
   */
 
  /*
  BONUS:
   Can you make a repeated pattern or a flexible algorithm that is bigger
   than the area you can visualize?  
   This function produces a "letter" size document 
   that can be printed at 200 dpi (decent printing resolution)
 
    size(2200, 1700, PDF, "wallpaper.pdf");
   */
 
 
  smooth();
}
 
 
void draw() {
  // Draw something good here
  line(0, 0, width, height);
  //etcetera
 
  // Exit the program 
  println("Finished.");
 
  /*
  exit() here makes the sketch similar to static mode 
   the draw function is called only once so don't do anything 
   interactive or dynamically animated, your output should be produced
   instantaneously  
   */
 
  exit(); //if you are just testing on screen get rid of this line!
}

Random vs. Perlin Noise

Perlin noise is an infinite random sequence of values changing harmonically.
The sequence will appear “natural” if you take contiguous samples (xoff).
For advanced use check the reference.

//the sampled coordinate
float xoff = 0.0;
 
//stores the position of the random circle
float randomPosition = 150;
 
void setup()
{	
size(300, 300);
smooth();
}
 
void draw() {
  background(0);
 
  //ellipse moving randomly
  randomPosition += random(-4, 4);
  ellipse(randomPosition, 100, 10, 10);
 
  xoff = xoff + .01;
  float n = noise(xoff) * width;
  ellipse(n, 200, 10, 10);
}

Modulo Operator %

The modulo operator % produces the remainder of the division between two members.

size(400, 100);
 
background(255);
for (int i=0; i<width; i=i+10) {
  int y = i%100;
  line(i, 0, i, y);
}

Use % to make a red square every 3 columns and 3 rows.
Solution:

 
size(400, 300);
smooth();
//noStroke();
noLoop();
background(0);
rectMode(CENTER);
ellipseMode(CENTER);
 
for (int r = 0; r <= 15; r++) {
  for (int c = 0; c <= 20; c++) {
 
    if (c%3==0 && r%3==0)
    {
 
      fill(255, 0, 0);
      rect(c*20, r*20, 10, 10);
    }
    else
    {
      fill(255);
      ellipse(c*20, r*20, 10, 10);
    }
  }
}

You can also use it to constrain colors:

fill(c%3*50);

Or to create regular patterns:

fill(c%3*50, r%3*50, 255);
println(4%3); //output 1

Or to trigger timed events:

void setup() {
  size(400, 100);
}
 
void draw() {
  background(0);
 
  if (frameCount % 100 == 0) {
    background(255);
  }
}

Make it flash every second!
Link the background color to the frameCount!

Posted in

Post a comment