catalogued triangle twist

This commit is contained in:
Sam
2022-03-16 19:33:42 +13:00
parent 70421f763f
commit ec6314dae2
8 changed files with 325 additions and 365 deletions

View File

@@ -0,0 +1,97 @@
<!DOCTYPE html>
<html>
<!-- ahhh -->
<body style="margin: 0; overflow: hidden">
<canvas
id="myCanvas"
width="10"
height="10"
style="display: block; box-sizing: border-box"
>
Your browser does not support the HTML5 canvas tag.</canvas
>
<script>
let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
let deg_per_sec = 30;
let time = 120;
let fps = 60;
centerX = ctx.canvas.width / 2;
centerY = ctx.canvas.height / 2;
rotation = 0; //was = j = angle
currentFrame = 0; //was = i
function render() {
if (currentFrame < time / (1 / fps)) {
setTimeout(() => {
render();
render_clear();
draw_shape_fill(4, 200, rotation, centerX, centerY, "blue")
}, 1000 / fps);
rotation += deg_per_sec / fps; // was = j = angle, now = rotation
currentFrame += 1; // was = i
}
}
render();
function draw_shape_fill(sides, radius, rotation, x, y, colour) {
var rot = Math.round((((sides - 2) * 180) / sides) * 2);
var piv = 360 / sides;
var stt = 0.5 * Math.PI - rad(rot) + rad(rotation);
var end = 0;
var n = radius / ((radius / 10) * (radius / 10)); //pixel correction for mid leaf
for (let i = 1; i < sides + 1; i++) {
end = stt + rad(rot);
ctx.beginPath();
ctx.arc(
x + Math.cos(rad(90 + piv * i + rotation)) * radius,
y + Math.sin(rad(90 + piv * i + rotation)) * radius,
radius,
stt - (stt - end) / 2,
end + rad(n),
0
);
ctx.fillStyle = colour;
ctx.fill();
ctx.beginPath();
ctx.arc(
x + Math.cos(rad(90 + piv * i + rotation)) * radius,
y + Math.sin(rad(90 + piv * i + rotation)) * radius,
radius,
stt,
end - (end - stt) / 2 + rad(n),
0
);
ctx.fillStyle = colour;
ctx.fill();
stt = end + -rad(rot - piv); //+rad(30);
}
}
function rad(degrees) {
var pi = Math.PI;
return degrees * (pi / 180);
}
function render_clear() {
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
}
</script>
</body>
</html>

122
Catalogue/foral sub.html Normal file
View File

@@ -0,0 +1,122 @@
<!DOCTYPE html>
<html>
<!-- ahhh -->
<body style="margin: 0;">
<canvas
id="myCanvas"
width="10"
height="10"
style="display: block; box-sizing: border-box"
>
Your browser does not support the HTML5 canvas tag.</canvas
>
<script>
let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
let deg_per_sec = 30;
let time = 120;
let fps = 60;
centerX = ctx.canvas.width / 2;
centerY = ctx.canvas.height / 2;
rotation = 0; //was = j = angle
currentFrame = 0; //was = i
function render() {
if (currentFrame < time / (1 / fps)) {
setTimeout(() => {
render();
render_clear();
draw_floral(11, 200, rotation *0, centerX, centerY, "red"); //used as an example
draw_shape_sub(11, 200, 0, centerX, centerY, "blue");
}, 1000 / fps);
rotation += deg_per_sec / fps; // was = j = angle, now = rotation
currentFrame += 1; // was = i
}
}
render();
function draw_shape_sub(sides, radius, rotation, x, y, colour) {
var denominator = sides - 2;
//var rot = Math.round((sides - 2) * 180 / sides * 2)
var rot =
Math.round((((sides - 2) * 180) / sides) * 2) * (1 / denominator);
var piv = 360 / sides;
var l = 1;
var stt = 0.5 * Math.PI - rad(rot) * l + rad(rotation);
var end = 0;
for (let i = 1; i < sides + 1; i++) {
end = stt + rad(rot);
ctx.beginPath();
ctx.arc(
x + Math.cos(rad(90 + piv * i + rotation)) * radius,
y + Math.sin(rad(90 + piv * i + rotation)) * radius,
radius,
stt,
end,
0
);
ctx.strokeStyle = colour;
ctx.stroke();
ctx.beginPath();
ctx.arc(
x + Math.cos(rad(90 + piv * i + rotation)) * radius,
y + Math.sin(rad(90 + piv * i + rotation)) * radius,
radius,
stt - rad(rot) * l,
end - rad(rot) * l,
0
);
ctx.strokeStyle = colour;
ctx.stroke();
stt = end + -rad(rot - piv); //+rad(30);
}
}
function draw_floral(sides, radius, rotation, x, y, colour) {
var rot = Math.round((((sides - 2) * 180) / sides) * 2);
var piv = 360 / sides;
var stt = 0.5 * Math.PI - rad(rot) + rad(rotation);
var end = 0;
for (let i = 1; i < sides + 1; i++) {
end = stt + rad(rot);
ctx.beginPath();
ctx.arc(
x + Math.cos(rad(90 + piv * i + rotation)) * radius,
y + Math.sin(rad(90 + piv * i + rotation)) * radius,
radius,
stt,
end,
0
);
ctx.strokeStyle = colour;
ctx.stroke();
stt = end + -rad(rot - piv); //+rad(30);
}
}
function rad(degrees) {
var pi = Math.PI;
return degrees * (pi / 180);
}
function render_clear() {
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
}
</script>
</body>
</html>

