// LL 2021

// Minsky Circle
// As seen at https://www.onirom.fr/ica.html

const steps = 10000; // min=0 max=10000 step=1
const steps_power_ten = 3; // min=0 max=10 step=1

const turtle = new Turtle();

let cx, cy;

const opacity = -0.02; // min=-1 max=1 step=0.01
const scale = 0.2; // min=0 max=2 step=0.01
const ratio = 1; // min=0.5 max=2 step=0.01
const skew = -0.25; // min=-1 max=1 step=0.005
const drift = 0; // min=0 max=10000 step=0.005
const radius = 50; // min=0 max=200 step=1
const shift_x = 2; // min=0 max=100 step=1
const shift_y = 3; // min=0 max=100 step=1
const div_x = 3; // min=0 max=3 step=0.01
const div_y = 2; // min=0 max=3 step=0.01
const integer = 0; // min=0 max=1 step=1 (No,Yes)
const symmetry = 0; // min=0 max=3 step=1 (No,Horizontal,Vertical,Both)

Canvas.setpenopacity(opacity);

function walk(i, t) {
    if (i==0) {
        init(t);
    }
    
    s_dot(cx, cy, i);
    
    if (shift_x > 0 && shift_y > 0) {
        cx += cy >> shift_x;
        cy -= cx >> shift_y;
    }

    if (integer) {
        if (div_x > 0 && div_y > 0) {
            cx += Math.floor(cy / div_x);
            cy -= Math.floor(cx / div_y);
        }
    } else {
        if (div_x > 0 && div_y > 0) {
            cx += cy / div_x;
            cy -= cx / div_y;
        }
    }

    return i < steps * (10 ** steps_power_ten) * (Math.cos(t*t * Math.PI*2) * 0.5 + 0.5);
}

function init(t) {
    cx = 0;
    cy = radius; // + Math.sin(t);
}

function s_dot(x, y, i) {
    const max_r = 0.1, min_r = 0.1, step = 1;
    
    for (var r = max_r; r >= min_r; r -= step) {
        dot(x, y, r, i);

        if (symmetry & 1) {
            dot(-x, y, r, i);
        }
        
        if (symmetry & 2) {
            dot(x, -y, r, i);
        }
        
        if ((symmetry & 3) == 3) {
            dot(-x, -y, r, i);
        }
    }
}

function dot(x, y, r, i) {
    x += y * -skew;
    x *= scale;
    y *= scale / ratio;
    y += i * drift / 1000000;
    if (Math.abs(x-r) <= 100 && Math.abs(y-r) <= 100) {
        turtle.jump(x, y-r);
        turtle.circle(r);
    }
}