/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.8NEbL1DPrWd/rev.1041
*
* authors:
* frederic.vernier
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
// This sketch builds on a prior work, "flower pattern", created by frederic.vernier
// http://studio.sketchpad.cc/sp/pad/view/ro.9Qte73oyE-QHJ/rev.1722
float a = 0;
int cx, cy;
void setup() {
size(920, 800);
smooth();
strokeWeight(2);
noLoop();
cx = width/2;
cy = height/2;
}
void drawPoly(int x, int y, R, int v){
float ANG = PI/3;
colorMode(HSB);
float aa= sin(a)*sin(a)*sin(a);
// dessine une courbe point par point
stroke(v, 255, 128);
for (int k=1; k<2; k++){
strokeWeight(4-k);
fill (v, 128, 255-k*32);
beginShape();
vertex(x+R*cos(0), y+R*sin(0));
for (int i=0; i<6; i++) {
int x0 = x+R*cos(i*ANG);
int y0 = y+R*sin(i*ANG);
int x1 = x+R*cos((i+1)*ANG);
int y1 = y+R*sin((i+1)*ANG);
int dx = 3*(y0-y1)/(2*k)*aa;
int dy = 3*(x1-x0)/(2*k)*aa;
bezierVertex((2*x0+x1)/3+dx, (2*y0+y1)/3+dy,
(x0+2*x1)/3-dx, (y0+2*y1)/3-dy, x1, y1);
}
endShape(CLOSE);
R=R/2;
}
}
void drawRecLine0(int x, int y, int r, int c) {
drawPoly(x, y, r, c);
if (x>=0 && x<=width && y>=0 && y<=height) {
drawRecLine0(x, y-r*sqrt(3), r, c);
}
}
void drawRecLine1(int x, int y, int r, int c) {
while (x>=0 && x<=width && y>=0 && y<=height) {
drawPoly(x, y, r, c);
y = y-r*sqrt(3);
}
}
void drawRecLine2(int r, int c, int n) {
pushMatrix();
drawPoly(0, 0, r, c);
translate (0, -r*sqrt(3));
float x = screenX(0, 0);
float y = screenY(0, 0);
if (x>=0 && x<=width && y>=0 && y<=height) {
drawRecLine2(r, c, n+1);
}
popMatrix();
}
void drawRecLine3(int r, int c) {
float x = screenX(0, 0);
float y = screenY(0, 0);
while (screenX(0, 0)>=0 && screenX(0, 0)<=width && screenY(0, 0)>=0 && screenY(0, 0)<=height) {
drawPoly(0, 0, r, c);
translate (0, -r*sqrt(3));
}
}
void drawRecLine4(int r, int c, boolean dir) {
pushMatrix();
while (screenX(0, r*sqrt(3))>=0 && screenX(0, r*sqrt(3))<=width && screenY(0, r*sqrt(3))>=0 && screenY(0, r*sqrt(3))<=height) {
drawPoly(0, 0, r, c);
translate (0, -r*sqrt(3));
}
popMatrix();
pushMatrix();
rotate(dir?PI/3:-PI/3);
translate (0, -r*sqrt(3));
if (screenX(0, 0)>=0 && screenX(0, 0)<=width && screenY(0, 0)>=0 && screenY(0, 0)<=height)
drawRecLine4(r, dir?c+50:c, !dir);
popMatrix();
}
void draw() {
int R = 50;
a = (a+PI/32);
background(255);
pushMatrix();
translate (cx, cy);
rotate(a/12);
drawPoly(0, 0, R, 0);
for (int i=0; i<6; i++) {
rotate(PI/3);
pushMatrix();
translate (0, -R*sqrt(3));
drawRecLine4 (R, 20, true);
popMatrix();
}
popMatrix();
}
void mouseMoved(){
//cx = mouseX;
//cy = mouseY;
}
void mouseOver(){
loop();
}
void mouseOut(){
noLoop();
}