a button to repaint
This commit is contained in:
parent
6a11ebf440
commit
49cf653dba
6 changed files with 130 additions and 9 deletions
30
main.js
30
main.js
|
@ -1,21 +1,33 @@
|
|||
import factory from "./painting/factory.js";
|
||||
import Canvas from "./painting/canvas.js";
|
||||
import Shape from "./painting/shape.js";
|
||||
import Button from "./ui/button.js";
|
||||
|
||||
document.body.innerHTML = "";
|
||||
|
||||
Shape.setBounding(window.innerWidth, window.innerHeight);
|
||||
let canvas = new Canvas(window.innerWidth, window.innerHeight);
|
||||
|
||||
let repaint = new Button("paint");
|
||||
repaint.addHandler(canvas.clear.bind(canvas));
|
||||
repaint.addHandler(paint);
|
||||
repaint.setPosition(50, 50);
|
||||
|
||||
window.addEventListener("resize", onWindowResize, false);
|
||||
|
||||
document.body.appendChild(canvas.element);
|
||||
document.body.appendChild(repaint.element);
|
||||
|
||||
let amount = Math.floor(Math.random() * 100 + 50);
|
||||
|
||||
for (let i = 0; i < amount; ++i) {
|
||||
let shape = factory.createRandomShape();
|
||||
canvas.draw(shape);
|
||||
}
|
||||
|
||||
window.addEventListener("resize", function(e) {
|
||||
function onWindowResize(e) {
|
||||
Shape.setBounding(window.innerWidth, window.innerHeight);
|
||||
canvas.resize(window.innerWidth, window.innerHeight);
|
||||
}, false);
|
||||
}
|
||||
|
||||
function paint() {
|
||||
let amount = Math.floor(Math.random() * 100 + 50);
|
||||
|
||||
for (let i = 0; i < amount; ++i) {
|
||||
let shape = factory.createRandomShape();
|
||||
canvas.draw(shape);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue