mirror of
https://github.com/SamEyeBam/animate.git
synced 2026-02-04 09:20:25 +00:00
V1.1
Giant refactor. added layers. ui overhaul. added save/load and we now got presets
This commit is contained in:
60
docs/js/shapes/Spiral1.js
Normal file
60
docs/js/shapes/Spiral1.js
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Spiral1 - Dual-direction spiral pattern
|
||||
*/
|
||||
class Spiral1 extends BaseShape {
|
||||
static config = [
|
||||
{ type: 'range', min: 1, max: 50, defaultValue: 20, property: 'sides' },
|
||||
{ type: 'range', min: 1, max: 600, defaultValue: 240, property: 'width' },
|
||||
{ type: 'color', defaultValue: '#4287f5', property: 'colour' },
|
||||
];
|
||||
|
||||
constructor(sides, width, colour) {
|
||||
super();
|
||||
this.sides = sides;
|
||||
this.width = width;
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
draw(elapsed) {
|
||||
this.updateFilters(elapsed);
|
||||
const rotation = elapsed * (this.speedMultiplier / 100);
|
||||
const rot = Math.round((this.sides - 2) * 180 / this.sides * 2);
|
||||
const piv = 360 / this.sides;
|
||||
let stt = 0.5 * Math.PI - rad(rot);
|
||||
let end = 0;
|
||||
const n = this.width / ((this.width / 10) * (this.width / 10));
|
||||
|
||||
for (let i = 1; i < this.sides + 1; i++) {
|
||||
end = stt + rad(rot);
|
||||
ctx.lineWidth = 5;
|
||||
|
||||
ctx.beginPath();
|
||||
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
|
||||
);
|
||||
ctx.strokeStyle = this.colour;
|
||||
ctx.stroke();
|
||||
|
||||
ctx.beginPath();
|
||||
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
|
||||
);
|
||||
ctx.strokeStyle = this.colour;
|
||||
ctx.stroke();
|
||||
|
||||
stt = end + -(rad(rot - piv));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shapeRegistry.register('Spiral1', Spiral1);
|
||||
Reference in New Issue
Block a user