mirror of
https://github.com/SamEyeBam/animate.git
synced 2025-09-28 06:55:25 +00:00
Solved the npoly twist equation. works for n sides greater than 3
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<html>
|
||||
<!-- ahhh -->
|
||||
|
||||
<body style="margin:0;overflow: hidden;">
|
||||
<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>
|
||||
@@ -29,8 +29,8 @@
|
||||
render();
|
||||
render_clear();
|
||||
|
||||
DrawTriangleTwist_angle(400,0,rotation,"red")
|
||||
// DrawTriangleTwist_width(400,0,rotation,"red")
|
||||
// DrawTriangleTwist_angle(400,0,rotation,"red")
|
||||
DrawTriangleTwist_width(400,0,rotation,"red")
|
||||
|
||||
}, 1000 / fps);
|
||||
rotation += deg_per_sec / fps; // was = j = innerRotation, now = rotation
|
||||
@@ -41,9 +41,10 @@
|
||||
render();
|
||||
|
||||
|
||||
function DrawTriangleTwist_width(width, rotation,innerRotation, colour){
|
||||
|
||||
let widthMultiplier = 1 / (2 * Math.sin(Math.PI / 180 * (150 - innerRotation + 120 * Math.floor(innerRotation / 120))))
|
||||
function DrawTriangleTwist_angle(width, rotation,innerRotation, colour){
|
||||
let out_angle = innerRotation;
|
||||
// let widthMultiplier = 1 / (2 * Math.sin(Math.PI / 180 * (150 - innerRotation + 120 * Math.floor(innerRotation / 120))))
|
||||
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+innerRotation*i,width*widthMultiplier**i, colour)
|
||||
@@ -51,7 +52,7 @@
|
||||
|
||||
}
|
||||
|
||||
function DrawTriangleTwist_angle(width, rotation,innerRotation, colour){
|
||||
function DrawTriangleTwist_width(width, rotation,innerRotation, colour){
|
||||
let out_angle = 0
|
||||
let innerAngle = innerRotation - (120*Math.floor(innerRotation/120));
|
||||
|
||||
@@ -62,7 +63,7 @@
|
||||
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))))
|
||||
let widthMultiplier = 1 / (2 * Math.sin(Math.PI / 180 * (150 - out_angle + 120 * Math.floor(out_angle / 120)))) //150 = 90+innerangle/2
|
||||
|
||||
for (let i = 0; i < 25; i++) {
|
||||
draw_triangle(180+out_angle*i,width*widthMultiplier**i, colour)
|
||||
@@ -70,9 +71,6 @@
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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);
|
||||
|
Reference in New Issue
Block a user