Skip to content

Instantly share code, notes, and snippets.

Created February 26, 2015 21:28
Show Gist options
  • Select an option

  • Save anonymous/51cfb99d3622a23cc227 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/51cfb99d3622a23cc227 to your computer and use it in GitHub Desktop.
Scala.jsFiddle gist
//
//for use in http://www.scala-js-fiddle.com/
//
object ScalaJSExample extends js.JSApp{
//https://github.com/processing/p5.js/wiki/p5.js-overview#instantiation--namespace
//@JSExport
val sk : js.Function1[js.Dynamic, Unit] = (sketch: js.Dynamic) => {
sketch.setup = () => {
sketch.createCanvas(100, 100);
}
sketch.draw = () => {
sketch.background(255);
sketch.fill(255);
sketch.rect(0,0,50,50);
}
}
def main() = {
//Page.clear();
println(script(src:="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.2/p5.js"))
println(div(id:="playground"))
//http://www.scala-js.org/doc/calling-javascript.html
val document = js.Dynamic.global.document
val playground = document.getElementById("playground")
val newP = document.createElement("p")
newP.innerHTML = "Hello world! <i>-- DOM</i>"
playground.appendChild(newP)
println("test test test")
val xs = Seq(1, 2, 3, 4, 5)
println(xs.toString)
val ys = Seq(4, 5, 6, 7, 8, 9)
println(ys.toString)
val zs = for{
x <- xs
y <- ys
} yield x * y
println(zs.toString)
//http://www.scala-js.org/doc/calling-javascript.html
//var myp5 = new p5(s);
val myp5 = js.Dynamic.newInstance(js.Dynamic.global.p5)(this.sk)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment