Tuesday, 8 May 2018

Cafe Wall Illusion using processing




Cafe Wall Illusion

int s=89;
color black=color(0);
color white=color(255);
Line l[];
float update=0;

void setup() {
  size(810, 680);
  stroke(89, 89, 89);
  strokeWeight(2);
  l=new Line[8];

  for (int i=0; i<8; i++) {
    l[i]=new Line(i*90);
  }
}

void draw() {

  for (int i=0; i<8; i++) {
    if (i%2==0)
      l[i].drawL(-270+update);
    else
      l[i].drawL(-270-update);
  }
  update=update+0.5;
  //println(update+"");
  if (update==180)
    update=0;
}

class Line {

  int n=20;
  float posY;

  Line(float posY) {
    this.posY=posY;
  }

  void drawL(float diff) {

    for (int i=0; i<16; i++) {
      float posX=i*90 +diff;
      if (i%2==0) {
        fill(0);
        rect(posX, posY, s, s);
      } else {
        fill(255);
        rect(posX, posY, s, s);
      }
    }
  }
}

No comments:

Post a Comment