View File

@@ -34,7 +34,7 @@
let colour1 = [137, 54, 255];
let colour2 = [158, 255, 54];
// Draw_nodal_expanding(5, 100000, rotation * 2 + 33000,0, colour1, colour2, 0.5, 2)
Draw_nodal_expanding(5, 10000, rotation+33000, 0, colour1, colour2, 1, 1)
Draw_nodal_expanding(5, 10000, rotation+33000, 0, colour1, colour2, 1, 2)
}, 1000 / fps);
rotation += deg_per_sec / fps; // was = j = angle, now = rotation

View File

@@ -0,0 +1,102 @@
<!DOCTYPE html>
<html>
<!-- ahhh -->
<body style="margin:0;overflow: hidden;">
<canvas id="myCanvas" width="10" height="10"
style="display: block;box-sizing: border-box;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
let deg_per_sec = 30;
let time = 120;
let fps = 60;
centerX = ctx.canvas.width / 2;
centerY = ctx.canvas.height / 2;
rotation = 0; //was = j = angle
currentFrame = 0; //was = i
function render() {
if (currentFrame < time / (1 / fps)) {
setTimeout(() => {
render();
render_clear();
DrawTriangleTwist_angle(400,0,rotation,"red")
// DrawTriangleTwist_width(400,0,rotation,"red")
}, 1000 / fps);
rotation += deg_per_sec / fps; // was = j = innerRotation, now = rotation
currentFrame += 1; // was = i
}
}
render();
function DrawTriangleTwist_width(width, rotation,innerRotation, colour){
let widthMultiplier = 1 / (2 * Math.sin(Math.PI / 180 * (150 - innerRotation + 120 * Math.floor(innerRotation / 120))))
for (let i = 0; i < 25; i++) {
draw_triangle(180+innerRotation*i,width*widthMultiplier**i, colour)
}
}
function DrawTriangleTwist_angle(width, rotation,innerRotation, colour){
let out_angle = 0
let innerAngle = innerRotation - (120*Math.floor(innerRotation/120));
if (innerAngle < 60) {
out_angle = 120 / (2 * Math.cos(rad(innerAngle))) - 60
}
else {
out_angle = -120 / (2 * Math.cos(2 * Math.PI / 3 - (innerAngle * Math.PI / 180))) + 180
}
let widthMultiplier = 1 / (2 * Math.sin(Math.PI / 180 * (150 - out_angle + 120 * Math.floor(out_angle / 120))))
for (let i = 0; i < 25; i++) {
draw_triangle(180+out_angle*i,width*widthMultiplier**i, colour)
}
}
function draw_triangle(ang, radius, colour) {
ctx.beginPath();
ctx.moveTo(centerX + Math.cos(rad(90 + 120 * 1 + ang)) * radius, centerY + Math.sin(rad(90 + 120 * 1 + ang)) * radius);
ctx.lineTo(centerX + Math.cos(rad(90 + 120 * 2 + ang)) * radius, centerY + Math.sin(rad(90 + 120 * 2 + ang)) * radius);
ctx.lineTo(centerX + Math.cos(rad(90 + 120 * 3 + ang)) * radius, centerY + Math.sin(rad(90 + 120 * 3 + ang)) * radius);
ctx.lineTo(centerX + Math.cos(rad(90 + 120 * 1 + ang)) * radius, centerY + Math.sin(rad(90 + 120 * 1 + ang)) * radius);
ctx.strokeStyle = colour;
ctx.stroke();
}
function rad(degrees) {
var pi = Math.PI;
return degrees * (pi / 180);
}
function render_clear() {
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
}
</script>
</body>
</html>

View File

@@ -28,7 +28,7 @@
render();
render_clear();
draw_triangle(0, 200)
draw_triangle(0, 200, "red");
}, 1000 / fps);
rotation += deg_per_sec / fps; // was = j = angle, now = rotation
@@ -38,13 +38,13 @@
render();
function draw_triangle(ang, radius) {
function draw_triangle(ang, radius, colour) {
ctx.beginPath();
ctx.moveTo(centerX + Math.cos(rad(90 + 120 * 1 + ang)) * radius, centerY + Math.sin(rad(90 + 120 * 1 + ang)) * radius);
ctx.lineTo(centerX + Math.cos(rad(90 + 120 * 2 + ang)) * radius, centerY + Math.sin(rad(90 + 120 * 2 + ang)) * radius);
ctx.lineTo(centerX + Math.cos(rad(90 + 120 * 3 + ang)) * radius, centerY + Math.sin(rad(90 + 120 * 3 + ang)) * radius);
ctx.lineTo(centerX + Math.cos(rad(90 + 120 * 1 + ang)) * radius, centerY + Math.sin(rad(90 + 120 * 1 + ang)) * radius);
ctx.strokeStyle = "red";
ctx.strokeStyle = colour;
ctx.stroke();
}