n-dimension volume of packed center sphere related to the spiral of theodorus (sqrt(n)-1)
click to change
let n = 500;
let triangles = [];
let theta, unit, w;
let t = 0;
let cnv;
function setup() {
w = min(windowWidth, windowHeight) * 0.9;
cnv = createCanvas(w, w);
background(200);
intitializeTriangles(20);
describe(
"over 500 triangles of the spiral of theodorus done in a way so the smallest are on top with a darker gradient on the outermost triangles. Next there are dots noting the corner of the triangle minus one with a circle drawn from the center through that dot, but obscured by some of the triangles laying on top. It looks like a spiral of dots, a white band of a spiral, then circular lines that get closer and closer towards the edge with a bluish hue. The spiral is constructed by starting with a right triangle that has a base and height of 1. Then making a triangle from the corner of the hypotenuse out by 1 at 90 degrees and then to the center. this process is repeated so the hypotenuses grow in the pattern of square root of 2, sqrt(3), sqrt(4), sqrt(5), etc. The zoom varies when the mouse is pressed."
);
}
function draw() {
background(255);
translate(w / 2, w / 2);
fill(255);
for (let i = n - 3; i >= 0; i--) {
fill(255 - i / 3, 255 - i / 4, 255 - i / 5);
stroke(100);
strokeWeight(0.1);
triangle(
triangles[i].pt1.x,
triangles[i].pt1.y,
triangles[i].pt2.x,
triangles[i].pt2.y,
triangles[i].pt3.x,
triangles[i].pt3.y
);
strokeWeight(0.5);
fill(i / 5);
circle(
triangles[i].r * cos(triangles[i].theta),
triangles[i].r * sin(triangles[i].theta),
3
);
noFill();
strokeWeight(0.1);
stroke(105 - i / 3, 105 - i / 4, 105 - i / 5);
circle(0, 0, triangles[i].r * 2);
}
}
function intitializeTriangles(d) {
unit = w / d;
r1 = sqrt(2);
r = (r1 - 1) * unit;
triangles[0] = {
pt1: { x: unit, y: 0 },
pt2: { x: unit, y: unit },
pt3: { x: 0, y: 0 },
theta: asin(abs(1 / sqrt(2))),
n: 2,
r: (sqrt(2) - 1) * unit
};
for (let i = 3; i < n; i++) {
let r1 = sqrt(i);
let r2 = sqrt(i - 1) * unit;
theta1 = triangles[i - 3].theta + asin(1 / r1);
let r = (r1 - 1) * unit;
triangles[i - 2] = {
pt1: {
x: r2 * cos(triangles[i - 3].theta),
y: r2 * sin(triangles[i - 3].theta)
},
pt2: { x: r1 * unit * cos(theta1), y: r1 * unit * sin(theta1) },
pt3: { x: 0, y: 0 },
theta: theta1,
n: 2,
r: r
};
}
}
function mousePressed() {
intitializeTriangles(int(random(5, 80)));
}
function keyPressed() {
if (keyCode === 83) {
save(cnv, "nD", "png");
}
}