> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.GvrL46g-PwG/rev.946
 * 
 * authors: 
 *   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/ 
 */ 



// This sketch builds on a prior work, "physical sphidron ornament", created by erdely daniel & [unnamed author] & dani & Janos Erdos Jr. & daniel
// http://studio.sketchpad.cc/sp/pad/view/ro.9ZgxCFo3EBEfR/rev.1114

var s = 54;

void setup(){
    size(480,480);
    fill(255);
    noStroke();
}

void draw(){
    //background(241,253,246);

    fill(255,192);
    rect(0,0,width, height);



    var off = s *sqrt(3);

    for(int i = -2; i < 7; i++){
        for(int j = -2; j < 7; j++){
    

        float x = i*s*2 +(j%2==0?0:s), y = j*off;

        PVector a = disort(x, y), b = disort(x+s, y+off), c = disort(x-s, y+off);
        
        fill(70,84,170, 255-dist(x,y, mouseX, mouseY)/3);
        
        beginShape();
        duplaspiral(a.x, a.y, b.x, b.y);
        duplaspiral(b.x, b.y, c.x, c.y);
        duplaspiral(c.x, c.y, a.x, a.y);
        endShape();

        }}
    }

PVector disort(float x, float y){
    float erz = 27;
    
    float d = dist(x,y, mouseX, mouseY), dd = sqrt(d)/erz;
    
    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;
 
    float radius = 0, d1 = d/phi, d1log=A*log(d1*B);
    for(var radius = 1; radius < d1; radius++){
            float aa = a+A*log(radius*B)-d1log-PI;
            vertex(x1+sin(aa)*radius, y1+cos(aa)*radius);
    }

    float d2 = d-d/phi, d2log=A*log(d1*B);
    for(var radius = d2; radius > 1; radius--){
            float aa = a+A*log(radius*B)-d1log;
            vertex(x2+sin(aa)*radius, y2+cos(aa)*radius);
    }
}

boolean l = true;
void mousePressed(){
    l=!l;
    if(l) loop();
    else noLoop();
}