/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.kzfA5zpz2dL/rev.1114
*
* authors:
* erdely daniel
*
* daniel
* Janos Erdos Jr.
*
* dani
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
void setup(){
size(400,400);
}
void draw(){
background(241,253,246);
fill(70,84,170);
//fill(202,26,88);
noStroke();
int s = 100;
for(int i = -s; i < width+s; i+=s)
for(int j = -s; j < height+s; j+=s){
if( (i/s+j/s)%2==0 ) continue;
PVector a = map(i, j);
PVector b = map(i+s, j);
PVector c = map(i, j+s);
PVector d = map(i+s, j+s);
beginShape();
duplaspiral(a.x, a.y, b.x, b.y);
duplaspiral(b.x, b.y, d.x, d.y);
duplaspiral(d.x, d.y, c.x, c.y);
duplaspiral(c.x, c.y, a.x, a.y);
endShape();
}
}
PVector map(int x, int y){
float d = dist(x,y, mouseX, mouseY), dd = sqrt(d)/2;
if(d==0) return new PVector(x,y);
return new PVector(x+(mouseX-x)/dd,y+(mouseY-y)/dd);
}
void duplaspiral(float x1, float y1, float x2, float y2){
final float d = dist(x1,y1,x2,y2), a = atan2(x1-x2,y1-y2);
final float phi = 2; //1.6180339887;
final float A = 2.15, B=1;
// beginShape();
for(int radius = 0, d1 = d/phi, d1log=A*log(d1*B); radius < d1; radius+=1){
float aa = a+A*log(radius*B)-d1log-PI;
vertex(x1+sin(aa)*radius, y1+cos(aa)*radius);
}
for(int d1 = d-d/phi, d1log=A*log(d1*B), radius = d1; radius > 0; radius-=1){
float aa = a+A*log(radius*B)-d1log;
vertex(x2+sin(aa)*radius, y2+cos(aa)*radius);
}
// endShape(OPEN);
}