Skip to content

Commit

Permalink
feat: draw axis
Browse files Browse the repository at this point in the history
  • Loading branch information
istudyatuni committed Feb 9, 2022
1 parent 1018367 commit db2b59c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/components/Canvas.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/** @type {HTMLCanvasElement} */
let canvas,
/** @type {CanvasRenderingContext2D} */
gl = null,
/** @type {ImageData} */
field
Expand All @@ -22,6 +23,8 @@
gl.fillStyle = 'white'
gl.fill()
gl.strokeStyle = 'black'
draw()
}
Expand All @@ -36,6 +39,30 @@
gl.putImageData(field, 0, 0)
wasm.set('none')
drawAxis($settings.lx, $settings.rx, width, height)
}
function drawAxis(lx, rx, width, height) {
if (lx < 0 && rx > 0) {
// y axis
let xw = rx - lx
let scale = width / xw
let ypix = Math.abs(lx) * scale
drawLine(ypix, 0, ypix, height)
}
// x axis now hardcoded to center
let xpix = height / 2
drawLine(0, xpix, width, xpix)
}
function drawLine(sx, sy, ex, ey) {
gl.beginPath()
gl.moveTo(sx, sy)
gl.lineTo(ex, ey)
gl.stroke()
}
onMount(init)
Expand Down

0 comments on commit db2b59c

Please sign in to comment.