addeed
This commit is contained in:
parent
6b5d7bec78
commit
1a736fc229
|
@ -12,17 +12,17 @@
|
|||
<div id="toolbar">
|
||||
<br>
|
||||
<select id="shape-selector">
|
||||
<option value="EyePrototype">EyePrototype</option>
|
||||
<option value="Nodal_expanding">Nodal_expanding</option>
|
||||
<option value="MaryFace">MaryFace</option>
|
||||
<option value="CircleExpand">CircleExpand</option>
|
||||
<option value="PolyTwistColourWidth">PolyTwistColourWidth</option>
|
||||
<option value="FloralPhyllo">FloralPhyllo</option>
|
||||
<option value="FloralPhyllo_Accident">FloralPhyllo_Accident</option>
|
||||
<option value="Spiral1">Spiral1</option>
|
||||
<option value="FloralAccident">FloralAccident</option>
|
||||
<option value="Nodal_expanding">Nodal_expanding</option>
|
||||
<option value="Nodal">Nodal</option>
|
||||
<option value="Phyllotaxis">Phyllotaxis</option>
|
||||
<option value="SquareTwist_angle">SquareTwist_angle</option>
|
||||
<option value="rectangle_pattern1">rectangle_pattern1</option>
|
||||
<option value="EyePrototype">EyePrototype</option>
|
||||
</select>
|
||||
<div id="custom"></div>
|
||||
<br>
|
||||
|
@ -45,9 +45,6 @@
|
|||
</div>
|
||||
<button class="buttonReset button-8" id="resetButton" onclick="Reset()">Reset Rotation</button>
|
||||
</div>
|
||||
<div>
|
||||
<button onclick="manualToggleSettings()" class="button">Show/hide</button>
|
||||
</div>
|
||||
</body>
|
||||
<script src="./js/helper.js" type="text/javascript"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
|
|
|
@ -3,17 +3,20 @@ async function fetchConfig(className) {
|
|||
const config = {
|
||||
PolyTwistColourWidth: [
|
||||
{ type: "range", min: 3, max: 10, defaultValue: 5, property: "sides" },
|
||||
{ type: "range", min: 1, max: 600, defaultValue: 400, property: "width" },
|
||||
{ type: "range", min: 400, max: 2000, defaultValue: 400, property: "width" },
|
||||
{ type: "range", min: 2, max: 5, defaultValue: 5, property: "line_width" },
|
||||
{ type: "range", min: 1, max: 100, defaultValue: 50, property: "depth" },
|
||||
{ type: "range", min: -180, max: 180, defaultValue: -90, property: "rotation" },
|
||||
{ type: "range", min: -180, max: 180, defaultValue: -90, property: "rotation", },
|
||||
{ type: "range", min: 1, max: 500, defaultValue: 100, property: "speedMultiplier", },
|
||||
{ type: "color", defaultValue: "#4287f5", property: "colour1" },
|
||||
{ type: "color", defaultValue: "#42f57b", property: "colour2" },
|
||||
],
|
||||
FloralPhyllo: [
|
||||
{ type: "range", min: 1, max: 600, defaultValue: 300, property: "width" },
|
||||
{ type: "range", min: 1, max: 100, defaultValue: 50, property: "depth" },
|
||||
{ type: "range", min: 1, max: 300, defaultValue: 150, property: "depth" },
|
||||
{ type: "range", min: 0, max: 3141, defaultValue: 0, property: "start" },
|
||||
{ type: "color", defaultValue: "#4287f5", property: "colour1" },
|
||||
{ type: "color", defaultValue: "#4287f5", property: "colour2" },
|
||||
{ type: "color", defaultValue: "#FC0362", property: "colour2" },
|
||||
],
|
||||
Spiral1: [
|
||||
{ type: "range", min: 1, max: 50, defaultValue: 20, property: "sides" },
|
||||
|
@ -33,22 +36,18 @@ async function fetchConfig(className) {
|
|||
],
|
||||
Nodal_expanding: [
|
||||
{ type: "range", min: 1, max: 100, defaultValue: 5, property: "expand" },
|
||||
{ type: "range", min: 1, max: 100000, defaultValue: 100000, property: "points" },
|
||||
{ type: "range", min: 1, max: 10, defaultValue: 3, property: "line_width" },
|
||||
{ type: "range", min: 1, max: 1000, defaultValue: 150, property: "points" },
|
||||
{ type: "range", min: 1, max: 360, defaultValue: 0, property: "start" },
|
||||
{ type: "range", min: 1, max: 10, defaultValue: 6, property: "line_width" },
|
||||
{ type: "color", defaultValue: "#2D81FC", property: "colour1" },
|
||||
{ type: "color", defaultValue: "#FC0362", property: "colour2" },
|
||||
{ type: "range", min: 0, max: 10, defaultValue: 5, property: "colour_change" },
|
||||
],
|
||||
Nodal: [
|
||||
{ type: "range", min: 1, max: 1000, defaultValue: 400, property: "width" },
|
||||
{ type: "range", min: 1, max: 20, defaultValue: 10, property: "points" },
|
||||
{ type: "range", min: 1, max: 10, defaultValue: 3, property: "line_width" },
|
||||
{ type: "range", min: 1, max: 20, defaultValue: 1, property: "step" },
|
||||
{ type: "color", defaultValue: "#2D81FC", property: "colour" },
|
||||
],
|
||||
Phyllotaxis: [
|
||||
{ type: "range", min: 1, max: 40, defaultValue: 24, property: "width" },
|
||||
{ type: "range", min: 0, max: 3141, defaultValue: 0, property: "start" },
|
||||
{ type: "range", min: 1, max: 1000, defaultValue: 300, property: "nMax" },
|
||||
{ type: "range", min: 0, max: 2, defaultValue: 0, property: "wave" },
|
||||
{ type: "color", defaultValue: "#2D81FC", property: "colour1" },
|
||||
{ type: "color", defaultValue: "#FC0362", property: "colour2" },
|
||||
],
|
||||
|
@ -57,20 +56,43 @@ async function fetchConfig(className) {
|
|||
{ type: "range", min: 1, max: 10, defaultValue: 1, property: "line_width" },
|
||||
{ type: "color", defaultValue: "#2D81FC", property: "colour1" },
|
||||
],
|
||||
rectangle_pattern1: [
|
||||
{ type: "range", min: 1, max: 800, defaultValue: 400, property: "width" },
|
||||
{ type: "range", min: 1, max: 100, defaultValue: 10, property: "squares" },
|
||||
{ type: "range", min: 1, max: 10, defaultValue: 1, property: "line_width" },
|
||||
{ type: "color", defaultValue: "#2D81FC", property: "colour1" },
|
||||
],
|
||||
EyePrototype: [
|
||||
{ type: "range", min: 0, max: 0, defaultValue: 0, property: "x" },
|
||||
{ type: "range", min: 0, max: 0, defaultValue: 0, property: "y" },
|
||||
{ type: "range", min: -180, max: 180, defaultValue: 0, property: "rotate" },
|
||||
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "flip" },
|
||||
{ type: "range", min: 1, max: 800, defaultValue: 400, property: "width" },
|
||||
{ type: "range", min: 1, max: 100, defaultValue: 10, property: "squares" },
|
||||
{ type: "range", min: 1, max: 20, defaultValue: 5, property: "blink_speed" },
|
||||
{ type: "range", min: 0, max: 1, defaultValue: 0, property: "draw_spiral" },
|
||||
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "spiral_full" },
|
||||
{ type: "range", min: 0, max: 1, defaultValue: 0, property: "draw_pupil" },
|
||||
{ type: "range", min: 0, max: 1, defaultValue: 0, property: "draw_expand" },
|
||||
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "draw_hypno" },
|
||||
{ type: "range", min: 1, max: 10, defaultValue: 1, property: "line_width" },
|
||||
{ type: "color", defaultValue: "#2D81FC", property: "colour1" },
|
||||
{ type: "color", defaultValue: "#00fffb", property: "colourPupil" },
|
||||
{ type: "color", defaultValue: "#ff0000", property: "colourSpiral" },
|
||||
{ type: "color", defaultValue: "#00fffb", property: "colourExpand" },
|
||||
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "draw_eyelid" },
|
||||
],
|
||||
CircleExpand: [
|
||||
{ type: "range", min: 1, max: 70, defaultValue: 21, property: "nCircles" },
|
||||
{ type: "range", min: 50, max: 150, defaultValue: 150, property: "gap" },
|
||||
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "linear" },
|
||||
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "heart" },
|
||||
{ type: "color", defaultValue: "#fc03cf", property: "colour1" },
|
||||
{ type: "color", defaultValue: "#00fffb", property: "colour2" },
|
||||
],
|
||||
MaryFace: [
|
||||
{ type: "range", min: -400, max: 400, defaultValue: -110, property: "x1" },
|
||||
{ type: "range", min: -400, max: 400, defaultValue: -140, property: "y1" },
|
||||
{ type: "range", min: -180, max: 180, defaultValue: 18, property: "rotate1" },
|
||||
{ type: "range", min: 0, max: 400, defaultValue: 160, property: "width1" },
|
||||
{ type: "range", min: -400, max: 400, defaultValue: 195, property: "x2" },
|
||||
{ type: "range", min: -400, max: 400, defaultValue: -30, property: "y2" },
|
||||
{ type: "range", min: -180, max: 180, defaultValue: 18, property: "rotate2" },
|
||||
{ type: "range", min: 0, max: 400, defaultValue: 160, property: "width2" },
|
||||
],
|
||||
};
|
||||
|
||||
if (className === undefined) {
|
||||
return config
|
||||
} else {
|
||||
|
@ -80,7 +102,7 @@ async function fetchConfig(className) {
|
|||
}
|
||||
|
||||
function addControl(item, instance) {
|
||||
// console.log(item);
|
||||
console.log(item);
|
||||
let parentDiv = document.getElementById("custom");
|
||||
|
||||
let title = document.createElement("p");
|
||||
|
@ -219,7 +241,7 @@ function drawEyelidAccident(x1, y1) {
|
|||
ctx.stroke();
|
||||
}
|
||||
|
||||
function DrawPolygon(sides, width, rotation, colour) {
|
||||
function DrawPolygon(sides, width, rotation, colour, line_width) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(
|
||||
centerX + width * Math.cos((rotation * Math.PI) / 180),
|
||||
|
@ -236,7 +258,7 @@ function DrawPolygon(sides, width, rotation, colour) {
|
|||
);
|
||||
}
|
||||
ctx.strokeStyle = colour;
|
||||
ctx.lineWidth = 3;
|
||||
ctx.lineWidth = line_width;
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
|
@ -248,6 +270,12 @@ function colourToText(colour) {
|
|||
return "rgb(" + colour[0] + "," + colour[1] + "," + colour[2] + ")";
|
||||
}
|
||||
|
||||
|
||||
function waveNormal(x, max) {
|
||||
let val = Math.sin((x / max) * Math.PI * 2 - max * (Math.PI / (max * 2))) / 2 + 0.5
|
||||
return val
|
||||
}
|
||||
|
||||
function LerpHex(a, b, amount) {
|
||||
var ah = parseInt(a.replace(/#/g, ""), 16),
|
||||
ar = ah >> 16,
|
||||
|
@ -277,10 +305,29 @@ function LerpRGB(a, b, t) {
|
|||
return newColor;
|
||||
}
|
||||
|
||||
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);
|
||||
function lerpRGB(a, b, t) {
|
||||
const result = [0, 0, 0];
|
||||
for (let i = 0; i < 3; i++) {
|
||||
result[i] = (1 - t) * a[i] + t * b[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
function drawCenter(width) {
|
||||
console.log("center?")
|
||||
ctx.strokeStyle = "pink";
|
||||
ctx.lineWidth = 1
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(centerX - width, centerY);
|
||||
ctx.lineTo(centerX + width, centerY);
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(centerX, centerY - width);
|
||||
ctx.lineTo(centerX, centerY + width);
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
function render_clear() {
|
||||
|
@ -288,3 +335,31 @@ function render_clear() {
|
|||
ctx.fillStyle = "black";
|
||||
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
}
|
||||
|
||||
function rotatePointTmp(x, y, centerXX, centerYY, rotation) {
|
||||
let xFromC = x - centerXX;
|
||||
let yFromC = y - centerYY;
|
||||
let d = (xFromC ** 2 + yFromC ** 2) ** 0.5
|
||||
// let orgAngle = Math.atan2(yFromC/xFromC)
|
||||
let orgAngle = Math.atan2(xFromC, yFromC)
|
||||
let tmp = Math.cos(rad(orgAngle - rotation)) * d
|
||||
// console.log(Math.cos((-90)*(Math.PI/180)))
|
||||
console.log(orgAngle)
|
||||
console.log(rad(rotation))
|
||||
console.log(Math.cos(orgAngle - rad(rotation)) * d)
|
||||
console.log(d)
|
||||
// console.log(d)
|
||||
let newPointX = Math.cos(orgAngle - rad(rotation+90)) * d + centerXX;
|
||||
let newPointY = Math.sin(orgAngle - rad(rotation+90)) * d + centerYY;
|
||||
return [newPointX, newPointY]
|
||||
}
|
||||
|
||||
function rotatePoint(x,y,rotation){
|
||||
let nCos = Math.cos(rad(rotation))
|
||||
// console.log(nCos*(180/Math.PI))
|
||||
// console.log(rad(rotation))
|
||||
let nSin = Math.sin(rad(rotation))
|
||||
let newX = x*nCos - y*nSin
|
||||
let newY = y*nCos + x*nSin
|
||||
return [newX,newY]
|
||||
}
|
|
@ -2,7 +2,8 @@
|
|||
var seed = cyrb128("813311281");
|
||||
var rand = sfc32(seed[0], seed[1], seed[2], seed[3]);
|
||||
|
||||
var gateway = `ws://192.168.20.13/ws`;
|
||||
// var gateway = `ws://192.168.1.184/ws`;
|
||||
var gateway = `ws://192.168.4.1/ws`;
|
||||
var websocket;
|
||||
window.addEventListener('load', onLoad);
|
||||
function initWebSocket() {
|
||||
|
@ -50,7 +51,7 @@ let targetFps = 60;
|
|||
let frameDuration = 1000 / targetFps;
|
||||
|
||||
let rotation = 0; //was = j = angle
|
||||
let paused = true;
|
||||
let paused = false;
|
||||
render_clear();
|
||||
|
||||
let drawObj = null;
|
||||
|
@ -61,11 +62,11 @@ const classMap = {
|
|||
FloralAccident: FloralAccident,
|
||||
FloralPhyllo_Accident: FloralPhyllo_Accident,
|
||||
Nodal_expanding: Nodal_expanding,
|
||||
Nodal: Nodal,
|
||||
Phyllotaxis: Phyllotaxis,
|
||||
SquareTwist_angle: SquareTwist_angle,
|
||||
rectangle_pattern1: rectangle_pattern1,
|
||||
EyePrototype: EyePrototype,
|
||||
Phyllotaxis:Phyllotaxis,
|
||||
SquareTwist_angle:SquareTwist_angle,
|
||||
EyePrototype:EyePrototype,
|
||||
CircleExpand:CircleExpand,
|
||||
MaryFace:MaryFace,
|
||||
// Add more class constructors here as needed
|
||||
};
|
||||
function createInstance(className, args) {
|
||||
|
@ -197,6 +198,7 @@ function manualToggleSettings() {
|
|||
tb.style.display = "none";
|
||||
}
|
||||
}
|
||||
manualToggleSettings()//force closed at start
|
||||
|
||||
function toggleSettings(e) {
|
||||
if (e.key == "p") {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class BaseShape {
|
||||
constructor() {
|
||||
this.controls = []; // Keep track of created elements and event listeners
|
||||
this.speedMultiplier = 100;
|
||||
}
|
||||
|
||||
initialise(config) {
|
||||
|
@ -8,6 +9,9 @@ class BaseShape {
|
|||
const { element, listener } = addControl(item, this);
|
||||
this.controls.push({ element, listener });
|
||||
}
|
||||
|
||||
const { element, listener } = addControl({ type: "range", min: 1, max: 500, defaultValue: 100, property: "speedMultiplier", }, this);
|
||||
this.controls.push({ element, listener });
|
||||
}
|
||||
|
||||
remove() {
|
||||
|
@ -30,20 +34,23 @@ class BaseShape {
|
|||
}
|
||||
|
||||
class PolyTwistColourWidth extends BaseShape {
|
||||
constructor(sides, width, depth, rotation, colour1, colour2) {
|
||||
constructor(sides, width, line_width, depth, rotation, speedMultiplier, colour1, colour2) {
|
||||
super();
|
||||
this.sides = sides;
|
||||
this.width = width;
|
||||
this.line_width = line_width;
|
||||
this.depth = depth;
|
||||
this.rotation = rotation;
|
||||
this.speedMultiplier = speedMultiplier;
|
||||
this.colour1 = colour1;
|
||||
this.colour2 = colour2;
|
||||
}
|
||||
|
||||
draw(innerRotation) {
|
||||
draw(rotation) {
|
||||
rotation *= (this.speedMultiplier / 100)
|
||||
let out_angle = 0;
|
||||
const innerAngle = 180 - ((this.sides - 2) * 180) / this.sides;
|
||||
const scopeAngle = innerRotation - (innerAngle * Math.floor(innerRotation / innerAngle));
|
||||
const scopeAngle = rotation - (innerAngle * Math.floor(rotation / innerAngle));
|
||||
|
||||
if (scopeAngle < innerAngle / 2) {
|
||||
out_angle = innerAngle / (2 * Math.cos((2 * Math.PI * scopeAngle) / (3 * innerAngle))) - innerAngle / 2;
|
||||
|
@ -57,28 +64,36 @@ class PolyTwistColourWidth extends BaseShape {
|
|||
for (let i = 0; i < this.depth; i++) {
|
||||
const fraction = i / this.depth;
|
||||
const ncolour = LerpHex(this.colour1, this.colour2, fraction);
|
||||
DrawPolygon(this.sides, this.width * widthMultiplier ** i, out_angle * i + this.rotation, ncolour);
|
||||
DrawPolygon(this.sides, this.width * widthMultiplier ** i, out_angle * i + this.rotation, ncolour, this.line_width);
|
||||
}
|
||||
}
|
||||
}
|
||||
class FloralPhyllo extends BaseShape {
|
||||
constructor(width, depth, colour1, colour2) {
|
||||
constructor(width, depth, start, colour1, colour2) {
|
||||
super();
|
||||
this.width = width;
|
||||
this.depth = depth;
|
||||
this.start = start;
|
||||
this.colour1 = colour1;
|
||||
this.colour2 = colour2;
|
||||
this.speedMultiplier = 500;
|
||||
}
|
||||
|
||||
draw(angle) {
|
||||
draw(rotation) {
|
||||
rotation *= (this.speedMultiplier / 500)
|
||||
rotation += this.start
|
||||
// var c = 24; //something to do with width. but not width
|
||||
var c = 1; //something to do with width. but not width
|
||||
for (let n = 200; n > 0; n -= 1) {
|
||||
const a = n * angle / 1000; //137.5;
|
||||
//dont make larger than 270 unless altering the number of colours in lerpedColours
|
||||
for (let n = this.depth; n > 0; n -= 1) {
|
||||
let colVal = waveNormal(n, this.depth)
|
||||
let ncolour = LerpHex(this.colour1, this.colour2, n / this.depth);
|
||||
const a = n * rotation / 1000; //137.5;
|
||||
const r = c * Math.sqrt(n);
|
||||
const x = r * Math.cos(a) + centerX;
|
||||
const y = r * Math.sin(a) + centerY;
|
||||
|
||||
drawEyelid(n * 2.4 + 40, x, y, this.colour1);
|
||||
drawEyelid(n * 2.4 + 40, x, y, ncolour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,6 +106,7 @@ class Spiral1 extends BaseShape {
|
|||
}
|
||||
|
||||
draw(rotation) {
|
||||
rotation *= (this.speedMultiplier / 100)
|
||||
var rot = Math.round((this.sides - 2) * 180 / this.sides * 2)
|
||||
var piv = 360 / this.sides;
|
||||
var stt = 0.5 * Math.PI - rad(rot) //+ rad(rotation);
|
||||
|
@ -127,6 +143,7 @@ class FloralAccident extends BaseShape {
|
|||
}
|
||||
|
||||
draw(rotation) {
|
||||
rotation *= (this.speedMultiplier / 100)
|
||||
var rot = Math.round((this.sides - 2) * 180 / this.sides * 2)
|
||||
var piv = 360 / this.sides;
|
||||
var stt = 0.5 * Math.PI - rad(rot) //+ rad(rotation);
|
||||
|
@ -162,12 +179,13 @@ class FloralPhyllo_Accident extends BaseShape {
|
|||
this.colour2 = colour2;
|
||||
}
|
||||
|
||||
draw(angle) {
|
||||
|
||||
draw(rotation) {
|
||||
rotation *= (this.speedMultiplier / 100)
|
||||
var c = 24; //something to do with width. but not width
|
||||
|
||||
for (let n = 0; n < 300; n += 1) {
|
||||
let a = n * (angle / 1000 + 100); //137.5;
|
||||
let ncolour = LerpHex(this.colour1, this.colour2, Math.cos(rad(n / 2)));
|
||||
let a = n * (rotation / 1000 + 100); //137.5;
|
||||
let r = c * Math.sqrt(n);
|
||||
let x = r * Math.cos(a) + centerX;
|
||||
let y = r * Math.sin(a) + centerY;
|
||||
|
@ -178,90 +196,110 @@ class FloralPhyllo_Accident extends BaseShape {
|
|||
}
|
||||
}
|
||||
class Nodal_expanding extends BaseShape {
|
||||
constructor(expand, points, line_width, colour1, colour2, colour_change) {
|
||||
constructor(expand, points, start, line_width, colour1, colour2, colour_change) {
|
||||
super();
|
||||
this.expand = expand;
|
||||
this.points = points;
|
||||
this.start = start;
|
||||
this.line_width = line_width;
|
||||
this.colour1 = colour1;
|
||||
this.colour2 = colour2;
|
||||
this.colour_change = colour_change
|
||||
}
|
||||
|
||||
draw(step) {
|
||||
let colour_change = this.colour_change / 10
|
||||
var angle = 360 / this.points * step
|
||||
draw(rotation) {
|
||||
rotation *= (this.speedMultiplier / 1000)
|
||||
var angle = (360 / 3000 * rotation) + this.start //2000 controls speed
|
||||
|
||||
var length = this.expand;
|
||||
|
||||
for (let z = 1; z <= 100; z++) { //why specifically 2500
|
||||
for (let z = 1; z <= this.points; z++) { //why specifically 2500
|
||||
ctx.beginPath();
|
||||
let ncolour = LerpHex(this.colour1, this.colour2, Math.cos(rad(z * colour_change)));
|
||||
let ncolour = LerpHex(this.colour1, this.colour2, z / this.points);
|
||||
|
||||
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));
|
||||
length += this.expand;
|
||||
ctx.lineWidth = this.line_width;//try 1
|
||||
ctx.strokeStyle = ncolour;
|
||||
ctx.lineCap = "round"
|
||||
// ctx.strokeStyle = colourToText(ncolour);
|
||||
// console.log(ncolour)
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
class Nodal extends BaseShape {
|
||||
constructor(width, points, line_width, step, colour) {
|
||||
super();
|
||||
this.width = width;
|
||||
this.points = points;
|
||||
this.line_width = line_width;
|
||||
this.step = step;
|
||||
this.colour = colour;
|
||||
}
|
||||
// Draw_nodal(300, 100, 31, rotation, "blue");
|
||||
draw(rotate) {
|
||||
// console.log(rotate)
|
||||
var angle = 360 / this.points * this.step
|
||||
ctx.beginPath();
|
||||
var start_angle = angle;
|
||||
var done = false;
|
||||
var total_moves = 1;
|
||||
ctx.moveTo(centerX + (Math.cos(rad(angle + rotate)) * this.width), centerY + (Math.sin(rad(angle + rotate)) * this.width));
|
||||
|
||||
while (done != true) {
|
||||
if ((total_moves * this.step) % this.points != 0) {
|
||||
total_moves++
|
||||
}
|
||||
else {
|
||||
total_moves++
|
||||
done = true
|
||||
}
|
||||
}
|
||||
for (let z = 1; z <= total_moves; z++) {
|
||||
ctx.lineTo(centerX + (Math.cos(rad(angle * z + rotate)) * this.width), centerY + (Math.sin(rad(angle * z + rotate)) * this.width));
|
||||
}
|
||||
ctx.lineWidth = this.line_width;//try 1
|
||||
ctx.strokeStyle = this.colour;
|
||||
ctx.stroke();
|
||||
|
||||
}
|
||||
}
|
||||
class Phyllotaxis extends BaseShape {
|
||||
constructor(width, nMax, colour1, colour2) {
|
||||
constructor(width, start, nMax, wave, colour1, colour2) {
|
||||
super();
|
||||
this.width = width;
|
||||
this.start = start;
|
||||
this.nMax = nMax;
|
||||
this.wave = wave;
|
||||
this.colour1 = colour1;
|
||||
this.colour2 = colour2;
|
||||
}
|
||||
// Draw_nodal(300, 100, 31, rotation, "blue");
|
||||
draw(angle) {
|
||||
drawWave(angle) {
|
||||
angle /= 1000
|
||||
const startColor = [45, 129, 252];
|
||||
const endColor = [252, 3, 98];
|
||||
const distanceMultiplier = 3;
|
||||
const maxIterations = 200;
|
||||
// angle=0;
|
||||
for (let n = 0; n < maxIterations; n++) {
|
||||
ctx.beginPath();
|
||||
const nColor = lerpRGB(startColor, endColor, Math.cos(rad(n / 2)));
|
||||
|
||||
// const nAngle = n* angle ;
|
||||
// const nAngle = n*angle+ Math.sin(rad(n*1+angle*4000))/1 ;
|
||||
const nAngle = n * angle + Math.sin(rad(n * 1 + angle * 40000)) / 2;
|
||||
const radius = distanceMultiplier * n;
|
||||
const xCoord = radius * Math.cos(nAngle) + centerX;
|
||||
const yCoord = radius * Math.sin(nAngle) + centerY;
|
||||
ctx.arc(xCoord, yCoord, 8, 0, 2 * Math.PI);
|
||||
ctx.fillStyle = colourToText(nColor);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
drawSpiral(angle) {
|
||||
angle /= 7000
|
||||
const startColor = [45, 129, 252];
|
||||
const endColor = [252, 3, 98];
|
||||
const distanceMultiplier = 2;
|
||||
const maxIterations = 1000;
|
||||
|
||||
for (let n = 0; n < maxIterations; n++) {
|
||||
const nColor = lerpRGB(startColor, endColor, Math.cos(rad(n / 2)));
|
||||
|
||||
const nAngle = n * angle + Math.sin(angle * n * 2);
|
||||
const radius = distanceMultiplier * n;
|
||||
const xCoord = radius * Math.cos(nAngle) + centerX;
|
||||
const yCoord = radius * Math.sin(nAngle) + centerY;
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(xCoord, yCoord, 8, 0, 2 * Math.PI);
|
||||
ctx.fillStyle = colourToText(nColor);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
// Draw_nodal(300, 100, 31, rotation, "blue");
|
||||
draw(rotation) {
|
||||
rotation *= (this.speedMultiplier / 300)
|
||||
rotation += this.start
|
||||
if (this.wave === 1) {
|
||||
this.drawWave(rotation)
|
||||
}
|
||||
else if (this.wave === 2) {
|
||||
this.drawSpiral(rotation)
|
||||
}
|
||||
else {
|
||||
for (let n = 0; n < this.nMax; n += 1) {
|
||||
const ncolour = LerpHex(this.colour1, this.colour2, n / this.nMax);
|
||||
// const ncolour = LerpHex(this.colour1, this.colour2, (n/this.nMax)**2);
|
||||
const a = n * (angle / 1000)//137.5;
|
||||
const a = n * (rotation / 1000)//137.5;
|
||||
const r = this.width * Math.sqrt(n);
|
||||
const x = r * Math.cos(a) + centerX;
|
||||
const y = r * Math.sin(a) + centerY;
|
||||
|
@ -273,7 +311,7 @@ class Phyllotaxis extends BaseShape {
|
|||
ctx.fill();
|
||||
// console.log(this.c)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
class SquareTwist_angle extends BaseShape {
|
||||
|
@ -295,92 +333,213 @@ class SquareTwist_angle extends BaseShape {
|
|||
ctx.restore();
|
||||
}
|
||||
// DrawSquareTwist_angle(400,0,rotation,"red")
|
||||
draw(innerRotation) {
|
||||
let out_angle = innerRotation;
|
||||
draw(rotation) {
|
||||
rotation *= (this.speedMultiplier / 100)
|
||||
let out_angle = rotation;
|
||||
let widthMultiplier = 1 / (2 * Math.sin(Math.PI / 180 * (130 - out_angle + 90 * Math.floor(out_angle / 90)))) + 0.5
|
||||
|
||||
for (let i = 0; i < 25; i++) {
|
||||
this.drawSquare(innerRotation * i, this.width * widthMultiplier ** i, this.colour1)
|
||||
this.drawSquare(rotation * i, this.width * widthMultiplier ** i, this.colour1)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
class rectangle_pattern1 extends BaseShape {
|
||||
constructor(width, squares, line_width, colour1) {
|
||||
|
||||
class CircleExpand extends BaseShape {
|
||||
constructor(nCircles, gap, linear, heart, colour1, colour2) {
|
||||
super();
|
||||
this.width = width;
|
||||
this.squares = squares;
|
||||
this.line_width = line_width;
|
||||
this.nCircles = nCircles;
|
||||
this.gap = gap;
|
||||
this.linear = linear;
|
||||
this.heart = heart;
|
||||
this.colour1 = colour1;
|
||||
this.colour2 = colour2
|
||||
}
|
||||
drawSquare(angle, size, colour) {
|
||||
ctx.save();
|
||||
ctx.translate(centerX, centerY)//-(Math.sin(rad(angle)) *centerX));
|
||||
ctx.rotate(rad(angle + 180));
|
||||
lerpColor(a, b, amount) {
|
||||
var ah = +a.replace('#', '0x'),
|
||||
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);
|
||||
|
||||
return '#' + ((1 << 24) + (rr << 16) + (rg << 8) + rb | 0).toString(16).slice(1);
|
||||
}
|
||||
|
||||
arraySort(x, y) {
|
||||
if (x.r > y.r) {
|
||||
return 1;
|
||||
}
|
||||
if (x.r < y.r) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
drawHeart(w, colour) {
|
||||
// var w = 200
|
||||
ctx.strokeStyle = "black";
|
||||
ctx.fillStyle = colour;
|
||||
ctx.lineWidth = 1;
|
||||
var x = centerX - w / 2;
|
||||
let y = centerY - w / 2
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = colour;
|
||||
ctx.lineWidth = this.line_width;
|
||||
ctx.rect(-size / 2, -size / 2, size, size);
|
||||
ctx.moveTo(x, y + w / 4);
|
||||
ctx.quadraticCurveTo(x, y, x + w / 4, y);
|
||||
ctx.quadraticCurveTo(x + w / 2, y, x + w / 2, y + w / 5);
|
||||
ctx.quadraticCurveTo(x + w / 2, y, x + w * 3 / 4, y);
|
||||
ctx.quadraticCurveTo(x + w, y, x + w, y + w / 4);
|
||||
ctx.quadraticCurveTo(x + w, y + w / 2, x + w * 3 / 4, y + w * 3 / 4);
|
||||
ctx.lineTo(x + w / 2, y + w);
|
||||
ctx.lineTo(x + w / 4, y + w * 3 / 4);
|
||||
ctx.quadraticCurveTo(x, y + w / 2, x, y + w / 4);
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
ctx.fill();
|
||||
}
|
||||
// Draw_rectangle_pattern1(rotation, squares, 200, "blue");
|
||||
|
||||
draw(rotation) {
|
||||
for (let z = 0; z < 360; z += 360 / this.squares) {
|
||||
this.drawSquare(z + rotation, this.width, this.colour1);
|
||||
rotation *= (0.9)
|
||||
ctx.strokeWeight = 1;
|
||||
ctx.lineWidth = 1;
|
||||
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--) {
|
||||
let newColour = this.lerpColor(this.colour1, this.colour2, newArr[i].c)
|
||||
|
||||
if (this.heart) {
|
||||
this.drawHeart(newArr[i].r, newColour)
|
||||
}
|
||||
else {
|
||||
ctx.beginPath();
|
||||
ctx.arc(centerX, centerY, newArr[i].r, 0, 2 * Math.PI);
|
||||
ctx.fillStyle = newColour;
|
||||
ctx.fill();
|
||||
ctx.stokeStyle = "black";
|
||||
ctx.stroke();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class EyePrototype extends BaseShape {
|
||||
constructor(width, line_width, colour1) {
|
||||
constructor(x, y, rotate, flip, width, blink_speed, draw_spiral, spiral_full, draw_pupil, draw_expand, draw_hypno, line_width, colourPupil, colourSpiral, colourExpand) {
|
||||
super();
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.rotate = rotate;
|
||||
this.flip = flip
|
||||
this.width = width;
|
||||
this.blink_speed = blink_speed;
|
||||
this.line_width = line_width;
|
||||
this.colour1 = colour1;
|
||||
this.step = 0;
|
||||
this.speed = 8;
|
||||
this.opening = true;
|
||||
this.counter = 0;
|
||||
this.points = [
|
||||
[50, 250],
|
||||
[450, 250],
|
||||
];
|
||||
this.cooldown = 0;
|
||||
this.draw_spiral = draw_spiral;
|
||||
this.spiral_full = spiral_full;
|
||||
this.draw_pupil = draw_pupil;
|
||||
this.draw_expand = draw_expand;
|
||||
this.draw_hypno = draw_hypno;
|
||||
this.colourPupil = colourPupil;
|
||||
this.colourSpiral = colourSpiral;
|
||||
this.colourExpand = colourExpand;
|
||||
this.centerPulse = new CircleExpand(10, 30, 1, 0, "#2D81FC", "#FC0362")
|
||||
}
|
||||
drawEyelid(step) {
|
||||
drawEyelid(rotation) {
|
||||
ctx.strokeStyle = "orange";
|
||||
let relCenterX = centerX + this.x;
|
||||
let relCenterY = centerY + this.y;
|
||||
rotation *= (this.speedMultiplier / 100)
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.points[0][0], this.points[0][1]);
|
||||
ctx.quadraticCurveTo(250, 250 - step, this.points[1][0], this.points[0][1]);
|
||||
let newPoint = 0
|
||||
let newPoint1 = 0
|
||||
let addedRotate = this.flip ? 90 : 0
|
||||
newPoint = rotatePoint(- this.width / 2, 0, this.rotate + addedRotate)
|
||||
ctx.moveTo(relCenterX + newPoint[0], relCenterY + newPoint[1]);
|
||||
newPoint = rotatePoint(0, - rotation / 400 * this.width, this.rotate + addedRotate)
|
||||
newPoint1 = rotatePoint(this.width / 2, 0, this.rotate + addedRotate)
|
||||
ctx.quadraticCurveTo(relCenterX + newPoint[0], relCenterY + newPoint[1], relCenterX + newPoint1[0], relCenterY + newPoint1[1]);
|
||||
|
||||
ctx.moveTo(this.points[0][0], this.points[0][1]);
|
||||
ctx.quadraticCurveTo(250, 250 + step, this.points[1][0], this.points[0][1]);
|
||||
newPoint = rotatePoint(- this.width / 2, 0, this.rotate + addedRotate)
|
||||
ctx.moveTo(relCenterX + newPoint[0], relCenterY + newPoint[1]);
|
||||
newPoint = rotatePoint(0, + rotation / 400 * this.width, this.rotate + addedRotate)
|
||||
newPoint1 = rotatePoint(this.width / 2, 0, this.rotate + addedRotate)
|
||||
ctx.quadraticCurveTo(relCenterX + newPoint[0], relCenterY + newPoint[1], relCenterX + newPoint1[0], relCenterY + newPoint1[1]);
|
||||
ctx.stroke();
|
||||
}
|
||||
eyelidCut(step) {
|
||||
eyelidCut(rotation) {
|
||||
let relCenterX = centerX + this.x;
|
||||
let relCenterY = centerY + this.y;
|
||||
let newPoint = 0
|
||||
let newPoint1 = 0
|
||||
let addedRotate = this.flip ? 90 : 0
|
||||
// ctx.lineWidth = 1;
|
||||
let squarePath = new Path2D();
|
||||
squarePath.moveTo(this.points[0][0], this.points[0][1]);
|
||||
squarePath.quadraticCurveTo(250, 250 - step, this.points[1][0], this.points[0][1]);
|
||||
newPoint = rotatePoint(- this.width / 2, 0, this.rotate + addedRotate)
|
||||
squarePath.moveTo(relCenterX + newPoint[0], relCenterY + newPoint[1]);
|
||||
newPoint = rotatePoint(0, - rotation / 400 * this.width, this.rotate + addedRotate)
|
||||
newPoint1 = rotatePoint(this.width / 2, 0, this.rotate + addedRotate)
|
||||
squarePath.quadraticCurveTo(relCenterX + newPoint[0], relCenterY + newPoint[1], relCenterX + newPoint1[0], relCenterY + newPoint1[1]);
|
||||
|
||||
squarePath.moveTo(this.points[0][0], this.points[0][1]);
|
||||
squarePath.quadraticCurveTo(250, 250 + step, this.points[1][0], this.points[0][1]);
|
||||
newPoint = rotatePoint(- this.width / 2, 0, this.rotate + addedRotate)
|
||||
squarePath.moveTo(relCenterX + newPoint[0], relCenterY + newPoint[1]);
|
||||
newPoint = rotatePoint(0, + rotation / 400 * this.width, this.rotate + addedRotate)
|
||||
newPoint1 = rotatePoint(this.width / 2, 0, this.rotate + addedRotate)
|
||||
squarePath.quadraticCurveTo(relCenterX + newPoint[0], relCenterY + newPoint[1], relCenterX + newPoint1[0], relCenterY + newPoint1[1]);
|
||||
|
||||
ctx.clip(squarePath);
|
||||
}
|
||||
drawGrowEye(step) {
|
||||
console.log(step)
|
||||
ctx.strokeStyle = "aqua";
|
||||
// console.log(step)
|
||||
ctx.strokeStyle = this.colourExpand
|
||||
ctx.beginPath();
|
||||
ctx.lineWidth = 5;
|
||||
ctx.arc(250, 250, step, 0, 2 * Math.PI);
|
||||
ctx.arc(centerX + this.x, centerY + this.y, step, 0, 2 * Math.PI);
|
||||
ctx.stroke();
|
||||
ctx.strokeStyle = "orange";
|
||||
}
|
||||
drawCircle(step) {
|
||||
ctx.strokeStyle = this.colourPupil
|
||||
ctx.beginPath();
|
||||
ctx.lineWidth = 5;
|
||||
ctx.arc(250, 250, step, 0, 2 * Math.PI);
|
||||
ctx.arc(centerX + this.x, centerY + this.y, step, 0, 2 * Math.PI);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
drawSpiral(step) {
|
||||
ctx.strokeStyle = this.colourSpiral;
|
||||
let a = 1
|
||||
let b = 5
|
||||
ctx.moveTo(centerX, centerY);
|
||||
ctx.beginPath();
|
||||
let max = this.spiral_full ? this.width : this.width / 2
|
||||
for (let i = 0; i < max; 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 + this.x, y + this.y);
|
||||
}
|
||||
ctx.lineWidth = 3;
|
||||
ctx.stroke();
|
||||
}
|
||||
stepFunc() {
|
||||
|
@ -391,47 +550,54 @@ class EyePrototype extends BaseShape {
|
|||
if (this.step >= 200) {
|
||||
this.cooldown = 200;
|
||||
this.opening = false;
|
||||
this.step -= this.speed;
|
||||
this.step -= this.blink_speed;
|
||||
} else {
|
||||
this.step += this.speed;
|
||||
this.step += this.blink_speed;
|
||||
}
|
||||
} else {
|
||||
if (this.step <= 0) {
|
||||
this.opening = true;
|
||||
this.step += this.speed;
|
||||
this.step += this.blink_speed;
|
||||
} else {
|
||||
this.step -= this.speed;
|
||||
this.step -= this.blink_speed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
draw(rotation) {
|
||||
console.log(this.counter)
|
||||
ctx.strokeStyle = "orange";
|
||||
let speedMult = 50
|
||||
// console.log(this.blink_speed)
|
||||
let waitTime = this.blink_speed
|
||||
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)
|
||||
|
||||
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);
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.rect(100, 100, 300, 300);
|
||||
ctx.stroke();
|
||||
|
||||
this.drawEyelid(this.step);
|
||||
|
||||
ctx.save();
|
||||
this.drawEyelid(outputRotation);
|
||||
// squareCut();
|
||||
this.eyelidCut(this.step);
|
||||
|
||||
if (this.counter % 100 == 0) {
|
||||
this.eyelidCut(outputRotation);
|
||||
// console.log(Math.floor(this.counter % this.width / 2))
|
||||
if (Math.floor(this.counter % (this.width / 4)) === 0) {
|
||||
this.counter = 0;
|
||||
}
|
||||
this.drawGrowEye(100 + this.counter);
|
||||
ctx.fillStyle = "black";
|
||||
ctx.fillRect(this.x - this.width / 2 + centerX, 0, this.width, ctx.canvas.height);
|
||||
if (this.draw_expand) {
|
||||
this.drawGrowEye(this.width / 4 + this.counter);
|
||||
}
|
||||
|
||||
this.drawCircle(100);
|
||||
if (this.draw_hypno) {
|
||||
this.centerPulse.draw(rotation)
|
||||
}
|
||||
if (this.draw_spiral) {
|
||||
this.drawSpiral(rotation)
|
||||
}
|
||||
if (this.draw_pupil) {
|
||||
this.drawCircle(this.width / 4);
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
|
||||
|
@ -439,4 +605,31 @@ class EyePrototype extends BaseShape {
|
|||
this.counter++;
|
||||
}
|
||||
}
|
||||
class MaryFace extends BaseShape {
|
||||
constructor(x1, y1, rotate1, width1, x2, y2, rotate2, width2) {
|
||||
super();
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
this.rotate1 = rotate1;
|
||||
this.width1 = width1;
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
this.rotate2 = rotate2;
|
||||
this.width2 = width2;
|
||||
this.eye1 = new EyePrototype(x1, y1, rotate1, 0, width1, 10, 1, 1, 0, 0, 0, 1, "#00fffb", "#00fffb", "#00fffb")
|
||||
this.eye2 = new EyePrototype(x2, y2, rotate2, 0, width2, 10, 1, 1, 0, 0, 0, 1, "#00fffb", "#00fffb", "#00fffb")
|
||||
// this.eye3 = new EyePrototype(112, -280, rotate2+2,1, width2, 10, 1, 1, 0, 0, 1, "#00fffb", "#00fffb", "#00fffb")
|
||||
this.eye3 = new EyePrototype(110, -280, rotate2 + 2, 1, width2, 10, 1, 1, 0, 0, 0, 1, "#00fffb", "#00fffb", "#00fffb")//maybe
|
||||
}
|
||||
|
||||
draw(rotation) {
|
||||
let img = new Image();
|
||||
img.src = "maryFace.png";
|
||||
|
||||
ctx.drawImage(img, centerX - img.width / 2, centerY - img.height / 2);
|
||||
this.eye1.draw(rotation);
|
||||
this.eye2.draw(rotation);
|
||||
this.eye3.draw(rotation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
Loading…
Reference in New Issue