Blame onefile/color-papers.c

261920
261920
#include <math.h></math.h>
261920
#include <helianthus.h></helianthus.h>
261920
261920
#define WIDTH  1024
261920
#define HEIGHT  768
261920
#define SIZE    100
261920
#define COUNT   100
261920
261920
261920
typedef struct {
261920
  double x, y, s, r, rk;
261920
} Rect;
261920
261920
261920
Framebuffer fb;
261920
Animation anim;
261920
Rect rects[COUNT];
261920
int id;
261920
261920
261920
void generateRect(Rect *r) {
261920
  r->x = randomFloat();
261920
  r->y = randomFloat();
261920
  r->s = randomFloat();
261920
  r->r = randomFloat();
261920
  r->rk = randomFloat()*2 - 1;
261920
}
261920
261920
261920
void drawRect(Rect *r, double a) {
261920
  a = (1 - cos(a*PI))/2;
261920
  double s = r->s * a * SIZE * ((mouseX() - WIDTH / 2) + (mouseY() - HEIGHT / 2))/100;
261920
  double rot = a*r->rk*180 + r->r*360;
261920
261920
  saveState();
261920
  //stroke(colorByRGBA(0, 0, 0, a));
261920
  fill(colorByHSVA(r->x*360, 1, 1, a));
261920
  translate(r->x*WIDTH, r->y*HEIGHT);
261920
  rotate(rot);
261920
  rect(-s/2, -s/2, s, s);
261920
  restoreState();
261920
}
261920
261920
261920
void init() {
261920
  fb = createFramebuffer(WIDTH, HEIGHT);
261920
  anim = createAnimationFromFramebuffer(fb);
261920
  for(int i = 0; i < COUNT; ++i)
261920
    generateRect(&rects[i]);
261920
  saveState();
261920
  target(fb);
261920
  clear();
261920
  restoreState();
261920
}
261920
261920
261920
void draw() {
261920
  saveState();
261920
  noStroke();
261920
261920
  rectTextured(anim, 0, 0, WIDTH, HEIGHT);
261920
  for(int i = 0; i < COUNT; ++i)
261920
    drawRect(&rects[(id + i)%COUNT], 1.0 - (double)i/COUNT);
261920
261920
  target(fb);
261920
  drawRect(&rects[id], 1.0);
261920
  generateRect(&rects[id]);
261920
  id = (id + 1)%COUNT;
261920
261920
  restoreState();
261920
}
261920
261920
261920
int main() {
261920
  windowSetVariableFrameRate();
261920
  windowSetSize(WIDTH, HEIGHT);
261920
  windowSetInit(&init);
261920
  windowSetDraw(&draw);
261920
  windowRun();
261920
}
261920