Skip to content

Instantly share code, notes, and snippets.

Last active July 19, 2022 03:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Playing with Scala.js and a canvas (code)
import scala.scalajs.js.annotation.JSExport
import org.scalajs.dom
import scala.util.Random
object Main {
def main(args: Array[String]): Unit = {
var canvas = dom.document.createElement("canvas")
val height = dom.window.innerHeight.toInt
val width = dom.window.innerWidth.toInt
canvas.height = height
canvas.width = width
val ctx = canvas.getContext("2d")
def reColor() = {
val r = Random.nextInt(255)
val g = Random.nextInt(255)
val b = Random.nextInt(255)
ctx.fillStyle = s"rgb($r, $g, $b)"
ctx.fillRect(0, 0, width, height)
dom.window.setInterval(() => reColor, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment