Skip to content

Instantly share code, notes, and snippets.

Created February 21, 2016 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/53ce08fc6095d650257b to your computer and use it in GitHub Desktop.
Save anonymous/53ce08fc6095d650257b to your computer and use it in GitHub Desktop.
ScalaFiddle gist
case class Pt(x: Double, y: Double)
object ScalaFiddle extends js.JSApp{
println("Hello!!")
val corners = Seq(
Pt(Page.canvas.width/2, 0),
Pt(0, Page.canvas.height),
Pt(Page.canvas.width, Page.canvas.height)
)
var p = corners(0)
val (w, h) = (Page.canvas.height.toDouble, Page.canvas.height.toDouble)
def main() = {
dom.window.setInterval(() => for(_ <- 0 until 10){
val c = corners(util.Random.nextInt(3))
p = Pt((p.x + c.x) / 2, (p.y + c.y) / 2)
val m = (p.y / h)
val r = 255 - (p.x / w * m * 255).toInt
val g = 255 - ((w-p.x) / w * m * 255).toInt
val b = 255 - ((h - p.y) / h * 255).toInt
Page.renderer.fillStyle = s"rgb($r, $g, $b)"
Page.renderer.fillRect(p.x, p.y, 1, 1)
}, 10)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment