Advertisement
grgml

Sine waves

May 28th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onGLC(glc) {
  2.     glc.loop();
  3.     glc.size(500, 500);
  4.     glc.setDuration(4);
  5.     glc.setMode('single');
  6.     glc.setEasing(false);
  7.     var list = glc.renderList,
  8.         width = glc.w,
  9.         height = glc.h,
  10.         color = glc.color;
  11.    
  12.     glc.styles.backgroundColor = "rgb(21, 21, 21)";
  13.  
  14.     // your code goes here:
  15.  
  16.     var mag = width/12;
  17.    
  18.     for(var n=0; n<4; n++){
  19.         wave(width/4 + 2*n*mag, mag, n*Math.PI/2);
  20.     }    
  21.  
  22.     function wave (ypos, mag, phase){        
  23.  
  24.         for(var i=50; i<=width-50; i+=10){
  25.             if(parseInt((i-50)/10)%2 == 1){
  26.                 glc.styles.fillStyle = "#ff0000";
  27.             } else {
  28.                 glc.styles.fillStyle = "#0000ff";
  29.             }
  30.            
  31.             list.addCircle({
  32.                 index: i,
  33.                 x: function(t){
  34.                     var offset = t*3*Math.PI;
  35.                     return ypos + mag*Math.sin(Math.PI*this.index/300 + offset + phase);
  36.                 },
  37.                 y: i,
  38.                 radius: 3,
  39.                 fillStyle: (((i-50)/10)%2 == 0)?"#cc0000":"#fff"
  40.             });
  41.             list.addCircle({
  42.                 index: i,
  43.                 x: function(t){
  44.                     var offset = t*3*Math.PI;
  45.                     return ypos + mag*Math.sin(-Math.PI*this.index/300 - offset - phase);
  46.                 },
  47.                 y: i,
  48.                 radius: 3,
  49.                 fillStyle: (((i-50)/10)%2 == 0)?"#cc0000":"#fff"
  50.             });  
  51.         }        
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement