Blob Blame Raw

#include <math.h>
#include <helianthus.h>


#define LINE 0.05
#define DOT  0


double dx = 0.4;
double dy = 0.4;


void drawLine(double pos) {
  line(0, 0, pos, 0);
  circle(0, 0, DOT);
  circle(pos, 0, DOT);
}

void drawQuad(double pos) {
  saveState();
  noFill();
  moveTo(0, 0);
  lineTo(1, 0);
  lineTo(1, pos);
  lineTo(0, pos);
  closePath();
  restoreState();

  circle(0, 0, DOT);
  circle(1, 0, DOT);
  circle(0, pos, DOT);
  circle(1, pos, DOT);
}

void drawCube(double pos) {
  double ddx = pos*dx;
  double ddy = pos*dy;

  saveState();
  noFill();

  moveTo(0, 0);
  lineTo(1, 0);
  lineTo(1, 1);
  lineTo(0, 1);
  closePath();

  moveTo(ddx + 0, ddy + 0);
  lineTo(ddx + 1, ddy + 0);
  lineTo(ddx + 1, ddy + 1);
  lineTo(ddx + 0, ddy + 1);
  closePath();

  line(0, 0, ddx + 0, ddy + 0);
  line(1, 0, ddx + 1, ddy + 0);
  line(0, 1, ddx + 0, ddy + 1);
  line(1, 1, ddx + 1, ddy + 1);

  restoreState();

  circle(0, 0, DOT);
  circle(1, 0, DOT);
  circle(0, 1, DOT);
  circle(1, 1, DOT);

  circle(ddx + 0, ddx + 0, DOT);
  circle(ddx + 1, ddx + 0, DOT);
  circle(ddx + 0, ddx + 1, DOT);
  circle(ddx + 1, ddy + 1, DOT);
}



void init() {
}


void draw() {
  double w = windowGetWidth();
  double h = windowGetHeight();
  double t = windowGetSeconds();

  saveState();
  translate(w/2, h/2);
  zoom(100);
  translate(-0.5, -0.5);

  fill(COLOR_BLACK);
  stroke(COLOR_BLACK);
  strokeWidth(LINE);

  double a = t/3*2*PI;
  double pos = 0.5*(1 - cos(a))*3;
  if (pos < 1) drawLine(pos); else
    if (pos < 2) drawQuad(pos-1); else
      drawCube(pos-2);

  restoreState();
}



int main() {
  windowSetVariableFrameRate();
  windowSetResizable(TRUE);
  windowSetInit(&init);
  windowSetDraw(&draw);
  windowRun();
  return 0;
}