2016-07-29 23:25:19 +05:30
|
|
|
|
import React from 'react';
|
|
|
|
|
|
2016-11-12 05:03:12 +05:30
|
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
|
|
|
|
|
2016-11-12 14:35:38 +05:30
|
|
|
|
import { IntlProvider } from 'components/i18n';
|
2016-11-12 05:03:12 +05:30
|
|
|
|
import appInfo from 'components/auth/appInfo/AppInfo.intl.json';
|
|
|
|
|
import messages from './BSoD.intl.json';
|
2016-11-13 15:05:35 +05:30
|
|
|
|
import { rAF as requestAnimationFrame } from 'functions';
|
2016-11-12 05:03:12 +05:30
|
|
|
|
|
|
|
|
|
import styles from './styles.scss';
|
|
|
|
|
|
2016-11-12 14:35:38 +05:30
|
|
|
|
// TODO: probably it is better to render this view from the App view
|
|
|
|
|
// to remove dependencies from store and IntlProvider
|
|
|
|
|
export default function BSoD({store}) {
|
2016-07-29 23:25:19 +05:30
|
|
|
|
return (
|
2016-11-12 14:35:38 +05:30
|
|
|
|
<IntlProvider store={store}>
|
|
|
|
|
<div className={styles.body}>
|
2016-11-13 15:05:35 +05:30
|
|
|
|
<canvas className={styles.canvas} ref={(el) => new BoxesField(el)} />
|
2016-11-12 14:45:23 +05:30
|
|
|
|
|
2016-11-12 14:35:38 +05:30
|
|
|
|
<div className={styles.wrapper}>
|
|
|
|
|
<div className={styles.title}>
|
|
|
|
|
<Message {...appInfo.appName} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.lineWithMargin}>
|
|
|
|
|
<Message {...messages.criticalErrorHappened} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.line}>
|
|
|
|
|
<Message {...messages.reloadPageOrContactUs} />
|
|
|
|
|
</div>
|
|
|
|
|
<a href="mailto:support@ely.by" className={styles.support}>
|
|
|
|
|
support@ely.by
|
|
|
|
|
</a>
|
|
|
|
|
<div className={styles.easterEgg}>
|
|
|
|
|
<Message {...messages.alsoYouCanInteractWithBackground}/>
|
|
|
|
|
</div>
|
2016-11-12 05:03:12 +05:30
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2016-11-12 14:35:38 +05:30
|
|
|
|
</IntlProvider>
|
2016-07-29 23:25:19 +05:30
|
|
|
|
);
|
|
|
|
|
}
|
2016-11-12 14:45:23 +05:30
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
class Box {
|
2016-11-12 14:45:23 +05:30
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
constructor({size, startX, startY, startRotate, color, shadowColor}) {
|
|
|
|
|
this.color = color;
|
|
|
|
|
this.shadowColor = shadowColor;
|
|
|
|
|
this.setSize(size);
|
|
|
|
|
this.x = startX;
|
|
|
|
|
this.y = startY;
|
|
|
|
|
this.angle = startRotate;
|
|
|
|
|
this.shadowLength = 2000; // TODO: should be calculated
|
2016-11-12 14:45:23 +05:30
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
get size() {
|
|
|
|
|
return this._initialSize;
|
2016-11-12 14:45:23 +05:30
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
get dots() {
|
|
|
|
|
const full = (Math.PI * 2) / 4;
|
2016-11-12 14:45:23 +05:30
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
const p1 = {
|
|
|
|
|
x: this.x + this.halfSize * Math.sin(this.angle),
|
|
|
|
|
y: this.y + this.halfSize * Math.cos(this.angle)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const p2 = {
|
|
|
|
|
x: this.x + this.halfSize * Math.sin(this.angle + full),
|
|
|
|
|
y: this.y + this.halfSize * Math.cos(this.angle + full)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const p3 = {
|
|
|
|
|
x: this.x + this.halfSize * Math.sin(this.angle + full * 2),
|
|
|
|
|
y: this.y + this.halfSize * Math.cos(this.angle + full * 2)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const p4 = {
|
|
|
|
|
x: this.x + this.halfSize * Math.sin(this.angle + full * 3),
|
|
|
|
|
y: this.y + this.halfSize * Math.cos(this.angle + full * 3)
|
|
|
|
|
};
|
2016-11-12 14:45:23 +05:30
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
return { p1, p2, p3, p4 };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rotate() {
|
|
|
|
|
const speed = (60 - this.halfSize) / 20;
|
|
|
|
|
this.angle += speed * 0.002;
|
|
|
|
|
this.x += speed;
|
|
|
|
|
this.y += speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
draw(ctx) {
|
|
|
|
|
const dots = this.dots;
|
2016-11-12 14:45:23 +05:30
|
|
|
|
ctx.beginPath();
|
2016-11-13 15:05:35 +05:30
|
|
|
|
ctx.moveTo(dots.p1.x, dots.p1.y);
|
|
|
|
|
ctx.lineTo(dots.p2.x, dots.p2.y);
|
|
|
|
|
ctx.lineTo(dots.p3.x, dots.p3.y);
|
|
|
|
|
ctx.lineTo(dots.p4.x, dots.p4.y);
|
|
|
|
|
ctx.fillStyle = this.color;
|
2016-11-12 14:45:23 +05:30
|
|
|
|
ctx.fill();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
drawShadow(ctx, light) {
|
|
|
|
|
const dots = this.dots;
|
|
|
|
|
const angles = [];
|
|
|
|
|
const points = [];
|
|
|
|
|
|
|
|
|
|
for (const i in dots) {
|
|
|
|
|
const dot = dots[i];
|
|
|
|
|
const angle = Math.atan2(light.y - dot.y, light.x - dot.x);
|
|
|
|
|
const endX = dot.x + this.shadowLength * Math.sin(-angle - Math.PI / 2);
|
|
|
|
|
const endY = dot.y + this.shadowLength * Math.cos(-angle - Math.PI / 2);
|
|
|
|
|
angles.push(angle);
|
|
|
|
|
points.push({
|
|
|
|
|
endX,
|
|
|
|
|
endY,
|
|
|
|
|
startX: dot.x,
|
|
|
|
|
startY: dot.y
|
|
|
|
|
});
|
2016-11-12 14:45:23 +05:30
|
|
|
|
}
|
2016-11-13 15:05:35 +05:30
|
|
|
|
|
|
|
|
|
for (let i = points.length - 1; i >= 0; i--) {
|
|
|
|
|
const n = i === 3 ? 0 : i + 1;
|
2016-11-12 14:45:23 +05:30
|
|
|
|
ctx.beginPath();
|
2016-11-13 15:05:35 +05:30
|
|
|
|
ctx.moveTo(points[i].startX, points[i].startY);
|
|
|
|
|
ctx.lineTo(points[n].startX, points[n].startY);
|
|
|
|
|
ctx.lineTo(points[n].endX, points[n].endY);
|
|
|
|
|
ctx.lineTo(points[i].endX, points[i].endY);
|
|
|
|
|
ctx.fillStyle = this.shadowColor;
|
2016-11-12 14:45:23 +05:30
|
|
|
|
ctx.fill();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
setSize(size) {
|
|
|
|
|
this._initialSize = size;
|
|
|
|
|
this.halfSize = Math.floor(size / 2);
|
|
|
|
|
}
|
2016-11-12 14:45:23 +05:30
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
}
|
2016-11-12 14:45:23 +05:30
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
/**
|
|
|
|
|
* Основано на http://codepen.io/mladen___/pen/gbvqBo
|
|
|
|
|
*/
|
|
|
|
|
class BoxesField {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {Node} elem - canvas DOM node
|
|
|
|
|
* @param {object} params
|
|
|
|
|
*/
|
|
|
|
|
constructor(elem, params = {
|
|
|
|
|
countBoxes: 14,
|
|
|
|
|
boxMinSize: 20,
|
|
|
|
|
boxMaxSize: 75,
|
|
|
|
|
backgroundColor: '#233d49',
|
|
|
|
|
lightColor: '#28555b',
|
|
|
|
|
shadowColor: '#274451',
|
|
|
|
|
boxColors: ['#207e5c', '#5b9aa9', '#e66c69', '#6b5b8c', '#8b5d79', '#dd8650']
|
|
|
|
|
}) {
|
|
|
|
|
this.elem = elem;
|
|
|
|
|
this.ctx = elem.getContext('2d');
|
|
|
|
|
this.params = params;
|
|
|
|
|
|
|
|
|
|
this.light = {
|
|
|
|
|
x: 160,
|
|
|
|
|
y: 200
|
2016-11-12 14:45:23 +05:30
|
|
|
|
};
|
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
this.resize();
|
|
|
|
|
this.drawLoop();
|
|
|
|
|
this.bindWindowListeners();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {Box[]}
|
|
|
|
|
*/
|
|
|
|
|
this.boxes = [];
|
|
|
|
|
while (this.boxes.length < this.params.countBoxes) {
|
|
|
|
|
this.boxes.push(new Box({
|
|
|
|
|
size: Math.floor((Math.random() * (this.params.boxMaxSize - this.params.boxMinSize)) + this.params.boxMinSize),
|
|
|
|
|
startX: Math.floor((Math.random() * elem.width) + 1),
|
|
|
|
|
startY: Math.floor((Math.random() * elem.height) + 1),
|
|
|
|
|
startRotate: Math.random() * Math.PI,
|
|
|
|
|
color: this.getRandomColor(),
|
|
|
|
|
shadowColor: this.params.shadowColor
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-12 14:45:23 +05:30
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
resize() {
|
|
|
|
|
const { width, height } = this.elem.getBoundingClientRect();
|
|
|
|
|
this.elem.width = width;
|
|
|
|
|
this.elem.height = height;
|
2016-11-12 14:45:23 +05:30
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
drawLight(light) {
|
|
|
|
|
const greaterSize = window.screen.width > window.screen.height ? window.screen.width : window.screen.height;
|
|
|
|
|
// еее, теорема пифагора и описывание окружности вокруг квадрата, не зря в универ ходил!!!
|
|
|
|
|
const lightRadius = greaterSize * Math.sqrt(2);
|
|
|
|
|
|
|
|
|
|
this.ctx.beginPath();
|
|
|
|
|
this.ctx.arc(light.x, light.y, lightRadius, 0, 2 * Math.PI);
|
|
|
|
|
const gradient = this.ctx.createRadialGradient(light.x, light.y, 0, light.x, light.y, lightRadius);
|
|
|
|
|
gradient.addColorStop(0, this.params.lightColor);
|
|
|
|
|
gradient.addColorStop(1, this.params.backgroundColor);
|
|
|
|
|
this.ctx.fillStyle = gradient;
|
|
|
|
|
this.ctx.fill();
|
2016-11-12 14:45:23 +05:30
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 15:05:35 +05:30
|
|
|
|
drawLoop() {
|
|
|
|
|
this.ctx.clearRect(0, 0, this.elem.width, this.elem.height);
|
|
|
|
|
this.drawLight(this.light);
|
|
|
|
|
|
|
|
|
|
for (let i in this.boxes) {
|
|
|
|
|
const box = this.boxes[i];
|
|
|
|
|
box.rotate();
|
|
|
|
|
box.drawShadow(this.ctx, this.light);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (let i in this.boxes) {
|
|
|
|
|
const box = this.boxes[i];
|
|
|
|
|
box.draw(this.ctx);
|
|
|
|
|
|
|
|
|
|
// Если квадратик вылетел за пределы экрана
|
|
|
|
|
if (box.y - box.halfSize > this.elem.height) {
|
|
|
|
|
box.y -= this.elem.height + 100;
|
|
|
|
|
this.updateBox(box);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (box.x - box.halfSize > this.elem.width) {
|
|
|
|
|
box.x -= this.elem.width + 100;
|
|
|
|
|
this.updateBox(box);
|
2016-11-12 14:45:23 +05:30
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-13 15:05:35 +05:30
|
|
|
|
|
|
|
|
|
requestAnimationFrame(this.drawLoop.bind(this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bindWindowListeners() {
|
|
|
|
|
window.addEventListener('resize', this.resize.bind(this));
|
|
|
|
|
window.addEventListener('mousemove', (event) => {
|
|
|
|
|
this.light.x = event.clientX;
|
|
|
|
|
this.light.y = event.clientY;
|
|
|
|
|
});
|
2016-11-12 14:45:23 +05:30
|
|
|
|
}
|
2016-11-13 15:05:35 +05:30
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {Box} box
|
|
|
|
|
*/
|
|
|
|
|
updateBox(box) {
|
|
|
|
|
box.color = this.getRandomColor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getRandomColor() {
|
|
|
|
|
return this.params.boxColors[Math.floor((Math.random() * this.params.boxColors.length))];
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 14:45:23 +05:30
|
|
|
|
}
|