Category: Assignment-04-Schotter

Michelle Ma – Schotter

I finall got this to work!! Hallelujah!! I’m still fresh to Processing and everything, so I’m pretty happy about these boxes…

size(500,700);
size(500,700);
stroke(0);
noFill();
 
float a=0;  //random bounds
float rand; //degrees to rotate randomly
 
for(int i=1;i< =20;i++){   //rows
  a += i*.7;              //randomness increases as rows increase
  for(int j=1;j<=13;j++){  //columns
    pushMatrix();
    rand = random(-a,a);
    translate(35+(j*30),35+(i*30));
    rotate(radians(rand));
    rect(0,0,30,30);
    popMatrix();
  }
}

Schotter2

Ticha-Shattering Schotter


(Click to shatter. Click again to stop.)

I was messing around with Processing and wanted to do something that was on the interactive side (and because Dave did something really neat :D). It’s not too fancy, but it works more or less the way I wanted it to. Initially, I wanted the structure to collapse continuously after the mouse is pressed once, but I couldn’t find a way to do that :/ Yay, it works now! Also, I’m going to have to find a way to not make the blocks react so violently. Fixed.

Here is le code:

int rows = 20;
int cols = 12;
bool beginShatter;
 
Square[][] squares = new Square[cols][rows];
 
void setup() {
  size(360, 480);
 
  smooth();
  //initialization of square array
  for (int c = 0; c < cols; c++ ) {
    for (int r = 0; r < rows; r++) {
      squares[c][r] = new Square(c*20, r*20);
    }
  }
  beginShatter = false;
   
}
 
void draw() {
  background(220);
 
  translate(55, 30);
 
  for (int c = 0; c < cols; c++ ) {
    for (int r = 0; r < rows; r++) {
      squares[c][r].display();
    }
  }
 
  if (beginShatter) {
    for (int r = 0; r < rows; r++ ) {
      for (int c = 0; c < cols; c++) {
        squares[c][r].fall((r+10)/4);
        squares[c][r].spin(r*3+1);
        squares[c][r].display();
      }
    }
  }
}
 
void mousePressed() {
    beginShatter = !beginShatter;
}
 
class Square {
  int xpos;
  int ypos;
  float theta;
 
  //Square constructor
  Square(int xpos_, int ypos_) {
    xpos = xpos_;
    ypos = ypos_;
    theta = 0;
  }
 
  void display() {
    stroke(1);
    noFill();
 
    pushMatrix();
    translate(xpos,ypos);
    rotate(theta);
    rect(0, 0, 20, 20);
    popMatrix();
  }
  void spin(int i) {
    float rand = random(-i, i);
    theta = 3*radians(rand)/4;
  }
  void fall(int i) {
    ypos+=(random(i))/4;
  }
}

It’s funny because I feel like the Schotters generated by this animation looks closer to the original than the ones I generated manually.

Dave-Schotter

dave-schotter-screenshot

 

I never did much with interactivity and animation in Processing before so I decided to incorporate it into this. The user decides when to stop.Try it out here:

Click and hold the mouse and then shake on the canvas to produce Schotter’s effect.

int square_width = 15;
float acceleration = 0.0;

class Square{
  float x,y,theta;
  float direction;

  Square(float a, float b, float t)
  {
    x = a;
    y = b;
    theta = t;
    direction = 1.0;
  }

  void change_angle(float t){
    theta = t;
  }

  void change_Xcoord(float i){
    x = i;
  }

  void change_Ycoord(float i){
    y = i;
  }

  void change_direction(float d){
    direction = d;
  }
}

Square squaresArray[][];

/**
 * initialize the default squares
 */
void generate_squares(){
  squaresArray = new Square[height/square_width][width/square_width];
  for (int y = 0; y < height/square_width; y++) {
    for(int x = 0; x < width/square_width; x++){
      squaresArray[y][x] = new Square(x*square_width,y*square_width,0);
    } 
  }

}

void setup() {
  size(510, 600);
  background(255);
  frameRate(30);
  noFill();

  generate_squares();
}

void mouseClicked(){
  for (int y = 1; y < squaresArray.length - 1; y++) {
    for(int x = 1; x < squaresArray[y].length - 1; x++){
      int a = Math.round(random(0,1));
      if(a == 0)
        a = -1;

      squaresArray[y][x].change_direction((float)a);
    }
  }
}

void draw(){

  // refresh screen
  background(255);

  float should_move;  // decides whether we should change Y coord
  if(!mousePressed)   // if user is dragging
  {
    acceleration = acceleration/1.1;
    should_move = 0.0;
  }
  else        // the user let go
  {
    acceleration = (mouseX - pmouseX)*0.007;
    should_move = 1.0;
  }

  // loop through to draw squares
  for (int y = 1; y < squaresArray.length - 1; y++) {
    for(int x = 1; x < squaresArray[y].length - 1; x++){

      Square square = squaresArray[y][x];

      pushMatrix();

      // rotate the square by theta
      translate((int)square.x,
            (int)square.y);
      rotate(square.theta);

      // record new angle
      square.change_angle(square.theta +
                  acceleration*(y/height + 1)*
                  (y*random(0.0,0.05) *
                  square.direction));

      // record new y location (squares slowly shift downward)
      square.change_Ycoord(square.y +
                  abs(acceleration)*
                  should_move*
                  ((y*y)/100.0));

      // draw the rectangle
      rect(0,0,square_width,square_width);

      popMatrix();
    }
  }
}

melanie-schotter

shitter

size(390, 560);
float rfactor = 0.001;
stroke(20);
for(int r = 0; r < 22; r++)
{
  for(int c = 0; c < 12; c++)
  {
    pushMatrix();
    noFill();
    translate(c*21+68, r*21+50);
    rotate(random(-rfactor,rfactor));
    rect(0, 0, 21, 21);
    popMatrix();
  }
  rfactor+=0.06;
}

Ticha-Schotter

int screenwidth = 360;
int screenheight = 480;
int hori = 55;
int vert = 30; 

void setup() {
  size(screenwidth, screenheight);
  background(220);
  noFill();
  noLoop();
}

void draw() {
  for (int row = 0; row < 20; row++) {
    for (int col = 0; col < 12; col++) {
      translate(hori+(col*20), vert+(row*20)); 

      float rand1 = random(-(row*4+(col/2)),row*4+(col/2));
      rotate(radians(rand1)); 
      rect(0, 0, 20, 20);
      rotate(-radians(rand1)); 

      translate(-hori-(col*20), -vert-(row*20));
    }
  }
}

Screen Shot 2013-09-05 at 10.03.38 PM Screen Shot 2013-09-05 at 10.13.36 PM

Madeleine-Schotter

int side = 20;
 
void setup() {
  size(320, 580);
  noLoop();
}
   
void draw() {
  background(225);
  fill(0, 0, 0, 0);
  smooth();
   
  for (int i = 0; i < 12; i++) {
    for (int j = 0; j < 24; j++) {
      pushMatrix();
      translate(i*side + 40, j*side + 40);
      rotate(random(PI*j/-54.0, PI*j/54.0)); //pick something good for this
      rect(0, 0, side, side);
      popMatrix();
    }
  }
}

Additional screenshot:

Screen Shot 2013-09-05 at 9.03.18 AM