From 673e9c13aea6cd1b11f5ca3e1f6edd474bbb1a19 Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 31 Mar 2023 17:17:27 -0500 Subject: implement nice map grid --- src/main.js | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'src/main.js') diff --git a/src/main.js b/src/main.js index f73a17b..a86a38e 100644 --- a/src/main.js +++ b/src/main.js @@ -1,39 +1,37 @@ -import Terrain from './Terrain.js'; import Canvas from './Canvas.js'; -import Brush from './Brush.js'; -import BrushSelector from './BrushSelector.js'; +import { Mat3, Vec3, Point, Shape } from './Geometry.js'; +import { MapGrid } from './MapView.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 canvas = new Canvas($('root')); - let brushing = false; + const xaxis = new Vec3(1, 0, 0); + const yaxis = new Vec3(0, 1, 0); + const zaxis = new Vec3(0, 0, 1); - canvas.onMouseDown = e => { - if (e.button == 0) brushing = true; - }; - canvas.onMouseUp = e => { - if (e.button == 0) brushing = false; - }; + const grid = new MapGrid(30, 90); - const pos = canvas.mouse.drawingPos; - canvas.onMouseMove = () => { - if (brushing) selector.apply(); - canvas.draw(); - }; - - canvas.onDraw = ct => { - terrain.render(ct); + let view = new Mat3(); + let angle = 0; - 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(); + canvas.onDraw = ct => { + ct.fillStyle = "#01162B" + ct.fillRect(-10,-10, 100, 100); + ct.lineWidth = 0.005; + ct.strokeStyle = "#E7305D"; + ct.fillStyle = "blue"; + ct.arc(0, 0, 1, 0, 2*Math.PI); ct.stroke(); + + grid.render(ct, view); }; canvas.draw(); + + setInterval(() => { + angle = angle + 0.01*Math.PI; + view.rotation(xaxis, angle); + canvas.draw(); + }, 50); } -- cgit v1.2.1