2023-03-21 05:23:52 +00:00
|
|
|
class BaseShape {
|
|
|
|
constructor() {
|
|
|
|
this.controls = []; // Keep track of created elements and event listeners
|
2023-04-17 06:10:38 +00:00
|
|
|
this.speedMultiplier = 100;
|
2023-03-21 05:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initialise(config) {
|
|
|
|
for (let item of config) {
|
2023-04-07 23:20:14 +00:00
|
|
|
const { element, listener } = addControl(item, this);
|
2023-03-21 05:23:52 +00:00
|
|
|
this.controls.push({ element, listener });
|
|
|
|
}
|
2023-04-29 07:27:11 +00:00
|
|
|
|
2023-05-04 07:20:19 +00:00
|
|
|
const { element, listener } = addControl({ type: "range", min: 1, max: 500, defaultValue: 100, property: "speedMultiplier", }, this);
|
2023-04-17 06:10:38 +00:00
|
|
|
this.controls.push({ element, listener });
|
2023-03-21 05:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
remove() {
|
|
|
|
this.controls.forEach(({ element, listener }) => {
|
|
|
|
if (element && listener) {
|
|
|
|
element.removeEventListener("input", listener);
|
|
|
|
}
|
|
|
|
if (element && element.parentElement) {
|
|
|
|
element.parentElement.removeChild(element);
|
2023-05-04 07:20:19 +00:00
|
|
|
const titleElement = document.getElementById("elText" + element.id.slice(2));
|
2023-03-21 05:23:52 +00:00
|
|
|
titleElement.parentElement.removeChild(titleElement);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.controls = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
draw() {
|
|
|
|
throw new Error("Draw function not implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class PolyTwistColourWidth extends BaseShape {
|
2023-05-04 07:20:19 +00:00
|
|
|
constructor(sides, width, line_width, depth, rotation, speedMultiplier, colour1, colour2) {
|
2023-03-21 05:23:52 +00:00
|
|
|
super();
|
|
|
|
this.sides = sides;
|
|
|
|
this.width = width;
|
2023-04-17 06:10:38 +00:00
|
|
|
this.line_width = line_width;
|
2023-03-21 05:23:52 +00:00
|
|
|
this.depth = depth;
|
|
|
|
this.rotation = rotation;
|
2023-04-17 06:10:38 +00:00
|
|
|
this.speedMultiplier = speedMultiplier;
|
2023-03-21 05:23:52 +00:00
|
|
|
this.colour1 = colour1;
|
|
|
|
this.colour2 = colour2;
|
|
|
|
}
|
|
|
|
|
2023-04-17 06:10:38 +00:00
|
|
|
draw(rotation) {
|
2023-05-04 07:20:19 +00:00
|
|
|
rotation *= (this.speedMultiplier / 100)
|
2023-03-21 05:23:52 +00:00
|
|
|
let out_angle = 0;
|
|
|
|
const innerAngle = 180 - ((this.sides - 2) * 180) / this.sides;
|
2023-05-04 07:20:19 +00:00
|
|
|
const scopeAngle = rotation - (innerAngle * Math.floor(rotation / innerAngle));
|
2023-03-21 05:23:52 +00:00
|
|
|
|
|
|
|
if (scopeAngle < innerAngle / 2) {
|
2023-05-04 07:20:19 +00:00
|
|
|
out_angle = innerAngle / (2 * Math.cos((2 * Math.PI * scopeAngle) / (3 * innerAngle))) - innerAngle / 2;
|
2023-03-21 05:23:52 +00:00
|
|
|
} else {
|
2023-05-04 07:20:19 +00:00
|
|
|
out_angle = -innerAngle / (2 * Math.cos(((2 * Math.PI) / 3) - ((2 * Math.PI * scopeAngle) / (3 * innerAngle)))) + (innerAngle * 3) / 2;
|
2023-03-21 05:23:52 +00:00
|
|
|
}
|
2023-05-04 07:20:19 +00:00
|
|
|
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)));
|
2023-03-21 05:23:52 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < this.depth; i++) {
|
|
|
|
const fraction = i / this.depth;
|
|
|
|
const ncolour = LerpHex(this.colour1, this.colour2, fraction);
|
2023-05-04 07:20:19 +00:00
|
|
|
DrawPolygon(this.sides, this.width * widthMultiplier ** i, out_angle * i + this.rotation, ncolour, this.line_width);
|
2023-03-21 05:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class FloralPhyllo extends BaseShape {
|
|
|
|
constructor(width, depth, colour1, colour2) {
|
|
|
|
super();
|
|
|
|
this.width = width;
|
|
|
|
this.depth = depth;
|
|
|
|
this.colour1 = colour1;
|
|
|
|
this.colour2 = colour2;
|
2023-04-17 06:10:38 +00:00
|
|
|
this.speedMultiplier = 500;
|
2023-03-21 05:23:52 +00:00
|
|
|
}
|
|
|
|
|
2023-04-17 06:10:38 +00:00
|
|
|
draw(rotation) {
|
2023-05-04 07:20:19 +00:00
|
|
|
rotation *= (this.speedMultiplier / 100)
|
2023-03-21 05:23:52 +00:00
|
|
|
// var c = 24; //something to do with width. but not width
|
|
|
|
var c = 1; //something to do with width. but not width
|
|
|
|
//dont make larger than 270 unless altering the number of colours in lerpedColours
|
|
|
|
for (let n = 200; n > 0; n -= 1) {
|
2023-04-17 06:10:38 +00:00
|
|
|
// let ncolour = LerpHex(this.colour1, this.colour2, n);
|
2023-05-04 07:20:19 +00:00
|
|
|
const a = n * rotation / 1000; //137.5;
|
2023-03-21 05:23:52 +00:00
|
|
|
const r = c * Math.sqrt(n);
|
|
|
|
const x = r * Math.cos(a) + centerX;
|
|
|
|
const y = r * Math.sin(a) + centerY;
|
|
|
|
|
2023-04-17 06:10:38 +00:00
|
|
|
drawEyelid(n * 2.4 + 40, x, y, ncolour);
|
2023-03-21 05:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class Spiral1 extends BaseShape {
|
2023-04-07 23:20:14 +00:00
|
|
|
constructor(sides, width, colour) {
|
2023-03-21 05:23:52 +00:00
|
|
|
super();
|
|
|
|
this.sides = sides;
|
|
|
|
this.width = width;
|
|
|
|
this.colour = colour;
|
|
|
|
}
|
|
|
|
|
|
|
|
draw(rotation) {
|
2023-05-04 07:20:19 +00:00
|
|
|
rotation *= (this.speedMultiplier / 100)
|
|
|
|
var rot = Math.round((this.sides - 2) * 180 / this.sides * 2)
|
2023-03-21 05:23:52 +00:00
|
|
|
var piv = 360 / this.sides;
|
2023-05-04 07:20:19 +00:00
|
|
|
var stt = 0.5 * Math.PI - rad(rot) //+ rad(rotation);
|
2023-03-21 05:23:52 +00:00
|
|
|
var end = 0;
|
2023-05-04 07:20:19 +00:00
|
|
|
var n = this.width / ((this.width / 10) * (this.width / 10)) //pixel correction for mid leaf
|
2023-03-21 05:23:52 +00:00
|
|
|
|
|
|
|
for (let i = 1; i < this.sides + 1; i++) {
|
|
|
|
end = stt + rad(rot);
|
|
|
|
|
|
|
|
ctx.beginPath();
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.arc(centerX + Math.cos(rad(90 + piv * i + rotation)) * this.width, centerY + Math.sin(rad(90 + piv * i + rotation)) * this.width, this.width, stt + rad(rotation) - (stt - end) / 2, end + rad(rotation) + rad(n), 0);
|
2023-03-21 05:23:52 +00:00
|
|
|
ctx.strokeStyle = this.colour;
|
|
|
|
ctx.stroke();
|
|
|
|
|
2023-05-04 07:20:19 +00:00
|
|
|
|
2023-03-21 05:23:52 +00:00
|
|
|
ctx.beginPath();
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.arc(centerX + Math.cos(rad(90 + piv * i - rotation)) * this.width, centerY + Math.sin(rad(90 + piv * i - rotation)) * this.width, this.width, stt - rad(rotation), end - (end - stt) / 2 + rad(n) - rad(rotation), 0);
|
2023-03-21 05:23:52 +00:00
|
|
|
ctx.strokeStyle = this.colour;
|
|
|
|
ctx.stroke();
|
|
|
|
|
2023-05-04 07:20:19 +00:00
|
|
|
|
|
|
|
stt = end + -(rad(rot - piv)) //+rad(30);
|
2023-03-21 05:23:52 +00:00
|
|
|
}
|
2023-05-04 07:20:19 +00:00
|
|
|
|
2023-03-21 05:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-21 06:08:08 +00:00
|
|
|
class FloralAccident extends BaseShape {
|
2023-04-07 23:20:14 +00:00
|
|
|
constructor(sides, width, colour) {
|
2023-03-21 06:08:08 +00:00
|
|
|
super();
|
|
|
|
this.sides = sides;
|
|
|
|
this.width = width;
|
|
|
|
this.colour = colour;
|
|
|
|
}
|
|
|
|
|
|
|
|
draw(rotation) {
|
2023-05-04 07:20:19 +00:00
|
|
|
rotation *= (this.speedMultiplier / 100)
|
|
|
|
var rot = Math.round((this.sides - 2) * 180 / this.sides * 2)
|
2023-03-21 06:08:08 +00:00
|
|
|
var piv = 360 / this.sides;
|
2023-05-04 07:20:19 +00:00
|
|
|
var stt = 0.5 * Math.PI - rad(rot) //+ rad(rotation);
|
2023-03-21 06:08:08 +00:00
|
|
|
var end = 0;
|
2023-05-04 07:20:19 +00:00
|
|
|
var n = this.width / ((this.width / 10) * (this.width / 10)) //pixel correction for mid leaf
|
2023-03-21 06:08:08 +00:00
|
|
|
|
|
|
|
for (let i = 1; i < this.sides + 1; i++) {
|
|
|
|
end = stt + rad(rot);
|
|
|
|
|
|
|
|
ctx.beginPath();
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.arc(centerX + Math.cos(rad(90 + piv * i + rotation)) * this.width, centerY + Math.sin(rad(90 + piv * i + rotation)) * this.width, this.width, stt - (stt - end + rad(rotation)) / 2, end + rad(n), 0);
|
2023-03-21 06:08:08 +00:00
|
|
|
ctx.strokeStyle = this.colour;
|
|
|
|
ctx.stroke();
|
|
|
|
|
2023-05-04 07:20:19 +00:00
|
|
|
|
2023-03-21 06:08:08 +00:00
|
|
|
ctx.beginPath();
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.arc(centerX + Math.cos(rad(90 + piv * i - rotation)) * this.width, centerY + Math.sin(rad(90 + piv * i - rotation)) * this.width, this.width, stt, end - (end - stt - rad(rotation)) / 2 + rad(n), 0);
|
2023-03-21 06:08:08 +00:00
|
|
|
ctx.strokeStyle = this.colour;
|
|
|
|
ctx.stroke();
|
|
|
|
|
2023-05-04 07:20:19 +00:00
|
|
|
|
|
|
|
stt = end + -(rad(rot - piv)) //+rad(30);
|
2023-03-21 06:08:08 +00:00
|
|
|
}
|
2023-05-04 07:20:19 +00:00
|
|
|
|
2023-03-21 06:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
class FloralPhyllo_Accident extends BaseShape {
|
2023-04-07 23:20:14 +00:00
|
|
|
constructor(sides, width, colour1, colour2) {
|
2023-03-21 06:08:08 +00:00
|
|
|
super();
|
|
|
|
this.sides = sides;
|
|
|
|
this.width = width;
|
|
|
|
this.colour1 = colour1;
|
|
|
|
this.colour2 = colour2;
|
|
|
|
}
|
|
|
|
|
2023-04-17 06:10:38 +00:00
|
|
|
draw(rotation) {
|
2023-05-04 07:20:19 +00:00
|
|
|
rotation *= (this.speedMultiplier / 100)
|
2023-03-21 06:08:08 +00:00
|
|
|
var c = 24; //something to do with width. but not width
|
|
|
|
|
|
|
|
for (let n = 0; n < 300; n += 1) {
|
|
|
|
let ncolour = LerpHex(this.colour1, this.colour2, Math.cos(rad(n / 2)));
|
2023-04-17 06:10:38 +00:00
|
|
|
let a = n * (rotation / 1000 + 100); //137.5;
|
2023-03-21 06:08:08 +00:00
|
|
|
let r = c * Math.sqrt(n);
|
|
|
|
let x = r * Math.cos(a) + centerX;
|
|
|
|
let y = r * Math.sin(a) + centerY;
|
|
|
|
|
|
|
|
drawEyelidAccident(x, y);
|
2023-05-04 07:20:19 +00:00
|
|
|
|
2023-03-21 06:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class Nodal_expanding extends BaseShape {
|
2023-04-07 23:20:14 +00:00
|
|
|
constructor(expand, points, line_width, colour1, colour2, colour_change) {
|
2023-03-21 06:08:08 +00:00
|
|
|
super();
|
|
|
|
this.expand = expand;
|
|
|
|
this.points = points;
|
|
|
|
this.line_width = line_width;
|
|
|
|
this.colour1 = colour1;
|
|
|
|
this.colour2 = colour2;
|
2023-05-04 07:20:19 +00:00
|
|
|
this.colour_change = colour_change
|
2023-03-21 06:08:08 +00:00
|
|
|
}
|
|
|
|
|
2023-04-17 06:10:38 +00:00
|
|
|
draw(rotation) {
|
2023-05-04 07:20:19 +00:00
|
|
|
rotation *= (this.speedMultiplier / 100)
|
|
|
|
let colour_change = this.colour_change / 8
|
|
|
|
var angle = 360 / this.points * rotation
|
2023-03-21 06:08:08 +00:00
|
|
|
|
|
|
|
var start_angle = angle;
|
|
|
|
var done = false;
|
|
|
|
var total_moves = 1;
|
|
|
|
var length = this.expand;
|
|
|
|
|
2023-05-04 07:20:19 +00:00
|
|
|
for (let z = 1; z <= 100; z++) { //why specifically 2500
|
2023-03-21 06:08:08 +00:00
|
|
|
ctx.beginPath();
|
2023-05-04 07:20:19 +00:00
|
|
|
let ncolour = LerpHex(this.colour1, this.colour2, Math.cos(rad(z * colour_change)));
|
|
|
|
|
|
|
|
ctx.moveTo(centerX + (Math.cos(rad(angle * (z - 1) + 0)) * (length - this.expand)), centerY + (Math.sin(rad(angle * (z - 1) + 0)) * (length - this.expand)));
|
|
|
|
ctx.lineTo(centerX + (Math.cos(rad(angle * z + 0)) * length), centerY + (Math.sin(rad(angle * z + 0)) * length));
|
2023-03-21 06:08:08 +00:00
|
|
|
length += this.expand;
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.lineWidth = this.line_width;//try 1
|
2023-03-21 06:08:08 +00:00
|
|
|
ctx.strokeStyle = ncolour;
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.lineCap = "round"
|
2023-03-21 06:08:08 +00:00
|
|
|
// ctx.strokeStyle = colourToText(ncolour);
|
2023-05-04 07:20:19 +00:00
|
|
|
console.log(ncolour)
|
2023-03-21 06:08:08 +00:00
|
|
|
ctx.stroke();
|
|
|
|
}
|
2023-05-04 07:20:19 +00:00
|
|
|
|
|
|
|
|
2023-03-21 06:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-23 04:28:46 +00:00
|
|
|
class Nodal extends BaseShape {
|
2023-04-07 23:20:14 +00:00
|
|
|
constructor(width, points, line_width, step, colour) {
|
2023-03-23 04:28:46 +00:00
|
|
|
super();
|
|
|
|
this.width = width;
|
|
|
|
this.points = points;
|
|
|
|
this.line_width = line_width;
|
|
|
|
this.step = step;
|
|
|
|
this.colour = colour;
|
|
|
|
}
|
2023-04-07 23:20:14 +00:00
|
|
|
// Draw_nodal(300, 100, 31, rotation, "blue");
|
2023-04-17 06:10:38 +00:00
|
|
|
draw(rotation) {
|
2023-05-04 07:20:19 +00:00
|
|
|
rotation *= (this.speedMultiplier / 100)
|
2023-03-23 04:28:46 +00:00
|
|
|
// console.log(rotate)
|
2023-05-04 07:20:19 +00:00
|
|
|
var angle = 360 / this.points * this.step
|
2023-03-23 04:28:46 +00:00
|
|
|
ctx.beginPath();
|
|
|
|
var start_angle = angle;
|
|
|
|
var done = false;
|
|
|
|
var total_moves = 1;
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.moveTo(centerX + (Math.cos(rad(angle + rotation)) * this.width), centerY + (Math.sin(rad(angle + rotation)) * this.width));
|
2023-03-23 04:28:46 +00:00
|
|
|
|
|
|
|
while (done != true) {
|
|
|
|
if ((total_moves * this.step) % this.points != 0) {
|
2023-05-04 07:20:19 +00:00
|
|
|
total_moves++
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
total_moves++
|
|
|
|
done = true
|
2023-03-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let z = 1; z <= total_moves; z++) {
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.lineTo(centerX + (Math.cos(rad(angle * z + rotation)) * this.width), centerY + (Math.sin(rad(angle * z + rotation)) * this.width));
|
2023-03-23 04:28:46 +00:00
|
|
|
}
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.lineWidth = this.line_width;//try 1
|
2023-03-23 04:28:46 +00:00
|
|
|
ctx.strokeStyle = this.colour;
|
|
|
|
ctx.stroke();
|
2023-05-04 07:20:19 +00:00
|
|
|
|
2023-03-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
class Phyllotaxis extends BaseShape {
|
2023-04-07 23:20:14 +00:00
|
|
|
constructor(width, nMax, colour1, colour2) {
|
2023-03-23 04:28:46 +00:00
|
|
|
super();
|
|
|
|
this.width = width;
|
|
|
|
this.nMax = nMax;
|
|
|
|
this.colour1 = colour1;
|
|
|
|
this.colour2 = colour2;
|
|
|
|
}
|
2023-04-07 23:20:14 +00:00
|
|
|
// Draw_nodal(300, 100, 31, rotation, "blue");
|
2023-04-17 06:10:38 +00:00
|
|
|
draw(rotation) {
|
2023-05-04 07:20:19 +00:00
|
|
|
rotation *= (this.speedMultiplier / 100)
|
2023-03-23 04:28:46 +00:00
|
|
|
for (let n = 0; n < this.nMax; n += 1) {
|
2023-04-07 23:20:14 +00:00
|
|
|
const ncolour = LerpHex(this.colour1, this.colour2, n / this.nMax);
|
2023-03-23 04:28:46 +00:00
|
|
|
// const ncolour = LerpHex(this.colour1, this.colour2, (n/this.nMax)**2);
|
2023-05-04 07:20:19 +00:00
|
|
|
const a = n * (rotation / 1000)//137.5;
|
2023-03-23 04:28:46 +00:00
|
|
|
const r = this.width * Math.sqrt(n);
|
|
|
|
const x = r * Math.cos(a) + centerX;
|
|
|
|
const y = r * Math.sin(a) + centerY;
|
|
|
|
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.arc(x, y, 8, 0, 2 * Math.PI);
|
|
|
|
ctx.fillStyle = ncolour;
|
|
|
|
// ctx.fillStyle = colourToText(ncolour);
|
|
|
|
ctx.fill();
|
|
|
|
// console.log(this.c)
|
|
|
|
}
|
2023-05-04 07:20:19 +00:00
|
|
|
|
2023-03-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
class SquareTwist_angle extends BaseShape {
|
2023-04-07 23:20:14 +00:00
|
|
|
constructor(width, line_width, colour1) {
|
2023-03-23 04:28:46 +00:00
|
|
|
super();
|
2023-04-07 23:20:14 +00:00
|
|
|
this.width = width;
|
2023-03-23 04:28:46 +00:00
|
|
|
this.line_width = line_width;
|
|
|
|
this.colour1 = colour1;
|
|
|
|
}
|
2023-04-07 23:20:14 +00:00
|
|
|
drawSquare(angle, size, colour) {
|
2023-03-23 04:28:46 +00:00
|
|
|
ctx.save();
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.translate(centerX, centerY)//-(Math.sin(rad(angle)) *centerX));
|
2023-03-23 04:28:46 +00:00
|
|
|
ctx.rotate(rad(angle + 180));
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.strokeStyle = colour;
|
2023-04-07 23:20:14 +00:00
|
|
|
ctx.lineWidth = this.line_width;
|
|
|
|
ctx.rect(-size / 2, -size / 2, size, size);
|
2023-03-23 04:28:46 +00:00
|
|
|
ctx.stroke();
|
|
|
|
ctx.restore();
|
2023-04-07 23:20:14 +00:00
|
|
|
}
|
|
|
|
// DrawSquareTwist_angle(400,0,rotation,"red")
|
2023-04-17 06:10:38 +00:00
|
|
|
draw(rotation) {
|
2023-05-04 07:20:19 +00:00
|
|
|
rotation *= (this.speedMultiplier / 100)
|
2023-04-17 06:10:38 +00:00
|
|
|
let out_angle = rotation;
|
2023-05-04 07:20:19 +00:00
|
|
|
let widthMultiplier = 1 / (2 * Math.sin(Math.PI / 180 * (130 - out_angle + 90 * Math.floor(out_angle / 90)))) + 0.5
|
2023-03-23 04:28:46 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < 25; i++) {
|
2023-05-04 07:20:19 +00:00
|
|
|
this.drawSquare(rotation * i, this.width * widthMultiplier ** i, this.colour1)
|
2023-04-07 23:20:14 +00:00
|
|
|
}
|
2023-05-04 07:20:19 +00:00
|
|
|
|
2023-03-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
class rectangle_pattern1 extends BaseShape {
|
2023-04-07 23:20:14 +00:00
|
|
|
constructor(width, squares, line_width, colour1) {
|
2023-03-23 04:28:46 +00:00
|
|
|
super();
|
2023-04-07 23:20:14 +00:00
|
|
|
this.width = width;
|
|
|
|
this.squares = squares;
|
2023-03-23 04:28:46 +00:00
|
|
|
this.line_width = line_width;
|
|
|
|
this.colour1 = colour1;
|
|
|
|
}
|
2023-04-07 23:20:14 +00:00
|
|
|
drawSquare(angle, size, colour) {
|
2023-03-23 04:28:46 +00:00
|
|
|
ctx.save();
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.translate(centerX, centerY)//-(Math.sin(rad(angle)) *centerX));
|
2023-03-23 04:28:46 +00:00
|
|
|
ctx.rotate(rad(angle + 180));
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.strokeStyle = colour;
|
2023-04-07 23:20:14 +00:00
|
|
|
ctx.lineWidth = this.line_width;
|
|
|
|
ctx.rect(-size / 2, -size / 2, size, size);
|
2023-03-23 04:28:46 +00:00
|
|
|
ctx.stroke();
|
|
|
|
ctx.restore();
|
2023-04-07 23:20:14 +00:00
|
|
|
}
|
|
|
|
// Draw_rectangle_pattern1(rotation, squares, 200, "blue");
|
|
|
|
draw(rotation) {
|
2023-05-04 07:20:19 +00:00
|
|
|
rotation *= (this.speedMultiplier / 100)
|
2023-04-07 23:20:14 +00:00
|
|
|
for (let z = 0; z < 360; z += 360 / this.squares) {
|
|
|
|
this.drawSquare(z + rotation, this.width, this.colour1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-04 07:20:19 +00:00
|
|
|
|
|
|
|
class CircleExpand extends BaseShape {
|
2023-05-04 07:49:52 +00:00
|
|
|
constructor(nCircles, gap, linear, colour1, colour2) {
|
2023-05-04 07:20:19 +00:00
|
|
|
super();
|
2023-05-04 07:49:52 +00:00
|
|
|
this.nCircles = nCircles;
|
|
|
|
this.gap = gap;
|
|
|
|
this.linear = linear;
|
|
|
|
this.colour1 = colour1;
|
|
|
|
this.colour2 = colour2
|
2023-05-04 07:20:19 +00:00
|
|
|
}
|
2023-05-04 07:49:52 +00:00
|
|
|
lerpColor(a, b, amount) {
|
2023-05-04 07:20:19 +00:00
|
|
|
var ah = +a.replace('#', '0x'),
|
2023-05-04 07:49:52 +00:00
|
|
|
ar = ah >> 16, ag = ah >> 8 & 0xff, ab = ah & 0xff,
|
|
|
|
bh = +b.replace('#', '0x'),
|
|
|
|
br = bh >> 16, bg = bh >> 8 & 0xff, bb = bh & 0xff,
|
|
|
|
rr = ar + amount * (br - ar),
|
|
|
|
rg = ag + amount * (bg - ag),
|
|
|
|
rb = ab + amount * (bb - ab);
|
2023-05-04 07:20:19 +00:00
|
|
|
|
|
|
|
return '#' + ((1 << 24) + (rr << 16) + (rg << 8) + rb | 0).toString(16).slice(1);
|
2023-05-04 07:49:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
arraySort(x, y) {
|
|
|
|
if (x.r > y.r) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (x.r < y.r) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2023-05-04 07:20:19 +00:00
|
|
|
|
|
|
|
draw(rotation) {
|
2023-05-04 07:49:52 +00:00
|
|
|
let arrOfWidths = []
|
|
|
|
let arrOfco = []
|
|
|
|
let intRot;
|
|
|
|
if (this.linear) {
|
|
|
|
intRot = Math.floor(rotation * 30) / 100
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
intRot = Math.sin(rad(Math.floor(rotation * 30) / 4)) + rotation / 4
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < this.nCircles; i++) {
|
|
|
|
const width = this.gap * ((intRot + i) % this.nCircles);
|
|
|
|
const colour = (Math.sin(rad(i * (360 / this.nCircles) - 90)) + 1) / 2
|
|
|
|
arrOfWidths.push({ r: width, c: colour });
|
|
|
|
}
|
|
|
|
|
|
|
|
let newArr = arrOfWidths.sort(this.arraySort)
|
|
|
|
|
|
|
|
for (let i = this.nCircles - 1; i >= 0; i--) {
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.arc(centerX, centerY, newArr[i].r, 0, 2 * Math.PI);
|
|
|
|
let newColour = this.lerpColor(this.colour1, this.colour2, newArr[i].c)
|
|
|
|
ctx.fillStyle = newColour;
|
|
|
|
ctx.fill();
|
|
|
|
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.beginPath();
|
2023-05-04 07:49:52 +00:00
|
|
|
ctx.arc(centerX, centerY, newArr[i].r, 0, 2 * Math.PI);
|
|
|
|
ctx.stokeStyle = "black";
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-07 23:20:14 +00:00
|
|
|
class EyePrototype extends BaseShape {
|
2023-05-04 07:20:19 +00:00
|
|
|
constructor(width, blink_speed, draw_spiral, draw_pupil, draw_expand, line_width, colourPupil, colourSpiral, colourExpand) {
|
2023-04-07 23:20:14 +00:00
|
|
|
super();
|
|
|
|
this.width = width;
|
|
|
|
this.line_width = line_width;
|
|
|
|
this.step = 0;
|
2023-04-29 07:27:11 +00:00
|
|
|
this.speed = blink_speed;
|
2023-04-07 23:20:14 +00:00
|
|
|
this.opening = true;
|
|
|
|
this.counter = 0;
|
|
|
|
this.cooldown = 0;
|
2023-04-29 07:27:11 +00:00
|
|
|
this.draw_spiral = draw_spiral;
|
|
|
|
this.draw_pupil = draw_pupil;
|
2023-05-02 02:31:18 +00:00
|
|
|
this.draw_expand = draw_expand;
|
2023-05-04 07:20:19 +00:00
|
|
|
this.colourPupil = colourPupil;
|
|
|
|
this.colourSpiral = colourSpiral;
|
|
|
|
this.colourExpand = colourExpand;
|
2023-04-07 23:20:14 +00:00
|
|
|
}
|
2023-04-17 06:10:38 +00:00
|
|
|
drawEyelid(rotation) {
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.strokeStyle = "orange";
|
|
|
|
rotation *= (this.speedMultiplier / 100)
|
2023-04-07 23:20:14 +00:00
|
|
|
ctx.lineWidth = 1;
|
|
|
|
ctx.beginPath();
|
2023-04-29 07:27:11 +00:00
|
|
|
ctx.moveTo(centerX - this.width / 2, centerY);
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.quadraticCurveTo(centerX, centerY - rotation / 400 * this.width, centerX + this.width / 2, centerY);
|
2023-04-07 23:20:14 +00:00
|
|
|
|
2023-04-29 07:27:11 +00:00
|
|
|
ctx.moveTo(centerX - this.width / 2, centerY);
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.quadraticCurveTo(centerX, centerY + rotation / 400 * this.width, centerX + this.width / 2, centerY);
|
2023-04-07 23:20:14 +00:00
|
|
|
ctx.stroke();
|
|
|
|
}
|
|
|
|
eyelidCut(step) {
|
|
|
|
// ctx.lineWidth = 1;
|
|
|
|
let squarePath = new Path2D();
|
2023-04-29 07:27:11 +00:00
|
|
|
squarePath.moveTo(centerX - this.width / 2, centerY);
|
2023-05-04 07:20:19 +00:00
|
|
|
squarePath.quadraticCurveTo(centerX, centerY - step / 400 * this.width, centerX + this.width / 2, centerY);
|
2023-04-07 23:20:14 +00:00
|
|
|
|
2023-04-29 07:27:11 +00:00
|
|
|
squarePath.moveTo(centerX - this.width / 2, centerY);
|
2023-05-04 07:20:19 +00:00
|
|
|
squarePath.quadraticCurveTo(centerX, centerY + step / 400 * this.width, centerX + this.width / 2, centerY);
|
2023-04-07 23:20:14 +00:00
|
|
|
|
|
|
|
ctx.clip(squarePath);
|
|
|
|
}
|
|
|
|
drawGrowEye(step) {
|
2023-04-29 07:27:11 +00:00
|
|
|
// console.log(step)
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.strokeStyle = this.colourExpand
|
2023-04-07 23:20:14 +00:00
|
|
|
ctx.beginPath();
|
|
|
|
ctx.lineWidth = 5;
|
2023-04-29 07:27:11 +00:00
|
|
|
ctx.arc(centerX, centerY, step, 0, 2 * Math.PI);
|
2023-04-07 23:20:14 +00:00
|
|
|
ctx.stroke();
|
|
|
|
}
|
|
|
|
drawCircle(step) {
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.strokeStyle = this.colourPupil
|
2023-04-07 23:20:14 +00:00
|
|
|
ctx.beginPath();
|
|
|
|
ctx.lineWidth = 5;
|
2023-04-29 07:27:11 +00:00
|
|
|
ctx.arc(centerX, centerY, step, 0, 2 * Math.PI);
|
|
|
|
ctx.stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
drawSpiral(step) {
|
2023-05-04 07:20:19 +00:00
|
|
|
ctx.strokeStyle = this.colourSpiral;
|
|
|
|
let a = 1
|
|
|
|
let b = 5
|
2023-04-29 07:27:11 +00:00
|
|
|
ctx.moveTo(centerX, centerY);
|
|
|
|
ctx.beginPath();
|
|
|
|
for (let i = 0; i < 400; i++) {
|
|
|
|
let angle = 0.1 * i;
|
|
|
|
let x = centerX + (a + b * angle) * Math.cos(angle + step / 2);
|
|
|
|
let y = centerY + (a + b * angle) * Math.sin(angle + step / 2);
|
|
|
|
|
|
|
|
ctx.lineTo(x, y);
|
|
|
|
}
|
|
|
|
ctx.lineWidth = 3;
|
2023-04-07 23:20:14 +00:00
|
|
|
ctx.stroke();
|
|
|
|
}
|
|
|
|
stepFunc() {
|
|
|
|
if (this.cooldown != 0) {
|
|
|
|
this.cooldown--;
|
|
|
|
} else {
|
|
|
|
if (this.opening == true) {
|
|
|
|
if (this.step >= 200) {
|
|
|
|
this.cooldown = 200;
|
|
|
|
this.opening = false;
|
|
|
|
this.step -= this.speed;
|
|
|
|
} else {
|
|
|
|
this.step += this.speed;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (this.step <= 0) {
|
|
|
|
this.opening = true;
|
|
|
|
this.step += this.speed;
|
|
|
|
} else {
|
|
|
|
this.step -= this.speed;
|
|
|
|
}
|
|
|
|
}
|
2023-03-23 04:28:46 +00:00
|
|
|
}
|
2023-04-07 23:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
draw(rotation) {
|
2023-05-04 05:29:04 +00:00
|
|
|
let speedMult = 50
|
|
|
|
let waitTime = 3
|
|
|
|
let cap = 200
|
|
|
|
let d = waitTime * speedMult * 10
|
|
|
|
let a = cap * 2 + d
|
|
|
|
let outputRotation = Math.min(Math.abs((Math.floor(rotation * speedMult) % a) - a / 2 - d / 2), cap)
|
|
|
|
// console.log("Rot: "+ rotation + " | " +Math.floor(rotation)%a)
|
|
|
|
console.log(outputRotation)
|
2023-04-29 07:27:11 +00:00
|
|
|
// console.log(this.counter)
|
2023-05-04 07:20:19 +00:00
|
|
|
|
2023-04-07 23:20:14 +00:00
|
|
|
ctx.fillStyle = "black";
|
|
|
|
// ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
|
|
|
// ctx.fillRect(0, 0, 500, 500);
|
|
|
|
|
|
|
|
// let newPath = new Path2D();
|
|
|
|
// newPath.arc(150, 75, 75, 0, 2 * Math.PI);
|
|
|
|
|
2023-04-29 07:27:11 +00:00
|
|
|
// ctx.beginPath();
|
|
|
|
// ctx.rect(centerX-300/2, centerY-300/2, 300, 300);
|
|
|
|
// ctx.stroke();
|
2023-04-07 23:20:14 +00:00
|
|
|
|
2023-05-04 05:29:04 +00:00
|
|
|
// this.drawEyelid(this.step);
|
|
|
|
this.drawEyelid(outputRotation);
|
2023-04-07 23:20:14 +00:00
|
|
|
|
|
|
|
ctx.save();
|
|
|
|
// squareCut();
|
2023-05-04 05:29:04 +00:00
|
|
|
this.eyelidCut(outputRotation);
|
2023-04-07 23:20:14 +00:00
|
|
|
if (this.counter % 100 == 0) {
|
|
|
|
this.counter = 0;
|
2023-03-23 04:28:46 +00:00
|
|
|
}
|
2023-05-04 07:20:19 +00:00
|
|
|
if (this.drawGrowEye) {
|
2023-05-02 02:31:18 +00:00
|
|
|
this.drawGrowEye(this.width / 4 + this.counter);
|
2023-04-29 07:27:11 +00:00
|
|
|
}
|
2023-05-04 07:20:19 +00:00
|
|
|
|
2023-05-02 02:31:18 +00:00
|
|
|
if (this.draw_spiral) {
|
2023-05-04 07:20:19 +00:00
|
|
|
this.drawSpiral(rotation)
|
2023-05-02 02:31:18 +00:00
|
|
|
}
|
2023-05-04 05:29:04 +00:00
|
|
|
if (this.draw_pupil) {
|
|
|
|
this.drawCircle(this.width / 4);
|
2023-04-29 07:27:11 +00:00
|
|
|
}
|
2023-04-07 23:20:14 +00:00
|
|
|
|
|
|
|
ctx.restore();
|
|
|
|
|
2023-05-04 07:20:19 +00:00
|
|
|
this.stepFunc();
|
|
|
|
this.counter++;
|
2023-03-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-04 07:20:19 +00:00
|
|
|
|