blob: b266e61c7422577583019eaebbdb3c97c8d38afd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import kotlinx.browser.document
import org.w3c.dom.CanvasRenderingContext2D
import org.w3c.dom.HTMLCanvasElement
class Renderer(val w: Int, val h: Int) {
private val canvas = (document.createElement("canvas") as HTMLCanvasElement)
.apply {
width = w
height = h
}
private val context = canvas.getContext("2d") as CanvasRenderingContext2D
init {
document.body!!.appendChild(canvas)
}
fun drawLine(startX: Int, startY: Int, endX: Int, endY: Int, cssColour: String = "#FF0000") {
context.strokeStyle = cssColour
context.lineWidth = 4.0
context.beginPath()
context.moveTo(startX.toDouble(), startY.toDouble())
context.lineTo(endX.toDouble(), endY.toDouble())
context.stroke()
}
fun clear() {
context.clearRect(0.0, 0.0, w.toDouble(), h.toDouble())
}
}
|