//////////////////////
//Dots- 50000      //
//Code By Ayoros  //
///////////////////

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

var angle1=0.0;
var angle2=0.0;
var angle3=0.0;
var angle_inc1=0.0052;
var angle_inc2=0.0201;
var angle_inc3=0.0121;
var angle_inc4=0.0075;
var angle_inc5=0.0091;
var angle_inc6=0.0091;
var angle_inc7=0.0075;
var evol=0;
var num_dots=50000;
var alpha_fade=0;
var fade_end=0;
var mycanvas2;
var frameBuffer;
var canvasImgData;

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

      canvasImgDST = mycanvas2.contex.createImageData(600, 400);
      frameBuffer = canvasImgDST.data;
        this.initdone = 1 ;
     }
function dots_anim(){
	angle1+=angle_inc1;
	angle2+=angle_inc2;
	angle3+=angle_inc3;
  canvasImgDST = mycanvas2.contex.createImageData(600, 400);
  frameBuffer = canvasImgDST.data;

  var wx=400/2;
	var wx2=400/4;
	var x=0.0;
	var y=0.0;

		
	var dest_x1=0.0;
	var dest_x2=0.0;
	var dest_y1=0.0;
	var dest_y2=0.0;
	var z1=0.0;
	var z2=0.0;
	var zcolor=0;
	for (var a=0; a<num_dots; a++)
	{
		z1=Math.cos(angle2+dest_x2)*Math.cos(angle3+dest_y1);
		z2=Math.sin(angle3+dest_y1)*Math.cos(angle1+dest_y2);
		x=wx+wx2*(Math.sin(angle1+dest_x2)+z1);
		y=wx+wx2*(z2+Math.sin(angle2+dest_x2));
			
	  if ((evol>0)&&(evol<250)){
      dest_x1+=angle_inc4;
      dest_x2-=angle_inc5+angle_inc4;
      dest_y1+=angle_inc6+angle_inc5;
      dest_y2+=angle_inc7;
    }
    if ((evol>=250)&&(evol<500)){
      dest_x1+=angle_inc4;
			dest_x2-=angle_inc5+angle_inc4;
			dest_y1+=angle_inc6+angle_inc5;
			dest_y2+=angle_inc7+angle_inc6;
    }
      if ((evol>=500)&&(evol<750)){
			dest_x1+=angle_inc4;
			dest_x2-=angle_inc5;
			dest_y1+=angle_inc6;
			dest_y2+=angle_inc7+angle_inc5;
      }
        if ((evol>=750)&&(evol<1000)){
			dest_x1+=angle_inc4;
			dest_x2-=angle_inc5;
			dest_y1+=angle_inc6+angle_inc5;
			dest_y2+=angle_inc7;
      }

    zcolor=0|((2+z1+z2)*60);
		drawsimpleObj(0|x,0|y,frameBuffer, zcolor);
  }
  
  if ( fade_end<=30 ) { alpha_fade += 0.02; }
  if ( (fade_end>=230 ) && (fade_end<250) ) { alpha_fade -= 0.02 ; }
  if (fade_end==250){alpha_fade = 0;fade_end = 0 ;}
  fade_end++ ;
  evol++;
  if (evol>=1000){evol=0;}
		
}


	function drawsimpleObj(x,y,D,c)
	{
		if (y>=0 && x>=0 && y<400 && x<600)
		{
			var p=(y*600+x)<<2;
			{
				D[p++]=c;
				D[p++]=c;
				D[p++]=c+155;
				D[p]=255;  // alpha
			}
		}
	}

   
    this.render = function(dest) {
        if (this.initdone == 0) { this.canvaspart = new canvas(600,400) ; this.init() ; }
          this.canvaspart.fill("rgba(0,0,0,0.2)");
          mycanvas2.clear();
          dots_anim();
          mycanvas2.contex.putImageData(canvasImgDST, 0, 0);
 
          mycanvas2.draw(this.canvaspart,100,0,alpha_fade);

          this.text.render(this.canvaspart,choix_pos[1].x,choix_pos[1].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 PART20//
////////////
