diff options
author | sanine <sanine.not@pm.me> | 2022-05-30 18:19:02 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-05-30 18:19:02 -0500 |
commit | 8aa6645f2311de78f74b35f804cc45c7fcf38f57 (patch) | |
tree | 95107aedc3305ef11526ef8dd846c249cc356cdb /src/main.js | |
parent | 9ccb4a7bc728fd0e85c04fddb802fde02b73cfe2 (diff) |
add brushesmain
Diffstat (limited to 'src/main.js')
-rw-r--r-- | src/main.js | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/main.js b/src/main.js index 4527a90..f73a17b 100644 --- a/src/main.js +++ b/src/main.js @@ -1,14 +1,17 @@ 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); - const BRUSH_RADIUS = 80; let brushing = false; + canvas.onMouseDown = e => { if (e.button == 0) brushing = true; }; @@ -18,20 +21,17 @@ window.onload = () => { const pos = canvas.mouse.drawingPos; canvas.onMouseMove = () => { - if (brushing) - terrain.applyBrush(pos.x, pos.y, (pt, strength) => { - pt.hue += 10 * strength; - }, 1, canvas.pixelsToUnits(BRUSH_RADIUS)); + if (brushing) selector.apply(); canvas.draw(); }; canvas.onDraw = ct => { - terrain.renderGrid(ct); + terrain.render(ct); ct.strokeStyle = '#fff'; ct.lineWidth = canvas.pixelsToUnits(1); ct.beginPath(); - ct.arc(pos.x, pos.y, canvas.pixelsToUnits(BRUSH_RADIUS), 0, 2*Math.PI); + ct.arc(pos.x, pos.y, canvas.pixelsToUnits(selector.radiusSlider.value), 0, 2*Math.PI); ct.closePath(); ct.stroke(); }; |