Art Squares


Project Code

This code is written and rendered using Processing (v3), a quick and easy graphical sketchbook engine written in Java
class Square {
  float x;
  float y;
  float z;
  float w;
  float h;
  float strokeW;
  float hue;
  int tick = 0;
  
  // 2d
  Square(float x_, float y_, float w_, float h_, float strokeW_, float hue_) {
    x = x_;
    y = y_;
    z = 0;
    w = w_;
    h = h_;
    strokeW = strokeW_;
    hue = hue_;
    tick = floor(map(floor(hue_), 0, 50, 0, 60));
  }
  
  // 3d
  Square(float x_, float y_, float z_, float w_, float h_, float strokeW_, float hue_) {
    x = x_;
    y = y_;
    z = z_;
    w = w_;
    h = h_;
    strokeW = strokeW_;
    hue = hue_;
    //tick = floor(map(floor(hue_), 0, 50, 0, 60));
    tick = floor(map(floor(hue_), 100, 10, 0, 60));
  }
  
  void update() {
    tick += 2;
  }
  
  void display() {
    push();
    
    float brightness = map((tick % 120), 0, 60, 0, 100); 
    
    translate(x, y);
    
    beginShape();
    
    noFill();
    strokeWeight(strokeW);
    stroke(hue, 100, brightness);
    
    //rect(0, 0, w, h);
    
    //vertex(0, 0, z);
    //vertex(w, 0, z);
    //vertex(w, h, z);
    //vertex(0, h, z);
    
    vertex(0, 0);
    vertex(w, 0);
    vertex(w, h);
    vertex(0, h);
    
    endShape(CLOSE);
    
    pop();
  }
}
Square[] sqs;

int num_sqs = 11;

void push() {
  pushMatrix();
  pushStyle();
}

void pop() {
  popStyle();
  popMatrix();
}


void setup() {
  //size(600, 600, P3D);
  size(600, 600);
  
  colorMode(HSB, 100);
  
  //ortho();
  
  sqs = new Square[ num_sqs ];
  
  float w = 200;
  float h = 200;
  float spacing = 18;
  float strokeW = 9;
  float starting_x = (0 - (w / 2) + ((num_sqs / 2) * (spacing + (strokeW / 2))));
  float starting_y = (0 - (h / 2) - ((num_sqs / 2) * (spacing + (strokeW / 2))));
  
  for(int i = num_sqs; i > 0; i--) {
    float x = (starting_x - (i * spacing));
    float y = (starting_y + (i * spacing));
    //float z = (-1 * (num_sqs - i) * spacing);
    
    //float hue = map(i, num_sqs, 1, 50, 0);
    float hue = map(i, num_sqs, 1, 100, 10);
    
    //sqs[ (i - 1) ] = new Square(x, y, z, w, h, strokeW, hue);
    sqs[ (i - 1) ] = new Square(x, y, w, h, strokeW, hue);
  }
}

void draw() {
  background(0);
  
  push();
  translate(width/2, height/2);
  
  for(Square sq : sqs) {
    sq.update();
    sq.display();
  }
  
  pop();
  
  if(frameCount == 50) { save("preview.png"); }
}
please visit our Contact Us page to get in touch
pyxol © 2021