Blob Blame Raw
#include <helianthus.h>
#include <math.h>

#define CIRCLES_COUNT   20
#define CIRCLES_RADIUS  25
#define RING_RADIUS     50
#define ROTATION_SPEED 70
#define RINGS_COUNT 3


double angles[6];
double speeds[6];


void init() {
  background(colorByHSV(0, 0, 0.2));
}

void draw() {
  for(int j = 1; j <= RINGS_COUNT; j++) {
    saveState();
    strokeWidth(CIRCLES_RADIUS + j*10);
    translate(mouseX(), mouseY());
    if (mouseDown("left")) {
      angles[j] -= windowGetFrameTime() * (ROTATION_SPEED * (j/3.0));
      speeds[j] = 0;
    } else
    if (mouseDown("right")) {
      angles[j] += windowGetFrameTime() * (ROTATION_SPEED * (j/3.0));
      speeds[j] = 0;
    } else {
      speeds[j] -= angles[j];
      speeds[j] *= pow(0.1, windowGetFrameTime());
      angles[j] += speeds[j]*windowGetFrameTime();
    }

    rotate(windowGetSeconds() + angles[j]);

    for(int i = 0; i < CIRCLES_COUNT; i++) {
      double a = 0;
      //if (mouseDown("left"))
        a = 360.0*i/CIRCLES_COUNT;
      double x = 1 + 0.05*sin(windowGetSeconds()*10 + a/180*PI*13);
      stroke(colorByHSV(a, 0.7, 1));
      point(RING_RADIUS*j*x, 0);
      rotate(360.0/CIRCLES_COUNT);
    }
    restoreState();
  }
}

int main() {
  windowSetTitle("Iron Spring Simulator");
  windowSetVariableFrameRate();
  windowSetResizable(TRUE);
  windowSetInit(&init);
  windowSetDraw(&draw);
  windowRun();
  return 0;
}