-
-
Save mushtaq/fc1a6c836fdc8be05539c0d219e377c3 to your computer and use it in GitHub Desktop.
ScalaFiddle gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math._ | |
val (h, w) = (Page.canvas.height, Page.canvas.width) | |
var x = 0.0 | |
// $FiddleStart | |
val graphs = Seq[(String, Double => Double)]( | |
("red", sin), | |
("green", x => 2 - abs(x % 8 - 4)), | |
("blue", x => 3 * pow(sin(x / 12), 2) * sin(x)) | |
) | |
// $FiddleEnd | |
.zipWithIndex | |
val count = graphs.size | |
dom.window.setInterval(() => { | |
x = (x + 1) % w | |
if (x == 0) Page.renderer.clearRect(0, 0, w, h) | |
else for (((color, func), i) <- graphs) { | |
val y = func(x/w * 75) * h/40 + h/count * (i+0.5) | |
Page.renderer.fillStyle = color | |
Page.renderer.fillRect(x, y, 3, 3) | |
} | |
}, 10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $Template default | |
case class Pt(x: Double, y: Double) | |
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) | |
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
println("Hello world!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment