blob: f73a17bef84ed783b0ee2c249515e98c308862b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
import Terrain from './Terrain.js';
import Canvas from './Canvas.js';
import Brush from './Brush.js';
import BrushSelector from './BrushSelector.js';
const $ = id => document.getElementById(id)
window.onload = () => {
const canvas = new Canvas('root');
const terrain = new Terrain();
const selector = new BrushSelector('root', canvas, terrain);
let brushing = false;
canvas.onMouseDown = e => {
if (e.button == 0) brushing = true;
};
canvas.onMouseUp = e => {
if (e.button == 0) brushing = false;
};
const pos = canvas.mouse.drawingPos;
canvas.onMouseMove = () => {
if (brushing) selector.apply();
canvas.draw();
};
canvas.onDraw = ct => {
terrain.render(ct);
ct.strokeStyle = '#fff';
ct.lineWidth = canvas.pixelsToUnits(1);
ct.beginPath();
ct.arc(pos.x, pos.y, canvas.pixelsToUnits(selector.radiusSlider.value), 0, 2*Math.PI);
ct.closePath();
ct.stroke();
};
canvas.draw();
}
|