////////////////////////////////////////////////
// HARMONOGRAPH                             ///
// http://en.wikipedia.org/wiki/Harmonograph//
// Original find under Wiki                //
// Optimize and Remake by Ayoros          //
///////////////////////////////////////////

function part22() {
    this.vbl = 0 ;
    this.canvaspart;
    this.text = new text_cursor() ;
    this.initdone = 0 ;

    var mycanvas2;
    var amplitude1 = 300;
    var time1 = 0.02;
    var phase1 = 1/16;
    var damping1 = 0.02;

    var amplitude2 = 100; 
    var time2 = 0.02; 
    var phase2 = 3 / 2; 
    var damping2 = 0.0315;

    var amplitude3 = 300;
    var time3 = 0.02;
    var phase3 = 13 / 15; 
    var damping3 = 0.02;

    var amplitude4 = 100;
    var time4 = 0.02;
    var phase4 = 1; 
    var damping4 = 0.02;
    
    function harmonograph() {
      time1 = (time1 + Math.random() / 80) % 10;  
      time2 = (time2 + Math.random() / 80) % 10;
      time3 = (time3 + Math.random() / 80) % 10;
      time4 = (time4 + Math.random() / 80) % 10;
      phase1 += 0.05 % (Math.PI*2)
      phase2 += 0.01 % (Math.PI*2)
      phase3 += 0.02 % (Math.PI*2)
      phase4 += 0.03 % (Math.PI*2)
      ctx.save();
      ctx.strokeStyle = "#c6413e";
      ctx.translate(300, 200);
      ctx.beginPath();
      for (var t = 0; t < 150; t+=0.01) 
      {
        var x = amplitude1 * Math.sin(time1 * t + Math.PI * phase1) * Math.exp(-damping1 * t) + amplitude2 * Math.sin(time2 * t + Math.PI * phase2) * Math.exp(-damping2 * t);
        var y = amplitude3 * Math.sin(time3 * t + Math.PI * phase3) * Math.exp(-damping3 * t) + amplitude4 * Math.sin(time4 * t + Math.PI * phase4) * Math.exp(-damping4 * t);
        ctx.lineTo(x, y);
      }
      ctx.stroke();
      ctx.restore();
    }

    this.init = function() {
        this.text.init(choix_text[6],10,8,font_key) ;
        mycanvas2=new canvas(600,400);
        ctx = mycanvas2.contex ;
        this.initdone = 1 ;
     }

   

    this.render = function(dest) {
        if (this.initdone == 0) { this.canvaspart = new canvas(600,400) ; this.init() ; }
         
          this.canvaspart.fill("rgba(0,0,0,0.1)");
          mycanvas2.clear();
         	
          mycanvas2.contex.globalCompositeOperation='lighter';
          harmonograph();
          mycanvas2.contex.globalCompositeOperation='source-over';
          
          mycanvas2.draw(this.canvaspart,0,0);
 
 
          this.text.render(this.canvaspart,choix_pos[0].x,choix_pos[0].y) ;

          this.canvaspart.draw(dest,60,88);

        if (this.vbl<100) mycanvasblack.draw(dest,60,88,1-this.vbl/100);
        if (this.vbl>intro_parts[part_running].part_duration-100) mycanvasblack.draw(dest,60,88,1-(intro_parts[part_running].part_duration-this.vbl)/100);
        this.vbl++ ;
    }
return this;
}
///////////////
//END PART21//
/////////////
