|
|
a5e8d6 |
|
|
|
a5e8d6 |
#include <math.h></math.h>
|
|
|
a5e8d6 |
#include <helianthus.h></helianthus.h>
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
#define LINE 0.05
|
|
|
a5e8d6 |
#define DOT 0
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
double dx = 0.4;
|
|
|
a5e8d6 |
double dy = 0.4;
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
void drawLine(double pos) {
|
|
|
a5e8d6 |
line(0, 0, pos, 0);
|
|
|
a5e8d6 |
circle(0, 0, DOT);
|
|
|
a5e8d6 |
circle(pos, 0, DOT);
|
|
|
a5e8d6 |
}
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
void drawQuad(double pos) {
|
|
|
a5e8d6 |
saveState();
|
|
|
a5e8d6 |
noFill();
|
|
|
a5e8d6 |
moveTo(0, 0);
|
|
|
a5e8d6 |
lineTo(1, 0);
|
|
|
a5e8d6 |
lineTo(1, pos);
|
|
|
a5e8d6 |
lineTo(0, pos);
|
|
|
a5e8d6 |
closePath();
|
|
|
a5e8d6 |
restoreState();
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
circle(0, 0, DOT);
|
|
|
a5e8d6 |
circle(1, 0, DOT);
|
|
|
a5e8d6 |
circle(0, pos, DOT);
|
|
|
a5e8d6 |
circle(1, pos, DOT);
|
|
|
a5e8d6 |
}
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
void drawCube(double pos) {
|
|
|
a5e8d6 |
double ddx = pos*dx;
|
|
|
a5e8d6 |
double ddy = pos*dy;
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
saveState();
|
|
|
a5e8d6 |
noFill();
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
moveTo(0, 0);
|
|
|
a5e8d6 |
lineTo(1, 0);
|
|
|
a5e8d6 |
lineTo(1, 1);
|
|
|
a5e8d6 |
lineTo(0, 1);
|
|
|
a5e8d6 |
closePath();
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
moveTo(ddx + 0, ddy + 0);
|
|
|
a5e8d6 |
lineTo(ddx + 1, ddy + 0);
|
|
|
a5e8d6 |
lineTo(ddx + 1, ddy + 1);
|
|
|
a5e8d6 |
lineTo(ddx + 0, ddy + 1);
|
|
|
a5e8d6 |
closePath();
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
line(0, 0, ddx + 0, ddy + 0);
|
|
|
a5e8d6 |
line(1, 0, ddx + 1, ddy + 0);
|
|
|
a5e8d6 |
line(0, 1, ddx + 0, ddy + 1);
|
|
|
a5e8d6 |
line(1, 1, ddx + 1, ddy + 1);
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
restoreState();
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
circle(0, 0, DOT);
|
|
|
a5e8d6 |
circle(1, 0, DOT);
|
|
|
a5e8d6 |
circle(0, 1, DOT);
|
|
|
a5e8d6 |
circle(1, 1, DOT);
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
circle(ddx + 0, ddx + 0, DOT);
|
|
|
a5e8d6 |
circle(ddx + 1, ddx + 0, DOT);
|
|
|
a5e8d6 |
circle(ddx + 0, ddx + 1, DOT);
|
|
|
a5e8d6 |
circle(ddx + 1, ddy + 1, DOT);
|
|
|
a5e8d6 |
}
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
void init() {
|
|
|
a5e8d6 |
}
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
void draw() {
|
|
|
a5e8d6 |
double w = windowGetWidth();
|
|
|
a5e8d6 |
double h = windowGetHeight();
|
|
|
a5e8d6 |
double t = windowGetSeconds();
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
saveState();
|
|
|
a5e8d6 |
translate(w/2, h/2);
|
|
|
a5e8d6 |
zoom(100);
|
|
|
a5e8d6 |
translate(-0.5, -0.5);
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
fill(COLOR_BLACK);
|
|
|
a5e8d6 |
stroke(COLOR_BLACK);
|
|
|
a5e8d6 |
strokeWidth(LINE);
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
double a = t/3*2*PI;
|
|
|
a5e8d6 |
double pos = 0.5*(1 - cos(a))*3;
|
|
|
a5e8d6 |
if (pos < 1) drawLine(pos); else
|
|
|
a5e8d6 |
if (pos < 2) drawQuad(pos-1); else
|
|
|
a5e8d6 |
drawCube(pos-2);
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
restoreState();
|
|
|
a5e8d6 |
}
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
|
|
|
a5e8d6 |
int main() {
|
|
|
a5e8d6 |
windowSetVariableFrameRate();
|
|
|
a5e8d6 |
windowSetResizable(TRUE);
|
|
|
a5e8d6 |
windowSetInit(&init);
|
|
|
a5e8d6 |
windowSetDraw(&draw);
|
|
|
a5e8d6 |
windowRun();
|
|
|
a5e8d6 |
return 0;
|
|
|
a5e8d6 |
}
|