Created
          August 24, 2014 01:04 
        
      - 
      
- 
        Save aaronlifton3/f6a64159c335fdbd6f63 to your computer and use it in GitHub Desktop. 
  
    
      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._ | |
| object ScalaJSExample extends js.JSApp{ | |
| def main(): Unit = { | |
| val (h, w) = (Page.canvas.height, Page.canvas.width) | |
| var x = 0.0 | |
| 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)), | |
| ("pink", cos) | |
| ).zipWithIndex | |
| dom.setInterval(() => { | |
| x = (x + 1) % w | |
| if (x == 0) Page.renderer.clearRect(0, 0, w, h) | |
| else for (((color, func), i) <- graphs) { | |
| val h2 = graphs.length | |
| val y = func(x/w * 75) * h/40 + h/h2 * (i+0.5) | |
| Page.renderer.fillStyle = color | |
| Page.renderer.fillRect(x, y, 3, 3) | |
| } | |
| }, 3) | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment