From 8aa6645f2311de78f74b35f804cc45c7fcf38f57 Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 30 May 2022 18:19:02 -0500 Subject: add brushes --- src/main.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/main.js') 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(); }; -- cgit v1.2.1