Blame onefile/iron-spring.c

261920
#include <helianthus.h></helianthus.h>
261920
#include <math.h></math.h>
261920
261920
#define CIRCLES_COUNT   20
261920
#define CIRCLES_RADIUS  25
261920
#define RING_RADIUS     50
261920
#define ROTATION_SPEED 70
261920
#define RINGS_COUNT 3
261920
261920
261920
double angles[6];
261920
double speeds[6];
261920
261920
261920
void init() {
261920
  background(colorByHSV(0, 0, 0.2));
261920
}
261920
261920
void draw() {
261920
  for(int j = 1; j <= RINGS_COUNT; j++) {
261920
    saveState();
261920
    strokeWidth(CIRCLES_RADIUS + j*10);
261920
    translate(mouseX(), mouseY());
261920
    if (mouseDown("left")) {
261920
      angles[j] -= windowGetFrameTime() * (ROTATION_SPEED * (j/3.0));
261920
      speeds[j] = 0;
261920
    } else
261920
    if (mouseDown("right")) {
261920
      angles[j] += windowGetFrameTime() * (ROTATION_SPEED * (j/3.0));
261920
      speeds[j] = 0;
261920
    } else {
261920
      speeds[j] -= angles[j];
261920
      speeds[j] *= pow(0.1, windowGetFrameTime());
261920
      angles[j] += speeds[j]*windowGetFrameTime();
261920
    }
261920
261920
    rotate(windowGetSeconds() + angles[j]);
261920
261920
    for(int i = 0; i < CIRCLES_COUNT; i++) {
261920
      double a = 0;
261920
      //if (mouseDown("left"))
261920
        a = 360.0*i/CIRCLES_COUNT;
261920
      double x = 1 + 0.05*sin(windowGetSeconds()*10 + a/180*PI*13);
261920
      stroke(colorByHSV(a, 0.7, 1));
261920
      point(RING_RADIUS*j*x, 0);
261920
      rotate(360.0/CIRCLES_COUNT);
261920
    }
261920
    restoreState();
261920
  }
261920
}
261920
261920
int main() {
261920
  windowSetTitle("Iron Spring Simulator");
261920
  windowSetVariableFrameRate();
261920
  windowSetResizable(TRUE);
261920
  windowSetInit(&init);
261920
  windowSetDraw(&draw);
261920
  windowRun();
261920
  return 0;
261920
}