Nucleotide
Elipses and lines spirally
Log in to post a comment.
Canvas.setpenopacity(-1)
const turtle = new Turtle();
const steps = 34; // min=5 max=40 step=1 helix elements
const helixWidth = 37; // min=5 max=80 step=1 helix width
const shapeW = 24; // min=2 max=30 step=1 structure width
const shapeH = 11; // min=1 max=15 step=1 structure height
const turns = 1; // min=1 max=6 step=1 structure peaks
const cos = a => Math.cos(a * Math.PI / 180);
const sin = a => Math.sin(a * Math.PI / 180);
function drawEllipse(cx, cy, w, h, rot){
const segments = 36;
turtle.jump(
cx + cos(rot) * w,
cy + sin(rot) * h
);
for (let i = 1; i <= segments; i++){
const a = rot + (i / segments) * 360;
const px = cx + cos(a) * w * cos(rot) - sin(a) * h * sin(rot);
const py = cy + cos(a) * w * sin(rot) + sin(a) * h * cos(rot);
turtle.goto(px, py);
}
}
function drawLine(cx, cy, w, rot){
turtle.jump(cx + cos(rot) * w, cy + sin(rot) * w);
turtle.goto(cx - cos(rot) * w, cy - sin(rot) * w);
}
const totalAngle = turns * 360;
for (let i = 0; i < steps; i++){
const t = i / (steps - 1);
const y = -90 + t * 180; // vertically distributed
const rot = t * totalAngle;
const x = cos(rot) * helixWidth; // horizontally distributed
drawEllipse(x, y, shapeW, shapeH, rot);
drawLine(x, y, shapeW * 0.6, rot + 90);
}