From ad192fe7068081ed88f8616581bf450d601e99b1 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 29 Dec 2020 20:13:01 +0000 Subject: Add textures --- src/main/kotlin/Renderer.kt | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/main/kotlin/Renderer.kt') diff --git a/src/main/kotlin/Renderer.kt b/src/main/kotlin/Renderer.kt index 8f71352..3a7111e 100644 --- a/src/main/kotlin/Renderer.kt +++ b/src/main/kotlin/Renderer.kt @@ -2,29 +2,38 @@ import kotlinx.browser.document import org.w3c.dom.CanvasRenderingContext2D import org.w3c.dom.HTMLCanvasElement -class Renderer(val viewportWidth: Int, val viewportHeight: Int) { +class Renderer(val viewportWidth: Int, val viewportHeight: Int, private val outputScale: Int) { private val canvas = (document.createElement("canvas") as HTMLCanvasElement) .apply { - width = viewportWidth - height = viewportHeight + width = viewportWidth * outputScale + height = viewportHeight * outputScale } private val context = canvas.getContext("2d") as CanvasRenderingContext2D init { + context.scale(outputScale.toDouble(), outputScale.toDouble()) document.body!!.appendChild(canvas) } - fun drawLine(startX: Int, startY: Int, endX: Int, endY: Int, cssColour: String = "#FF0000") { + fun drawLine(startX: Double, startY: Double, endX: Double, endY: Double, cssColour: String = "#FF0000") { context.strokeStyle = cssColour - context.lineWidth = 4.0 + context.lineWidth = 2.0 context.beginPath() - context.moveTo(startX.toDouble(), startY.toDouble()) - context.lineTo(endX.toDouble(), endY.toDouble()) + context.moveTo(startX, startY) + context.lineTo(endX, endY) context.stroke() } + fun drawLine(startX: Int, startY: Double, endX: Int, endY: Double, cssColour: String = "#FF0000") { + drawLine(startX.toDouble(), startY, endX.toDouble(), endY, cssColour) + } + + fun drawLine(startX: Int, startY: Double, endX: Int, endY: Int, cssColour: String = "#FF0000") { + drawLine(startX.toDouble(), startY, endX.toDouble(), endY.toDouble(), cssColour) + } + fun clear() { context.clearRect(0.0, 0.0, viewportWidth.toDouble(), viewportHeight.toDouble()) } -- cgit v1.2.3