2d Transformations

Example of transformation + scale + rotation.
More info here.

void setup()
{
  size(200, 200);
  background(255);
  noStroke();
  rectMode(CENTER);

  // draw the original position in gray
  fill(192);
  rect(0, 0, 40, 40);

  // draw a translucent blue rectangle in the new position
  fill(0, 0, 255, 128);

  pushMatrix();
    translate(100, 100);
    rotate(radians(45));
    scale(0.5);
    rect(0, 0, 40, 40);
  popMatrix();
}

Now reproduce the plotter drawing on the below (Georg Nees Schotter 1968)!

A solution:


void setup()
{
  size(380,800);
  background(255);
  smooth();
  noLoop();
  noFill();
}

int rows = 12;
int columns = 25;
int side = 30; //of the square & distance

//variables to calibrate the randomness
float translationRandomness = .5;
float rotationRandomness = 1;

void draw()
{
    for(int r = 0; r<rows ; r++)
  {
    for(int c = 0; c<columns; c++)
    {
      pushMatrix();
      
      //10 is the margin
      float xPos = 10 + r*side + (random(-translationRandomness*c,translationRandomness*c));
      float yPos = 10 + c*side + (random(-translationRandomness*c,translationRandomness*c));
      translate(xPos, yPos);
      
      float rotation = random(-c*rotationRandomness,c*rotationRandomness);      
      rotate(radians(rotation));
      
      rect(0,0, side, side);
      popMatrix();
    }
  }

}
Posted in

Post a comment