Chasing helixes

Dragon's are made of chasing helixes

Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);


// Global code will be evaluated once.
const turtle = new Turtle();
const x1 = -50  // min = -50 max = 50 step = 0.1
const x2 = 50 // min = -50 max = 50 step = 0.1

const r1 = 32 // min = 1 max = 50 step = 0.1
const r2 = 3 // min = 1 max = 50 step = 0.1
//const r3 = 50 // min = 1 max = 50 step = 0.1
const f1 = 1 // min = .1 max = 3 step = 0.01
const f2 = 1 // min = .1 max = 5 step = 0.01
//const f3 = 1 // min = .1 max = 10 step = 0.1
// steps
const s1 = 30 // min = 1 max = 500 step = 1
const s2 = 140 // min = 1 max = 500 step = 1
//const s3 = 75 // min = 1 max = 500 step = 1
const g1 = .1 // min = -.1 max = .1 step = .001
const g2 = .1 // min = -.1 max = .1 step = .001
//const g3 = .1 // min = -2 max = 2 step = .01
const steps = 1000 // min = 1 max = 2000 step = 1
turtle.penup();

class CircleDrawer {
    constructor(cx, cy, f, r, g, theta, steps) {
        this.cx = cx;
        this.cy = cy;
        this.f = f;
        this.r = r;
        this.g = g; // grow
        this.theta = theta; //radians
        this.steps = steps;
    }
    
    getCurrentX() {
        return this.cx + Math.cos(this.theta * this.f) * this.r;
    }
    
    getCurrentY() {
        return this.cy + Math.sin(this.theta * this.f) * this.r;
    }
    
    step() {
        this.theta += Math.PI * 2 / this.steps;
        this.r += this.g
    }
}

let cd1 = new CircleDrawer(x1, 0, f1, r1, g1, 1, s1);
let cd2 = new CircleDrawer(x2, 0, f2, r2, g2, 0, s2);
//let cd3 = new CircleDrawer(0, 0, r3, g3, 0, s3);
for(let i = 0; i < steps; i++) {
    
    let t = i/(steps-1);
    let ti = 1.0 - t; 
    
    let x = ti * cd1.getCurrentX() + t * cd2.getCurrentX();
    let y = ti * cd1.getCurrentY() + t * cd2.getCurrentY();

    turtle.goto(x,y);
    //turtle.goto(cd1.getCurrentX(), cd1.getCurrentY());
    //turtle.goto(cd2.getCurrentX(), cd2.getCurrentY());

     
    //turtle.goto(cd.getCurrentX() + cd2.getCurrentX() + cd3.getCurrentX(), cd.getCurrentY() + cd2.getCurrentX() + cd3.getCurrentX());
    if(i == 0) {
        turtle.pendown();
    }
    cd1.step();
    cd2.step();
    //cd3.step();
}