Recitation 6 Documentation

Part 1: Recitation project

int barWidth = 40;
int lastBar = -1;
void setup() {
  size(1024, 768);
  background(0);
  rectMode(CENTER);
}

void draw() {
  drawBackground();
  for (int i=240; i<=width-160; i+=80) {
    if (i==240||i==800) {
      for (int j=240; j<=height-160; j+=80) {
        drawLight(i, j, color(random(155, 255), random(160, 250), random(70, 130)));
      }
    } else {
      drawLight(i, 240, color(random(155, 255), random(160, 250), random(70, 130)));
      drawLight(i, 560, color(random(155, 255), random(160, 250), random(70, 130)));
    }
  }
  
  fill(#EE82FC);
  textSize(240);
  textAlign(CENTER);
  text("IMA", width/2-30, height/2+40);
}

void drawLight(int x, int y, color c) {
  if(!mousePressed){
    fill(c);
  }
  else fill(#FBFF93,100);
  stroke(0, 0, 0);
  circle(x-40, y-48, 48);
  fill(#9A989D);
  rect(x-40, y-24, 16, 2.4);
  rect(x-40, y-21.6, 16, 2.4);
  rect(x-40, y-19.2, 16, 2.4);
  rect(x-40, y-16.8, 16, 2.4);
  rect(x-40, y-14.4, 16, 2.4);
}

void drawBackground(){
  push();
  rectMode(LEFT);
  colorMode(HSB, width, height, 100); 
  noStroke();
  int whichBar = mouseX / barWidth;
  if (whichBar != lastBar) {
    int barX = whichBar * barWidth;
    fill(barX, mouseY, 56,40);
    rect(barX, 0, barWidth, height);
    lastBar = whichBar;
  }
  pop();
}

Part 2: Homework

void setup() {
  size(1024, 768);
  background(0);
  rectMode(CENTER);
}

void draw() {
  for (int i=80; i<=width+80; i+=80) {
    for (int j=80; j<=height; j+=80) {
      drawLight(i, j, color(random(155, 255), random(160, 250), random(70, 130)));
    }
  }
  int x1=mouseX/100;
  int y1=mouseY/100;
  drawIMA(x1, y1);
}

void drawLight(int x, int y, color c) {
  fill(c);
  stroke(0,0,0);
  circle(x-40, y-48, 48);
  fill(#9A989D);
  rect(x-40, y-24, 16, 2.4);
  rect(x-40, y-21.6, 16, 2.4);
  rect(x-40, y-19.2, 16, 2.4);
  rect(x-40, y-16.8, 16, 2.4);
  rect(x-40, y-14.4, 16, 2.4);
}

void drawIMA(int a, int b) {
  a=a*80;
  b=b*80;
  if (mousePressed) {
    for (int i=b; i<=b+320; i+=80) {
      drawLight(a, i, color(random(100, 120), random(150, 200), random(200, 255)));
      drawLight(a+160, i, color(random(100, 120), random(150, 200), random(200, 255)));
      drawLight(a+320, i, color(random(100, 120), random(150, 200), random(200, 255)));
    }
    drawLight(a+240, b+80, color(random(100, 120), random(150, 200), random(200, 255)));
    for (int i=b+80; i<=b+320; i+=80) {
      drawLight(a+480, i, color(random(100, 120), random(150, 200), random(200, 255)));
      drawLight(a+640, i, color(random(100, 120), random(150, 200), random(200, 255)));
    }
    drawLight(a+560, b, color(random(100, 120), random(150, 200), random(200, 255)));
    drawLight(a+560, b+160, color(random(100, 120), random(150, 200), random(200, 255)));
    
  }
}

I have learnt a lot from the recitation class. My biggest takeaway is that I learnt a useful coding skill which is “push()” and “pop()”. It has been applied to many situations. 

 

Leave a Reply

Your email address will not be published. Required fields are marked *