2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2016-09-20 04:32:51 +08:00
|
|
|
const MAX_PARTICLES = 150;
|
2016-09-20 04:11:15 +08:00
|
|
|
|
|
|
|
const SIZE = 144;
|
|
|
|
|
|
|
|
let width, height;
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
const COLORS = [
|
|
|
|
"#BF1E2E",
|
|
|
|
"#F1592A",
|
|
|
|
"#F7941D",
|
|
|
|
"#9EB83B",
|
|
|
|
"#3AB54A",
|
|
|
|
"#12A89D",
|
|
|
|
"#25AAE2",
|
|
|
|
"#0E76BD",
|
|
|
|
"#652D90",
|
|
|
|
"#92278F",
|
|
|
|
"#ED207B",
|
|
|
|
"#8C6238"
|
|
|
|
];
|
2016-09-20 04:11:15 +08:00
|
|
|
|
|
|
|
class Particle {
|
|
|
|
constructor() {
|
|
|
|
this.reset();
|
2018-06-15 23:03:24 +08:00
|
|
|
this.y = Math.random() * (height + SIZE) - SIZE;
|
2016-09-20 04:11:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
this.y = -SIZE;
|
2016-09-20 04:30:56 +08:00
|
|
|
this.origX = Math.random() * (width + SIZE);
|
2016-09-20 04:11:15 +08:00
|
|
|
this.speed = 1 + Math.random();
|
|
|
|
this.ang = Math.random() * 2 * Math.PI;
|
2018-06-15 23:03:24 +08:00
|
|
|
this.scale = Math.random() * 0.4 + 0.2;
|
|
|
|
this.radius = Math.random() * 25 + 25;
|
2016-09-20 04:11:15 +08:00
|
|
|
this.color = COLORS[Math.floor(Math.random() * COLORS.length)];
|
2018-06-15 23:03:24 +08:00
|
|
|
this.flipped = Math.random() > 0.5 ? 1 : -1;
|
2016-09-20 04:11:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
move() {
|
|
|
|
this.y += this.speed;
|
|
|
|
|
|
|
|
if (this.y > height + SIZE) {
|
|
|
|
this.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.ang += this.speed / 30.0;
|
|
|
|
if (this.ang > 2 * Math.PI) {
|
|
|
|
this.ang = 0;
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.x = this.origX + this.radius * Math.sin(this.ang);
|
2016-09-20 04:11:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-24 00:30:52 +08:00
|
|
|
export default Component.extend({
|
2018-06-15 23:03:24 +08:00
|
|
|
classNames: ["wizard-canvas"],
|
|
|
|
tagName: "canvas",
|
2016-09-20 04:11:15 +08:00
|
|
|
ctx: null,
|
|
|
|
ready: false,
|
2017-08-21 20:56:22 +08:00
|
|
|
particles: null,
|
2016-09-20 04:11:15 +08:00
|
|
|
|
|
|
|
didInsertElement() {
|
2019-01-19 17:05:51 +08:00
|
|
|
this._super(...arguments);
|
2016-09-20 04:11:15 +08:00
|
|
|
|
2019-07-16 18:45:15 +08:00
|
|
|
const canvas = this.element;
|
2018-06-15 23:03:24 +08:00
|
|
|
this.ctx = canvas.getContext("2d");
|
2016-09-20 04:11:15 +08:00
|
|
|
this.resized();
|
|
|
|
|
|
|
|
this.particles = [];
|
2018-06-15 23:03:24 +08:00
|
|
|
for (let i = 0; i < MAX_PARTICLES; i++) {
|
2016-09-20 04:11:15 +08:00
|
|
|
this.particles.push(new Particle());
|
|
|
|
}
|
|
|
|
|
|
|
|
this.ready = true;
|
|
|
|
this.paint();
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
$(window).on("resize.wizard", () => this.resized());
|
2016-09-20 04:11:15 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
2019-01-19 17:05:51 +08:00
|
|
|
this._super(...arguments);
|
2018-06-15 23:03:24 +08:00
|
|
|
$(window).off("resize.wizard");
|
2016-09-20 04:11:15 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
resized() {
|
|
|
|
width = $(window).width();
|
|
|
|
height = $(window).height();
|
|
|
|
|
2019-07-16 18:45:15 +08:00
|
|
|
const canvas = this.element;
|
2016-09-20 04:11:15 +08:00
|
|
|
canvas.width = width;
|
|
|
|
canvas.height = height;
|
|
|
|
},
|
|
|
|
|
|
|
|
paint() {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (this.isDestroying || this.isDestroyed || !this.ready) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-20 04:11:15 +08:00
|
|
|
|
|
|
|
const { ctx } = this;
|
|
|
|
ctx.clearRect(0, 0, width, height);
|
|
|
|
|
|
|
|
this.particles.forEach(particle => {
|
|
|
|
particle.move();
|
|
|
|
this.drawParticle(particle);
|
|
|
|
});
|
|
|
|
|
|
|
|
window.requestAnimationFrame(() => this.paint());
|
|
|
|
},
|
|
|
|
|
|
|
|
drawParticle(p) {
|
|
|
|
const c = this.ctx;
|
|
|
|
|
|
|
|
c.save();
|
|
|
|
c.translate(p.x - SIZE, p.y - SIZE);
|
2016-09-20 04:41:06 +08:00
|
|
|
c.scale(p.scale * p.flipped, p.scale);
|
2016-09-20 04:11:15 +08:00
|
|
|
c.fillStyle = p.color;
|
|
|
|
c.strokeStyle = p.color;
|
|
|
|
c.globalAlpha = "1.0";
|
|
|
|
c.lineWidth = "1";
|
|
|
|
c.lineCap = "butt";
|
|
|
|
c.lineJoin = "round";
|
|
|
|
c.mitterLimit = "1";
|
|
|
|
c.beginPath();
|
2018-06-15 23:03:24 +08:00
|
|
|
c.moveTo(97.9, 194.9);
|
|
|
|
c.lineTo(103.5, 162.9);
|
|
|
|
c.bezierCurveTo(88.7, 152, 84.2, 139.7, 90.2, 126.3);
|
|
|
|
c.bezierCurveTo(99.5, 105.6, 124.6, 89.6, 159.7, 100.4);
|
|
|
|
c.lineTo(159.7, 100.4);
|
|
|
|
c.bezierCurveTo(175.9, 105.4, 186.4, 111.2, 192.6, 118.5);
|
|
|
|
c.bezierCurveTo(200, 127.2, 201.6, 138.4, 197.5, 152.7);
|
|
|
|
c.bezierCurveTo(194, 165, 187.4, 173.6, 177.9, 178.3);
|
|
|
|
c.bezierCurveTo(165.6, 184.4, 148.4, 183.7, 129.4, 176.3);
|
|
|
|
c.bezierCurveTo(127.7, 175.6, 126, 174.9, 124.4, 174.2);
|
|
|
|
c.lineTo(97.9, 194.9);
|
2016-09-20 04:11:15 +08:00
|
|
|
c.closePath();
|
2018-06-15 23:03:24 +08:00
|
|
|
c.moveTo(138, 99.3);
|
|
|
|
c.bezierCurveTo(115.4, 99.3, 99.3, 111.9, 92.4, 127.3);
|
|
|
|
c.bezierCurveTo(86.8, 139.7, 91.2, 151.2, 105.5, 161.5);
|
|
|
|
c.lineTo(106.1, 161.9);
|
|
|
|
c.lineTo(101.2, 189.4);
|
|
|
|
c.lineTo(124, 171.7);
|
|
|
|
c.lineTo(124.6, 172);
|
|
|
|
c.bezierCurveTo(126.4, 172.8, 128.3, 173.6, 130.2, 174.3);
|
|
|
|
c.bezierCurveTo(148.6, 181.4, 165.1, 182.2, 176.8, 176.4);
|
|
|
|
c.bezierCurveTo(185.7, 172, 191.9, 163.9, 195.2, 152.2);
|
|
|
|
c.bezierCurveTo(202.4, 127.2, 191.9, 112.8, 159, 102.7);
|
|
|
|
c.lineTo(159, 102.7);
|
|
|
|
c.bezierCurveTo(151.6, 100.3, 144.5, 99.3, 138, 99.3);
|
2016-09-20 04:11:15 +08:00
|
|
|
c.closePath();
|
|
|
|
c.fill();
|
|
|
|
c.stroke();
|
|
|
|
c.beginPath();
|
2018-06-15 23:03:24 +08:00
|
|
|
c.moveTo(115.7, 136.2);
|
|
|
|
c.bezierCurveTo(115.7, 137.9, 115, 139.3, 113.3, 139.3);
|
|
|
|
c.bezierCurveTo(111.6, 139.3, 110.2, 137.9, 110.2, 136.2);
|
|
|
|
c.bezierCurveTo(110.2, 134.5, 111.6, 133.1, 113.3, 133.1);
|
|
|
|
c.bezierCurveTo(115, 133, 115.7, 134.4, 115.7, 136.2);
|
2016-09-20 04:11:15 +08:00
|
|
|
c.closePath();
|
|
|
|
c.fill();
|
|
|
|
c.stroke();
|
|
|
|
c.beginPath();
|
2018-06-15 23:03:24 +08:00
|
|
|
c.moveTo(145.8, 141.6);
|
|
|
|
c.bezierCurveTo(145.8, 143.3, 144.4, 144.1, 142.7, 144.1);
|
|
|
|
c.bezierCurveTo(141, 144.1, 139.6, 143.4, 139.6, 141.6);
|
|
|
|
c.bezierCurveTo(139.6, 141.6, 141, 138.5, 142.7, 138.5);
|
|
|
|
c.bezierCurveTo(144.4, 138.5, 145.8, 139.9, 145.8, 141.6);
|
2016-09-20 04:11:15 +08:00
|
|
|
c.closePath();
|
|
|
|
c.fill();
|
|
|
|
c.stroke();
|
|
|
|
c.beginPath();
|
2018-06-15 23:03:24 +08:00
|
|
|
c.moveTo(171.6, 146.8);
|
|
|
|
c.bezierCurveTo(171.6, 148.5, 171, 149.9, 169.2, 149.9);
|
|
|
|
c.bezierCurveTo(167.5, 149.9, 166.1, 148.5, 166.1, 146.8);
|
|
|
|
c.bezierCurveTo(166.1, 145.1, 167.5, 143.7, 169.2, 143.7);
|
|
|
|
c.bezierCurveTo(171, 143.6, 171.6, 145, 171.6, 146.8);
|
2016-09-20 04:11:15 +08:00
|
|
|
c.closePath();
|
|
|
|
c.fill();
|
|
|
|
c.stroke();
|
|
|
|
c.restore();
|
|
|
|
}
|
|
|
|
});
|