Canvas.setpenopacity(1);
let R = 17.6;// min=1 max=200 step=0.01
let Rincrease = 2.0;// min=0.0 max=5 step=0.1
let steps = 44;// min=1 max=100 step=1
// Global code will be evaluated once.
const turtle = new Turtle();
turtle.degrees();
turtle.penup();
function circle(x, y, r) {
turtle.setheading(-90);
turtle.jump(x-r, y);
turtle.pendown();
turtle.circle(r);
}
function p(v) {
return [Math.cos(v), Math.sin(v)];
}
function r(a) {
let x = Math.cos(a);
let y = Math.sin(a);
return Math.sqrt((x-1)*(x-1)+y*y);
}
function circleA(a, r1, r2) {
let x = Math.cos(a);
let y = Math.sin(a);
circle(x*r1, y*r1, r2);
}
let cr = R;
let rRad = r(1);
let rRad2 = r(0.5);
circle(0, 0, 0.03*R);
turtle.jump(-cr, 0);
turtle.pendown();
turtle.goto(cr, 0);
circle(0, 0, R);
for (let i=0; i<3; i++) {
let pos = p(i * 1.0);
circle(pos[0]*cr, pos[1]*cr, rRad*cr);
}
circleA(3, cr, rRad2*cr);
let pRad = 3.5;
let pi = Math.acos(-1);
let pStep = pi;
let step = pi-3;
turtle.pendown();
let str = "11.";
function walk(i) {
console.log(`${step} ${pStep} ${pRad}`);
if (pStep < pRad) {
str += "0";
console.log(str);
circleA(pStep, cr, cr*r(step));
pStep += step;
step *= 2;
} else {
str += "1";
console.log(str);
step = pStep - pRad;
turtle.jump(0, 0);
turtle.goto(Math.cos(pRad+0.0)*cr, Math.sin(pRad+0.0)*cr);
//circleA(pRad, cr, cr*rRad2);
pRad = pRad+0.5;
circleA(pStep, cr, cr*r(step));
pStep += step;
step *= 2;
if (pStep >= 2*pi || pRad >= 2*pi) {
pStep -= 2*pi;
pRad -= 2 * pi;
cr += Rincrease*R;
circle(0, 0, cr);
}
}
console.log(`2: ${step} ${pStep} ${pRad}`);
return i < steps;
}