Fixed animations and added maryFace
This commit is contained in:
parent
2091c4bd95
commit
0716d1286e
|
@ -12,6 +12,7 @@
|
||||||
<div id="toolbar">
|
<div id="toolbar">
|
||||||
<br>
|
<br>
|
||||||
<select id="shape-selector">
|
<select id="shape-selector">
|
||||||
|
<option value="MaryFace">MaryFace</option>
|
||||||
<option value="CircleExpand">CircleExpand</option>
|
<option value="CircleExpand">CircleExpand</option>
|
||||||
<option value="EyePrototype">EyePrototype</option>
|
<option value="EyePrototype">EyePrototype</option>
|
||||||
<option value="PolyTwistColourWidth">PolyTwistColourWidth</option>
|
<option value="PolyTwistColourWidth">PolyTwistColourWidth</option>
|
||||||
|
|
|
@ -15,7 +15,7 @@ async function fetchConfig(className) {
|
||||||
{ type: "range", min: 1, max: 600, defaultValue: 300, property: "width" },
|
{ 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: 100, defaultValue: 50, property: "depth" },
|
||||||
{ type: "color", defaultValue: "#4287f5", property: "colour1" },
|
{ type: "color", defaultValue: "#4287f5", property: "colour1" },
|
||||||
{ type: "color", defaultValue: "#4287f5", property: "colour2" },
|
{ type: "color", defaultValue: "#FC0362", property: "colour2" },
|
||||||
],
|
],
|
||||||
Spiral1: [
|
Spiral1: [
|
||||||
{ type: "range", min: 1, max: 50, defaultValue: 20, property: "sides" },
|
{ type: "range", min: 1, max: 50, defaultValue: 20, property: "sides" },
|
||||||
|
@ -66,25 +66,38 @@ async function fetchConfig(className) {
|
||||||
{ type: "color", defaultValue: "#2D81FC", property: "colour1" },
|
{ type: "color", defaultValue: "#2D81FC", property: "colour1" },
|
||||||
],
|
],
|
||||||
EyePrototype: [
|
EyePrototype: [
|
||||||
|
{ type: "range", min: -400, max: 400, defaultValue: 0, property: "x" },
|
||||||
|
{ type: "range", min: -400, max: 400, defaultValue: 0, property: "y" },
|
||||||
|
{ type: "range", min: -180, max: 180, defaultValue: 0, property: "rotate" },
|
||||||
{ type: "range", min: 1, max: 800, defaultValue: 400, property: "width" },
|
{ type: "range", min: 1, max: 800, defaultValue: 400, property: "width" },
|
||||||
{ type: "range", min: 1, max: 100, defaultValue: 10, property: "blink_speed" },
|
{ type: "range", min: 1, max: 100, defaultValue: 10, property: "blink_speed" },
|
||||||
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "draw_spiral" },
|
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "draw_spiral" },
|
||||||
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "draw_pupil" },
|
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "draw_pupil" },
|
||||||
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "draw_expand" },
|
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "draw_expand" },
|
||||||
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "draw_eyelid" },
|
|
||||||
{ type: "range", min: 1, max: 10, defaultValue: 1, property: "line_width" },
|
{ type: "range", min: 1, max: 10, defaultValue: 1, property: "line_width" },
|
||||||
{ type: "color", defaultValue: "#00fffb", property: "colourPupil" },
|
{ type: "color", defaultValue: "#00fffb", property: "colourPupil" },
|
||||||
{ type: "color", defaultValue: "#ff0000", property: "colourSpiral" },
|
{ type: "color", defaultValue: "#ff0000", property: "colourSpiral" },
|
||||||
{ type: "color", defaultValue: "#00fffb", property: "colourExpand" },
|
{ type: "color", defaultValue: "#00fffb", property: "colourExpand" },
|
||||||
|
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "draw_eyelid" },
|
||||||
],
|
],
|
||||||
CircleExpand: [
|
CircleExpand: [
|
||||||
{ type: "range", min: 1, max: 70, defaultValue: 70, property: "nCircles" },
|
{ type: "range", min: 1, max: 70, defaultValue: 21, property: "nCircles" },
|
||||||
{ type: "range", min: 1, max: 70, defaultValue: 43, property: "gap" },
|
{ 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: "linear" },
|
||||||
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "heart" },
|
{ type: "range", min: 0, max: 1, defaultValue: 1, property: "heart" },
|
||||||
{ type: "color", defaultValue: "#fc03cf", property: "colour1" },
|
{ type: "color", defaultValue: "#fc03cf", property: "colour1" },
|
||||||
{ type: "color", defaultValue: "#00fffb", property: "colour2" },
|
{ type: "color", defaultValue: "#00fffb", property: "colour2" },
|
||||||
],
|
],
|
||||||
|
MaryFace: [
|
||||||
|
{ type: "range", min: -400, max: 400, defaultValue: -100, property: "x1" },
|
||||||
|
{ type: "range", min: -400, max: 400, defaultValue: -150, property: "y1" },
|
||||||
|
{ type: "range", min: -180, max: 180, defaultValue: 0, property: "rotate1" },
|
||||||
|
{ type: "range", min: 0, max: 400, defaultValue: 160, property: "width1" },
|
||||||
|
{ type: "range", min: -400, max: 400, defaultValue: 200, property: "x2" },
|
||||||
|
{ type: "range", min: -400, max: 400, defaultValue: -30, property: "y2" },
|
||||||
|
{ type: "range", min: -180, max: 180, defaultValue: 0, property: "rotate2" },
|
||||||
|
{ type: "range", min: 0, max: 400, defaultValue: 160, property: "width2" },
|
||||||
|
],
|
||||||
};
|
};
|
||||||
return config[className];
|
return config[className];
|
||||||
}
|
}
|
||||||
|
@ -258,6 +271,12 @@ function colourToText(colour) {
|
||||||
return "rgb(" + colour[0] + "," + colour[1] + "," + colour[2] + ")";
|
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) {
|
function LerpHex(a, b, amount) {
|
||||||
var ah = parseInt(a.replace(/#/g, ""), 16),
|
var ah = parseInt(a.replace(/#/g, ""), 16),
|
||||||
ar = ah >> 16,
|
ar = ah >> 16,
|
||||||
|
|
|
@ -30,6 +30,7 @@ function createInstance(className, args) {
|
||||||
rectangle_pattern1:rectangle_pattern1,
|
rectangle_pattern1:rectangle_pattern1,
|
||||||
EyePrototype:EyePrototype,
|
EyePrototype:EyePrototype,
|
||||||
CircleExpand:CircleExpand,
|
CircleExpand:CircleExpand,
|
||||||
|
MaryFace:MaryFace,
|
||||||
// Add more class constructors here as needed
|
// Add more class constructors here as needed
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -83,8 +83,10 @@ class FloralPhyllo extends BaseShape {
|
||||||
// var c = 24; //something to do with width. but not width
|
// var c = 24; //something to do with width. but not width
|
||||||
var c = 1; //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
|
//dont make larger than 270 unless altering the number of colours in lerpedColours
|
||||||
|
let max = 200;
|
||||||
for (let n = 200; n > 0; n -= 1) {
|
for (let n = 200; n > 0; n -= 1) {
|
||||||
// let ncolour = LerpHex(this.colour1, this.colour2, n);
|
let colVal = waveNormal(n, max)
|
||||||
|
let ncolour = LerpHex(this.colour1, this.colour2, n / max);
|
||||||
const a = n * rotation / 1000; //137.5;
|
const a = n * rotation / 1000; //137.5;
|
||||||
const r = c * Math.sqrt(n);
|
const r = c * Math.sqrt(n);
|
||||||
const x = r * Math.cos(a) + centerX;
|
const x = r * Math.cos(a) + centerX;
|
||||||
|
@ -451,8 +453,11 @@ class CircleExpand extends BaseShape {
|
||||||
|
|
||||||
|
|
||||||
class EyePrototype extends BaseShape {
|
class EyePrototype extends BaseShape {
|
||||||
constructor(width, blink_speed, draw_spiral, draw_pupil, draw_expand, line_width, colourPupil, colourSpiral, colourExpand) {
|
constructor(x, y, rotate, width, blink_speed, draw_spiral, draw_pupil, draw_expand, line_width, colourPupil, colourSpiral, colourExpand) {
|
||||||
super();
|
super();
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.rotate = rotate;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.line_width = line_width;
|
this.line_width = line_width;
|
||||||
this.step = 0;
|
this.step = 0;
|
||||||
|
@ -472,21 +477,21 @@ class EyePrototype extends BaseShape {
|
||||||
rotation *= (this.speedMultiplier / 100)
|
rotation *= (this.speedMultiplier / 100)
|
||||||
ctx.lineWidth = 1;
|
ctx.lineWidth = 1;
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(centerX - this.width / 2, centerY);
|
ctx.moveTo(centerX + this.x - this.width / 2, centerY + this.y);
|
||||||
ctx.quadraticCurveTo(centerX, centerY - rotation / 400 * this.width, centerX + this.width / 2, centerY);
|
ctx.quadraticCurveTo(centerX + this.x, centerY + this.y - rotation / 400 * this.width, centerX + this.x + this.width / 2, centerY + this.y);
|
||||||
|
|
||||||
ctx.moveTo(centerX - this.width / 2, centerY);
|
ctx.moveTo(centerX + this.x - this.width / 2, centerY + this.y);
|
||||||
ctx.quadraticCurveTo(centerX, centerY + rotation / 400 * this.width, centerX + this.width / 2, centerY);
|
ctx.quadraticCurveTo(centerX + this.x, centerY + this.y + rotation / 400 * this.width, centerX + this.x + this.width / 2, centerY + this.y);
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
}
|
}
|
||||||
eyelidCut(step) {
|
eyelidCut(step) {
|
||||||
// ctx.lineWidth = 1;
|
// ctx.lineWidth = 1;
|
||||||
let squarePath = new Path2D();
|
let squarePath = new Path2D();
|
||||||
squarePath.moveTo(centerX - this.width / 2, centerY);
|
squarePath.moveTo(centerX + this.x - this.width / 2, centerY + this.y);
|
||||||
squarePath.quadraticCurveTo(centerX, centerY - step / 400 * this.width, centerX + this.width / 2, centerY);
|
squarePath.quadraticCurveTo(centerX + this.x, centerY + this.y - step / 400 * this.width, centerX + this.x + this.width / 2, centerY + this.y);
|
||||||
|
|
||||||
squarePath.moveTo(centerX - this.width / 2, centerY);
|
squarePath.moveTo(centerX + this.x - this.width / 2, centerY + this.y);
|
||||||
squarePath.quadraticCurveTo(centerX, centerY + step / 400 * this.width, centerX + this.width / 2, centerY);
|
squarePath.quadraticCurveTo(centerX + this.x, centerY + this.y + step / 400 * this.width, centerX + this.x + this.width / 2, centerY + this.y);
|
||||||
|
|
||||||
ctx.clip(squarePath);
|
ctx.clip(squarePath);
|
||||||
}
|
}
|
||||||
|
@ -495,14 +500,14 @@ class EyePrototype extends BaseShape {
|
||||||
ctx.strokeStyle = this.colourExpand
|
ctx.strokeStyle = this.colourExpand
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.lineWidth = 5;
|
ctx.lineWidth = 5;
|
||||||
ctx.arc(centerX, centerY, step, 0, 2 * Math.PI);
|
ctx.arc(centerX + this.x, centerY + this.y, step, 0, 2 * Math.PI);
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
}
|
}
|
||||||
drawCircle(step) {
|
drawCircle(step) {
|
||||||
ctx.strokeStyle = this.colourPupil
|
ctx.strokeStyle = this.colourPupil
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.lineWidth = 5;
|
ctx.lineWidth = 5;
|
||||||
ctx.arc(centerX, centerY, step, 0, 2 * Math.PI);
|
ctx.arc(centerX + this.x, centerY + this.y, step, 0, 2 * Math.PI);
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,7 +522,7 @@ class EyePrototype extends BaseShape {
|
||||||
let x = centerX + (a + b * angle) * Math.cos(angle + step / 2);
|
let x = centerX + (a + b * angle) * Math.cos(angle + step / 2);
|
||||||
let y = centerY + (a + b * angle) * Math.sin(angle + step / 2);
|
let y = centerY + (a + b * angle) * Math.sin(angle + step / 2);
|
||||||
|
|
||||||
ctx.lineTo(x, y);
|
ctx.lineTo(x + this.x, y + this.y);
|
||||||
}
|
}
|
||||||
ctx.lineWidth = 3;
|
ctx.lineWidth = 3;
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
|
@ -568,15 +573,17 @@ class EyePrototype extends BaseShape {
|
||||||
// ctx.stroke();
|
// ctx.stroke();
|
||||||
|
|
||||||
// this.drawEyelid(this.step);
|
// this.drawEyelid(this.step);
|
||||||
this.drawEyelid(outputRotation);
|
|
||||||
|
|
||||||
ctx.save();
|
ctx.save();
|
||||||
|
this.drawEyelid(outputRotation);
|
||||||
// squareCut();
|
// squareCut();
|
||||||
this.eyelidCut(outputRotation);
|
this.eyelidCut(outputRotation);
|
||||||
if (this.counter % 100 == 0) {
|
if (this.counter % 100 == 0) {
|
||||||
this.counter = 0;
|
this.counter = 0;
|
||||||
}
|
}
|
||||||
if (this.drawGrowEye) {
|
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.drawGrowEye(this.width / 4 + this.counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -593,4 +600,28 @@ class EyePrototype extends BaseShape {
|
||||||
this.counter++;
|
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, width1, 10, 1, 1, 0, 1, "#00fffb", "#00fffb", "#00fffb")
|
||||||
|
this.eye2 = new EyePrototype(x2, y2, rotate2, width2, 10, 1, 1, 0, 1, "#00fffb", "#00fffb", "#00fffb")
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
Loading…
Reference in New Issue