Gas Ballon
Mesh Touching Sinusoidal Waves
Log in to post a comment.
// Turtletoy is a community for creative coding. We believe the joy
// is in the craft. I love the joy :), but OGT AI helping ;)
// API Reference: https://turtletoy.net/syntax
// ToDo: Project on sphere and rotate
Canvas.setpenopacity(1);
const turtle = new Turtle();
turtle.penup();
const R = 100; // min=50, max=100, step=1 // radius of the outer circle
const Ri = 1.5; // min=-1, max=50, step=1 // radius of the inner circle
const waves = 12; // number of sinus waves around
const amp = 10; // wave amplitude
const steps = 720; // smoothness
const rings = 12; // min=3, max=20, step=1
// -------------------------
// mesh (latitude lines)
// -------------------------
/*for (let j = 1; j < rings; j++) {
const rr = R * j / rings;
const rr2 = R * (j + 1) / rings;
turtle.goto(rr, 0);
turtle.pendown();
for (let i = 0; i <= steps; i++) {
const a = i * 2 * Math.PI / steps;
const r =
rr +
amp * Math.sin(waves * a) * (rr / R);
const x = r * Math.cos(a);
const y = r * Math.sin(a);
turtle.goto(x, y);
}
for (let i = 0; i <= steps; i++) {
const a = i * 2 * Math.PI / steps;
const r =
rr + amp * Math.cos(waves * a + Math.PI/2)
* (rr / R)
;
const x = r * Math.cos(a);
const y = r * Math.sin(a);
turtle.goto(x, y);
}
turtle.penup();
}*/
const dr = R / rings;
for (let j = 1; j < rings; j++) {
const rr = dr * j + Ri;
// half-distance rule
const A_out = dr / 2;
const A_in = dr / 2;
turtle.penup();
turtle.goto(rr, 0);
turtle.pendown();
// primary wave
for (let i = 0; i <= steps; i++) {
const a = i * 2 * Math.PI / steps;
const s = Math.sin(waves * a);
const r =
rr
+ A_out * Math.max(0, s)
- A_in * Math.max(0, -s);
turtle.goto(
r * Math.cos(a),
r * Math.sin(a)
);
}
// phase-shifted wave (mesh)
for (let i = 0; i <= steps; i++) {
const a = i * 2 * Math.PI / steps;
const s = Math.cos(waves * a + Math.PI/2);
const r =
rr
+ A_out * Math.max(0, s)
- A_in * Math.max(0, -s);
turtle.goto(
r * Math.cos(a),
r * Math.sin(a)
);
}
turtle.penup();
}