2018-11-18 18:04:50 +00:00
|
|
|
import factory from "./painting/factory.js";
|
2018-11-19 07:59:20 +00:00
|
|
|
import Shape from "./painting/shape.js";
|
2018-11-19 15:03:05 +00:00
|
|
|
|
|
|
|
import Canvas from "./ui/canvas.js";
|
2018-11-19 14:09:43 +00:00
|
|
|
import Button from "./ui/button.js";
|
2018-11-19 14:44:36 +00:00
|
|
|
import Panel from "./ui/panel.js";
|
2018-11-18 00:00:38 +00:00
|
|
|
|
2018-11-18 18:04:50 +00:00
|
|
|
document.body.innerHTML = "";
|
2018-11-19 15:03:05 +00:00
|
|
|
const maxPanelWidth = 300;
|
2018-11-18 10:07:36 +00:00
|
|
|
|
2018-11-19 07:59:20 +00:00
|
|
|
Shape.setBounding(window.innerWidth, window.innerHeight);
|
|
|
|
let canvas = new Canvas(window.innerWidth, window.innerHeight);
|
2018-11-18 18:04:50 +00:00
|
|
|
|
2018-11-19 14:09:43 +00:00
|
|
|
let repaint = new Button("paint");
|
|
|
|
repaint.addHandler(canvas.clear.bind(canvas));
|
|
|
|
repaint.addHandler(paint);
|
2018-11-19 14:44:36 +00:00
|
|
|
repaint.setPosition(25, 25);
|
|
|
|
|
2018-11-19 15:03:05 +00:00
|
|
|
let panel = new Panel(Math.min(maxPanelWidth ,window.innerWidth - 20), window.innerHeight - 20);
|
|
|
|
panel.setPosition(10, 10);
|
2018-11-19 14:44:36 +00:00
|
|
|
|
|
|
|
let settings = new Button("gear");
|
|
|
|
settings.addHandler(panel.toggle.bind(panel));
|
2018-11-19 15:03:05 +00:00
|
|
|
settings.setPosition(100, 25);
|
2018-11-19 07:59:20 +00:00
|
|
|
|
2018-11-19 14:09:43 +00:00
|
|
|
window.addEventListener("resize", onWindowResize, false);
|
|
|
|
|
|
|
|
document.body.appendChild(canvas.element);
|
2018-11-19 14:44:36 +00:00
|
|
|
document.body.appendChild(panel.element);
|
2018-11-19 14:09:43 +00:00
|
|
|
document.body.appendChild(repaint.element);
|
2018-11-19 14:44:36 +00:00
|
|
|
document.body.appendChild(settings.element);
|
2018-11-19 07:59:20 +00:00
|
|
|
|
2018-11-19 14:09:43 +00:00
|
|
|
function onWindowResize(e) {
|
2018-11-19 07:59:20 +00:00
|
|
|
Shape.setBounding(window.innerWidth, window.innerHeight);
|
2018-11-19 15:03:05 +00:00
|
|
|
canvas.setSize(window.innerWidth, window.innerHeight);
|
|
|
|
panel.setSize(Math.min(maxPanelWidth ,window.innerWidth - 20), window.innerHeight - 20)
|
2018-11-19 14:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function paint() {
|
|
|
|
let amount = Math.floor(Math.random() * 100 + 50);
|
|
|
|
|
|
|
|
for (let i = 0; i < amount; ++i) {
|
|
|
|
let shape = factory.createRandomShape();
|
|
|
|
canvas.draw(shape);
|
|
|
|
}
|
|
|
|
}
|