mirror of
https://github.com/SamEyeBam/animate.git
synced 2025-09-27 22:45:25 +00:00
Worked on overlay
This commit is contained in:
@@ -22,15 +22,21 @@
|
||||
rotation = 0; //was = j = angle
|
||||
currentFrame = 0; //was = i
|
||||
|
||||
let depth = 300 //custom to npoly twist
|
||||
|
||||
function render() {
|
||||
if (currentFrame < time / (1 / fps)) {
|
||||
setTimeout(() => {
|
||||
render();
|
||||
render_clear();
|
||||
|
||||
colour1 = [255, 0, 0];
|
||||
colour2 = [0, 0, 0];
|
||||
|
||||
DrawPolyTwist_width(3,400,-90,rotation,"red")
|
||||
// DrawSquareTwist_angle(3,400,0,rotation,"red")
|
||||
DrawPolyTwistColour_angle(15,400,-90,rotation/20,colour1, colour2)
|
||||
// DrawPolyTwist_angle(15,400,-90,rotation/20,"red")
|
||||
// DrawPolyTwistColour_width(4,400,-45,rotation/4,colour1,colour2)
|
||||
// DrawPolyTwist_width(10,400,-90,rotation/20,"red")
|
||||
|
||||
}, 1000 / fps);
|
||||
rotation += deg_per_sec / fps; // was = j = innerRotation, now = rotation
|
||||
@@ -41,15 +47,17 @@
|
||||
render();
|
||||
|
||||
|
||||
function DrawSquareTwist_angle(sides,width, rotation,innerRotation, colour){
|
||||
function DrawPolyTwist_angle(sides,width, rotation,innerRotation, colour){
|
||||
let out_angle = innerRotation;
|
||||
// let widthMultiplier = 169 / (239 * Math.sin(Math.PI / 180 * (135 - out_angle + 90 * Math.floor(out_angle / 90))))
|
||||
// let widthMultiplier = Math.sqrt(0.5) * 1/ (Math.sin(Math.PI / 180 * (135 - out_angle + 90 * Math.floor(out_angle / 90))))
|
||||
let widthMultiplier = Math.sqrt(0.5) * 1/ (Math.sin(Math.PI / 180 * (135 - out_angle + 90 * Math.floor(out_angle / 90))))
|
||||
let innerAngle = 180 - ((sides-2) *180/sides);
|
||||
let minWidth = Math.sin(rad(innerAngle/2))*(0.5/Math.tan(rad(innerAngle/2)))*2;
|
||||
|
||||
let widthMultiplier = minWidth / Math.sin(Math.PI / 180 * (90+innerAngle/2 - out_angle + innerAngle * Math.floor(out_angle / innerAngle)))
|
||||
|
||||
for (let i = 0; i < 25; i++) {
|
||||
for (let i = 0; i < depth; i++) {
|
||||
DrawPolygon(sides,width*widthMultiplier**i,innerRotation*i, colour)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function DrawPolyTwist_width(sides,width, rotation,innerRotation, colour){
|
||||
@@ -67,11 +75,57 @@
|
||||
|
||||
let widthMultiplier = minWidth / Math.sin(Math.PI / 180 * (90+innerAngle/2 - out_angle + innerAngle * Math.floor(out_angle / innerAngle)))
|
||||
|
||||
for (let i = 0; i < 25; i++) {
|
||||
for (let i = 0; i < depth; i++) {
|
||||
DrawPolygon(sides,width*widthMultiplier**i,out_angle*i+rotation, colour)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function DrawPolyTwistColour_angle(sides,width, rotation,innerRotation,colour1,colour2){
|
||||
let out_angle = innerRotation;
|
||||
let innerAngle = 180 - ((sides-2) *180/sides);
|
||||
let minWidth = Math.sin(rad(innerAngle/2))*(0.5/Math.tan(rad(innerAngle/2)))*2;
|
||||
|
||||
let widthMultiplier = minWidth / Math.sin(Math.PI / 180 * (90+innerAngle/2 - out_angle + innerAngle * Math.floor(out_angle / innerAngle)))
|
||||
|
||||
for (let i = 0; i < depth; i++) {
|
||||
let fraction = i/depth;
|
||||
// let fraction = Math.cos(rad(i / 2));
|
||||
// let fraction = (-1*(i-depth)**2)/depth**2+1
|
||||
let ncolour = LerpRGB(colour1,colour2,fraction);
|
||||
// let ncolour = LerpRGB(colour1,colour2,((i-depth)**2)/depth**2);
|
||||
|
||||
DrawPolygon(sides,width*widthMultiplier**i,out_angle*i+rotation, colourToText(ncolour))
|
||||
}
|
||||
}
|
||||
|
||||
function DrawPolyTwistColour_width(sides,width, rotation,innerRotation, colour1,colour2){
|
||||
let out_angle = 0
|
||||
let innerAngle = 180 - ((sides-2) *180/sides);
|
||||
let scopeAngle = innerRotation - (innerAngle*Math.floor(innerRotation/innerAngle));
|
||||
|
||||
if (scopeAngle < innerAngle/2) {
|
||||
out_angle = innerAngle / (2 * Math.cos((2*Math.PI*scopeAngle)/(3*innerAngle))) - innerAngle/2
|
||||
}
|
||||
else {
|
||||
out_angle = -innerAngle / (2 * Math.cos( ((2*Math.PI)/3) - ((2*Math.PI*scopeAngle)/(3*innerAngle))) ) + (innerAngle*3)/2
|
||||
}
|
||||
let minWidth = Math.sin(rad(innerAngle/2))*(0.5/Math.tan(rad(innerAngle/2)))*2;
|
||||
|
||||
let widthMultiplier = minWidth / Math.sin(Math.PI / 180 * (90+innerAngle/2 - out_angle + innerAngle * Math.floor(out_angle / innerAngle)))
|
||||
|
||||
for (let i = 0; i < depth; i++) {
|
||||
// let ncolour = LerpRGB(colour1,colour2,i/depth);
|
||||
let fraction = i/depth;
|
||||
// let fraction = Math.cos(rad(i / 2));
|
||||
// let fraction = (-1*(i-depth)**2)/depth**2+1
|
||||
let ncolour = LerpRGB(colour1,colour2,fraction);
|
||||
// let ncolour = LerpRGB(colour1,colour2,((i-depth)**2)/depth**2);
|
||||
|
||||
DrawPolygon(sides,width*widthMultiplier**i,out_angle*i+rotation, colourToText(ncolour))
|
||||
}
|
||||
}
|
||||
|
||||
function DrawPolygon(sides, width, rotation, colour) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo (centerX + width * Math.cos(rotation*Math.PI/180), centerY + width * Math.sin(rotation*Math.PI/180));
|
||||
@@ -95,6 +149,22 @@
|
||||
return degrees * (pi / 180);
|
||||
}
|
||||
|
||||
function colourToText(colour) {
|
||||
return "rgb(" + colour[0] + "," + colour[1] + "," + colour[2] + ")"
|
||||
}
|
||||
|
||||
function LerpRGB(a, b, t) {
|
||||
if (t < 0) {
|
||||
t *= -1;
|
||||
}
|
||||
var newColor = [0, 0, 0];
|
||||
newColor[0] = a[0] + (b[0] - a[0]) * t;
|
||||
newColor[1] = a[1] + (b[1] - a[1]) * t;
|
||||
newColor[2] = a[2] + (b[2] - a[2]) * t;
|
||||
return newColor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function render_clear() {
|
||||
|
Reference in New Issue
Block a user