import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import ddf.minim.*; 
import moonlander.library.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class Z_THE_DEMO13 extends PApplet {

 


Moonlander moonlander;

//int CANVAS_WIDTH = 640;
//int CANVAS_HEIGHT = 480;
// Don't change this \u2013 needed for resolution independent rendering
//float ASPECT_RATIO = (float)CANVAS_WIDTH/CANVAS_HEIGHT;


//variables for Rocket
double trig ;
double part_jump ;
double part_size ;
double part_rad ;
double cam_X ;
double cam_Y ;
double cam_Z ;
double cam_TX ;
double cam_TY ;
double cam_TZ ;
double cam_PF ;



public void setup() {
  
  // Set up the drawing area size and renderer (usually P2D or P3D,
  // respectively for accelerated 2D/3D graphics).

  
  
     //size(640, 480,P3D);  // size always goes first!
      //surface.setResizable(true);
      //surface.setSize(1920, 1080);
      // Drawing options that don't change, modify as you wish
   frameRate(60);
  noCursor();
  //frameRate(40);
  noStroke();
  fill(255);
  

  
  moonlander = Moonlander.initWithSoundtrack(this, "Dascon_Hakuna-Matata-extended.mp3", 125, 8);
  moonlander.start();
  //setupAudio();
  
  
  //setup draw1
  background(0xff02030D);
  //img = loadImage("demologo.png");
  px = width/2; py = height/2;
  dot = new ArrayList(); 
  
  //setup draw2
  rectMode(CENTER);
  sphereDetail(5);
  poop = new Particle[numdots]; //do zmiany
  for (int i=0;i<numdots;i++)
  {
    poop[i]=new Particle();
  }
  
  //setup draw3
   bbobs = new Bob[numBbobsx*numBbobsy];
    for (int i = 0; i < numBbobsx; i++) {
      for (int j = 0; j < numBbobsy; j++){
        
        bbobs[l] = new Bob((-numBbobsx/2+i)*0,(-numBbobsy/2+j)*0);
        l++; 
   
      }
  }
  
  //setup draw 5
  
   
   pol = new ArrayList(); //do zmiany
  
  f = createFont("digital04B31.TTF",64); // digital04B31, 128 point, anti-aliasing on
  
  greetcl = new ArrayList();; //do zmiany  
  
  greet = new StringList();
  greet.append("Greets:");
greet.append("Kusma");
greet.append("PSenough");
greet.append("iq");
greet.append("04");
greet.append("Black");
greet.append("Raven Kwok");
greet.append("Manoylov_AC");
greet.append("Vormplus");
greet.append("Daniel\nShiffman");
greet.append("axHell");
greet.append("SirJames");
greet.append("Sixtus");
greet.append("Priest");
greet.append("Piles");
greet.append("Reckruth");
greet.append("Sagrael");
greet.append("Thanks\ngoes to:");
greet.append("Thanks\ngoes to: Dascon");
greet.append("Thanks\ngoes to: Dascon\nfor this\nsplendid tune");
greet.append("and special\ngreeets");
greet.append("and special\ngreeets\nto lovely\naudience");
greet.append("and special\ngreeets\nto lovely\naudience\nhere on\npartyplace");
greet.append("and remember");
greet.append("Demo");
greet.append("Demo or");
greet.append("Demo or Die!"); //26 
  
  
  for (int i=0;i<greet.size();i++){
  
      TxtSpring D = new TxtSpring(greet.get(i));
      greetcl.add(D);
 }
 
 textFont(f); 
  
}

public void draw() {
   moonlander.update();
  
  //values from Rocket
  trig = moonlander.getValue("trigger_effect");
  part_jump = moonlander.getValue("particle_jump");
  part_size = moonlander.getValue("particle_size");
  part_rad = moonlander.getValue("particle_radius");
  cam_X = moonlander.getValue("cameraX");
  cam_Y = moonlander.getValue("cameraY");
  cam_Z = moonlander.getValue("cameraZ");
  cam_TX = moonlander.getValue("cameraTX");
  cam_TY = moonlander.getValue("cameraTY");
  cam_TZ = moonlander.getValue("cameraTZ");
  cam_PF = moonlander.getValue("cameraPFAct");
  
  
  // Reset all transformations.
  //resetMatrix();

  // The following lines map coordinates so that we can
  // draw in a resolution independent coordinate system. 
  //
  // After this line coordinate axes are as follows:
  //   x: -ASPECT_RATIO ... ASPECT_RATION
  //   y: -1 ... 1  
  // Negative x is at left, y at bottom, origo at the center of 
  // the screen.
  // This is the coordinate system you're probably used to 
  // already!
  //translate(CANVAS_WIDTH/2.0, CANVAS_HEIGHT/2.0);
  //scale(CANVAS_WIDTH/2.0/ASPECT_RATIO, -CANVAS_HEIGHT/2.0);
  
  // Clear the screen after previous frame.
  // If you comment this line, you always draw on top the last frame,
  // which can lead to something interesting.
  //clear();
 
  
  moonlander.update();
  
  background(0xff02030D);
  
  if (trig == 1.1f ) {     //czysci ArrayList dot podmienia logo;
for (int i = dot.size() - 1; i >= 0; i--) {
  
    dot.remove(i);}
     //enddraw=true;
    px = width/2; py = height/2;
    iter = 0;
    img = loadImage("demologo.png");
   println(frameRate,px,py,dot.size(), enddraw); 
}
  
  
  
  
  if(trig == 1 ){
     draw1();
 
  }
  
  if (trig == 1.5f ) {     //czysci ArrayList dot podmienia logo;
for (int i = dot.size() - 1; i >= 0; i--) {
    dot.remove(i);}
     //enddraw=true;
    px = width/2; py = height/2;
    iter = 0;
    img = loadImage("credits_logo.png");
   println(frameRate,px,py,dot.size(), enddraw); 
}

    
  if(trig == 2||trig ==2.5f ){
  draw2();
  }
  
  if(trig == 2.5f){
  frameRate(30);
    k=0;
  }
 
  if(trig == 3 ||trig ==3.2f){
    draw3();
  }
  
   if(trig == 3.5f){
    
     numBbobsx = 10;
    numBbobsy =10;
    l=0;
    fillTantacle();
    frameRate(40);
  }
  
  
  if(trig == 4){
      
    draw4();
  }
  
  if(trig == 4.5f){
for (int i = pol.size() - 1; i >= 0; i--) {
  
    pol.remove(i);}
    frameRate(45);
    px = width/2; py = height/2;
    iter = 0;
    img = loadImage("rev_logo.png");
  }
  
  if(trig == 5){
     draw5();
}
  
   if(trig == 6){ 
 
    draw1();
  }
  
  if(trig == 7){ 
  exit();
  }
  
}
class DotSpring
{
  //PVector loc;

  float w =0, N=3, r=10;
  float t=0, k=1;
  //int numVert;
  float Fcolor;
  //float rotX, rotY;
  //float rZ,tZ;
  float xpos;
  float ypos;


  DotSpring(float Txpos, float Typos, float TFcolor)
  {

    //loc = new PVector(1000*floor(random(-3,3)),1000*floor(random(-3,3)));
    xpos =Txpos;
    ypos =Typos;
    Fcolor= TFcolor*5; //!!
    w = TFcolor*5;
    //numVert= floor(random( 3, 10 ));
    //rotX= random( 0.9, 2.2 );
    //rotY= random( 0.9, 2.2 );
    //rZ= random( -10, 10 );    
    //tZ= random( 10, 50 );
  }


  /*void regularPolygon( float radius, int numPoints ) //funkcja rysujaca wielokat foremny
   {
   float angle = TWO_PI / numPoints;
   beginShape();
   for (int i = 0; i < numPoints; i++) {
   float x = cos( i * angle ) * radius;
   float y = sin( i * angle ) * radius;
   vertex( x, y );
   }
   endShape(CLOSE);
   } */

  public void render()
  {

    float dw = w/2/N;
    colorMode(HSB, 360, 100, 100);
    pushMatrix();
    translate(xpos, ypos); 
    //noStroke();
    strokeWeight(1);
    stroke(229, 69, 99,k);

    for (int i=0; i<N; i++) { 

      //rotateX(radians(t*(N/rotX-i)));
      //rotateY(radians(t*(N/rotY-i/0.95)));
      //rotateZ(radians(t*(N/1.2-i)));
      if (i%2==0)fill(229, 69, Fcolor*2.5f, k);

      else fill(229, 69, Fcolor*0.5f, k);
      translate(0, 0, 10+100*t); //ruch obiektu w strone Z dodac funkce spring!!
      rotateZ(radians(k*10));
      rotateY(radians(k*5));
      box(t+w/2-i*dw);
      //ellipse(0, 0, t+w/2-i*dw, t+w/2-i*dw);

      //regularPolygon( 10 + i * 10, numVert);
    }

    popMatrix();
    //t = 50*sin(radians(10*k))/k;
    //t =(2+5*cos(k/2)/(0.001*k))/5;
    t=10*(1-sin(k)/(0.2f*k))*exp(1.0f-(0.05f*(k)));
    //t=10+1*(1-sin(3*k)/k)*exp(1.0-(0.1*(k)));
    //t=10*k*exp(1.0-(0.2*k));

    k++;
    //println(frameCount);  //debug
  }
}

ArrayList pol;
PFont f;
StringList greet;
ArrayList greetcl;
float maxWeight1=20;
float spacing1 = maxWeight1+1;




public void draw5() {
  camera(width/2.0f+t*500, height/2.0f+t*500, (100+(float)cam_Y) / tan(PI*30.0f / 180.0f), width/2.0f, height/2.0f, (float)cam_TZ, 0, 1, 0);   
  perspective(PI/(3.0f-(float)cam_PF), 1.7777778f, cameraZ/200.0f, cameraZ*1000.0f);cameraZ=((height/2.0f) / tan(PI*60.0f/360.0f));
  background(0xff02030D);
    for(int s = 4; s > 0; --s){ // for more speed
      
   if (px-10 <= 0 || px+10 >= width  ) { enddraw=false; } //stop przy krawedzi okna (okrag)}  
   else { enddraw=true; }
 
 if (enddraw == true) {
      degree = (iter * goldenRatio) * 360;
      r = sqrt(iter++) * spacing1;
      calcPointPos(width/2, height/2, r, (degree % 360));
      
      int pix = img.get((int)px, (int)py);
      currWeight = map(brightness(pix), 0, 100, minWeight, maxWeight1);
      
      //strokeWeight(currWeight);
      //stroke(0); // stroke(pix);
      //point(px, py);
      if(currWeight != 0){
      
      RPolSpring D = new RPolSpring(px,py,currWeight);
      pol.add(D);}
      
 }     
   }       
      for (int i = 0; i < pol.size(); i++) {
    
          
      RPolSpring A = (RPolSpring) pol.get(i);
      A.render(); 
   
  }

      


      TxtSpring C = (TxtSpring) greetcl.get((int)part_jump);
      if ((int)part_rad==1)    
      C.k=0;                   
      C.render();      
 
 
 z++;
 t = sin(radians(z));
 println((int)frameRate,pol.size(),mouseY); //debug 
}
class RPolSpring
{
//PVector loc;
 
  float w , N=2, r=10;
  float t=0, k=0;
  int numVert;
  float Fcolor;
  float rotX, rotY;
  //float rZ,tZ;
  float xpos;
  float ypos;
  

RPolSpring(float Txpos,float Typos,float TFcolor)
{
 
  //loc = new PVector(1000*floor(random(-3,3)),1000*floor(random(-3,3)));
 
  xpos =Txpos;
  ypos =Typos;
  Fcolor= TFcolor; 
  w = TFcolor*1.5f;
  numVert= round(random( 3, 6 ));
    rotX= random( 0.9f, 2.2f );
    rotY= random( 0.9f, 2.2f );
    //rZ= random( -10, 10 );    
    //tZ= random( 10, 50 );    
}


public void regularPolygon( float radius, int numPoints ) //funkcja rysujaca wielokat foremny
  {
    float angle = TWO_PI / numPoints;
    beginShape();
    for (int i = 0; i < numPoints; i++) {
      float x = cos( i * angle ) * radius;
      float y = sin( i * angle ) * radius;
      vertex( x, y );
    }
    endShape(CLOSE);
  } 

public void render()
{
 
  float dw = w/N;
     
    pushMatrix();
     translate(xpos, ypos); 
        noStroke();
        //strokeWeight(1);
       //stroke(0,Fcolor*3,0,k);
   
    for (int i=0 ; i<N; i++) { 
    
      rotateX(radians(k*(N/rotX-i)));
      rotateY(radians(k*(N/rotY-i/0.95f)));
      rotateZ(radians(k*(N/1.2f-i)));
      if (i%2==0)fill(119,99,Fcolor*4,k*2);
     
      else fill(119,99,Fcolor*3,k*2);
      translate(0, 0, 6+10*t); //ruch obiektu w strone Z dodac funkce spring!!
      //rotateZ(radians(rZ));

      //ellipse(0, 0, w/2-i*dw, w/2-i*dw);

      regularPolygon( w/4-i*dw, numVert);
    }
   
    popMatrix();
    //s = 50*sin(radians(10*k))/k;
    //t =(2+5*cos(k/2)/(0.001*k))/5;
    t=10*(1-sin(k)/(0.2f*k))*exp(1.0f-(0.05f*(k)));
    //t=10+1*(1-sin(3*k)/k)*exp(1.0-(0.1*(k)));
    //t=10*k*exp(1.0-(0.2*k));
    
    k++;
    
}

}
class TxtSpring
{
//PVector loc;
 
  float w =0, N=4, r=10;
  float t=0;
  //int numVert;
  float Fcolor;
  //float rotX, rotY;
  float rZ,tZ;
  String greeto;
  int k; //shrinkOrGrow=1;

TxtSpring(String Tgreeto) //, float Tzpos, float Typos)
{
 
  //loc = new PVector(1000*floor(random(-3,3)),1000*floor(random(-3,3)));
  greeto = Tgreeto;
  Fcolor=50;
    //numVert= floor(random( 3, 10 ));
    //rotX= random( 0.9, 2.2 );
    //rotY= random( 0.9, 2.2 );
    rZ= 2;    
    k=0;
    //tZ= random( 10, 50 );    
}



public void render()
{
 
  //float dw = w/2/N;
    //colorMode(HSB, 360, 100, 100); 
    pushMatrix();
     //translate(xpos, ypos); 
        noStroke();
        //strokeWeight(1);
       //stroke(0,Fcolor*3,0,k);
   
   for (int i=0 ; i<=N; i++) { 
    
      //rotateX(radians(t*(N/rotX-i)));
      //rotateY(radians(t*(N/rotY-i/0.95)));
      //rotateZ(radians(t*(N/1.2-i)));
      //if (i%2==0)fill(75, 106, 255,Fcolor*3 );
     if (i%2==0)fill(0, 0, 99,Fcolor*i*2);
      else fill(229, 69, 33,Fcolor*i*2);
      //translate(0, 0, -t); //ruch obiektu w strone Z dodac funkce spring!!
      //rotateY(radians(-rZ-5*t));
      rotateY(-radians(rZ+t/2));

      //greet
  textAlign(LEFT);

  text(greeto, width/2, height/2);
  //translate(30,30);
  //rotate(radians(10));
    
    }
   
    popMatrix();
    
    //t=(1-sin(k)/(0.2*k))*exp(1.0-(0.05*(k)));
    t=(1-sin(k*2)/(0.2f*k))*exp(1.0f-(0.2f*(k)));
    
    
    k++;
   /* if (k>= 30) {
        shrinkOrGrow = 0;      
    } else if (k <= 1) {
        shrinkOrGrow = 1;
            }
    // check if the circle needs to grow or shrink
    if (shrinkOrGrow == 1) {
        k+= 1;
    } else if (shrinkOrGrow == 0) {
        k-= 1;  
    }*/
    
println(k,t);  //debug
    
}

}
class Bob
{
//PVector loc;
 


  int N=30, r=10;
  //float t=0, k=0;
  //int Fcolor;
  //float rotX, rotY;
  float rZ,tZ;
  float xpos;
  float ypos;
  float w;

Bob(float Txpos,float Typos)
{

  //loc = new PVector(1000*floor(random(-3,3)),1000*floor(random(-3,3)));
  xpos =Txpos;
  ypos =Typos;
   //numVert= floor(random( 3, 10 ));
    //Fcolor= floor(random(60, 99 ));
    //rotX= random( 0.9, 2.2 );
    //rotY= random( 0.9, 2.2 );
    rZ= random( -10, 10 );    
    tZ= 5;    //out
    w=1000; //out
}



public void render()
{
 
  float dw = w/N;
   
     colorMode(HSB,360, 100, 100);
   pushMatrix();
     translate(xpos, ypos); 
      
     rectMode(CENTER);
   //noStroke();
        //noFill();
   
    for (int i=N; i>1; i--) { 
    
      rotate(radians(t*(N-i)));
    if (i%2==0) {
    fill(229,69,60-i*2);
    stroke(229, 69, 90-i*2);
    }
    else {
    fill(255);
      stroke(255);
      }
    translate(0,0,20+i*tZ);
    //rect(0, 0, w-i*dw, w-i*dw, r*(N-i), r*(N-i), r*(N-i), r*(N-i) );
    box(w-i*dw, w-i*dw, 25);
  }
   for (int i=1; i<N; i++) { 
    rotate(radians(t*(N-i)));
    if (i%2==0) {
    fill(229,69,60-i*2);
    stroke(229, 69, 90-i*2);
    }
    else {
    fill(255);
      stroke(255);
      }
    translate(0,0,20+i*tZ);  //*tZ 
    //rect(0, 0, w-i*dw, w-i*dw, r*(N-i), r*(N-i), r*(N-i), r*(N-i));
    box(w-i*dw, w-i*dw, 25);
    }
    popMatrix();
    t = sin(radians(k));
    //k++;
  }

//println(frameRate, xpos, ypos);
}

ArrayList dot;
int z=0;
float t=0 ;


float px, py, r, degree;
float minWeight=0;
float maxWeight=10;
float currWeight;
float spacing = maxWeight+5;
float goldenRatio = ((sqrt(5) + 1 ) / 2);
int iter = 0;
PImage img;
boolean enddraw=true;



public void draw1() {
 camera(width/2.0f+t*500, height/2.0f+t*200, 500+(float)cam_Z  / tan(PI*30.0f / 180.0f), width/2.0f, height/2.0f,-10+(float)cam_TZ, 0, 1, 0);    
perspective(PI/(3.0f-(float)cam_PF), 1.7777778f, cameraZ/200.0f, cameraZ*200.0f);cameraZ=((height/2.0f) / tan(PI*60.0f/360.0f));
  
  //background(#02030D);
    for(int i = 70; i > 0; --i){ // for more speed
      
   if (px-50 <= 0 || px+50 >= width  ) { enddraw=false; } //stop przy krawedzi okna (okrag), || py-50 <= 0 || py+50 >= height
   else { enddraw=true; }
   
   if (enddraw == true) {
      degree = (iter * goldenRatio) * 360;
      r = sqrt(iter++) * spacing;
      calcPointPos(width/2, height/2, r, (degree % 360));
      colorMode(HSB,360, 100, 100);
      int pix = img.get((int)px, (int)py);
      currWeight = map(brightness(pix), 0, 255, minWeight, maxWeight);
      
      //strokeWeight(currWeight);
      //stroke(0); // stroke(pix);
      //point(px, py);
      if(currWeight != 0){
      
      DotSpring D = new DotSpring(px,py,currWeight);
      dot.add(D);}
      
}
}   
     
for (int i = 0; i < dot.size(); i++) {
    
          
      DotSpring A = (DotSpring) dot.get(i);
      A.render();
   
  }      

/*if (song.position()>12300 && song.position()<=12400) {     //czysci ArrayList dot;
for (int i = dot.size() - 1; i >= 0; i--) {
  
    dot.remove(i);}
     enddraw=true;
    px = width/2; py = height/2;
  }*/


 
 z++;
  //println(z, dot.size()) ; //debug
  println(frameRate,px,py,dot.size(), enddraw);
 
t = sin(radians(z));

}

public void calcPointPos(float x, float y, float r, float graden) {
  px = x + cos(radians(graden))*(r/2);
  py = y + sin(radians(graden))*(r/2);
    
  
}
boolean flag=false;
Particle[] poop;

int distance=400;
int mdistance=350;
int numdots = 620;

public void draw2()
{
        
  camera(width/2.0f+(float)cam_X, height/2.0f+(float)cam_Y, (float)cam_Z / tan(PI*30.0f / 180.0f), width/2.0f+(float)cam_TX, height/2.0f+(float)cam_TY, (float)cam_TZ, 0, 1, 0);    
  perspective(PI/(3.0f-(float)cam_PF), 1.7777778f, cameraZ/10.0f, cameraZ*100.0f);cameraZ=((height/2.0f) / tan(PI*60.0f/360.0f));
  println(frameRate,poop.length);  
  pushMatrix();
      
  //white cubes picking for Rocket thread
  for (int i=0;i<poop.length;i++)
  {
  if(poop[i].c==0xffffffff){
  poop[i].r=(float)part_size*random(0.7f,2.2f);
  poop[i].dtet=(float)part_jump*1.5f;
  poop[i].dfi=(float)part_jump*1.5f;
  }
    
  
  if(poop[i].rs>2399 ){
  poop[i].rs=4*(float)part_rad;
     
}  
  
  if(poop[i].rs>=1200 && poop[i].rs<2400){
   poop[i].rs=2400-(float)part_rad;
    }  
    if(poop[i].rs<=1199){
  poop[i].rs=(float)part_rad;
     }
     
    
    
    
    Particle Pn1 = (Particle) poop[i];    // bierze 1 obiekt z tabl poop
    Pn1.display();
    Pn1.update();
    for (int j = i + 1; j < poop.length; j++) {  // bierze 2 obiekt z tabl poop
      Particle Pn2 = (Particle) poop[j];
      Pn2.update();
      if (dist(Pn1.x, Pn1.y,Pn1.z, Pn2.x, Pn2.y,Pn2.z)< distance && dist(Pn1.x, Pn1.y,Pn1.z, Pn2.x, Pn2.y,Pn2.z)> mdistance) //jesli odleglosc < distance = 50
      {
        for (int k = j + 1; k < poop.length; k++) {  // bierze 3 obiekt z tabl poop
          Particle Pn3 = (Particle) poop[k];
          if (dist(Pn3.x, Pn3.y,Pn3.z, Pn2.x, Pn2.y,Pn2.z)< distance && dist(Pn1.x, Pn1.y,Pn1.z, Pn2.x, Pn2.y,Pn2.z)> mdistance) {
            if (flag) {
              stroke(Pn3.c);
              fill(Pn3.c, 45); //access to class, wypelnia kolorem  z danego obiektu
            }
            else {
              noFill();
              strokeWeight(1);
              stroke(Pn3.c, 10000/dist(Pn3.x, Pn3.y,Pn3.z, Pn2.x, Pn2.y,Pn2.z));
            }
            beginShape(TRIANGLES);
            vertex(Pn1.x, Pn1.y,Pn1.z);
            vertex(Pn2.x, Pn2.y,Pn2.z);
            vertex(Pn3.x, Pn3.y,Pn3.z);
            endShape();
          }
 
          Pn3.update();
        }
      }
    }
  }
  popMatrix();
}
 


class Particle {    //CLASSS!!!
  float x, y,z, r;
  int c;
  int i=1, j=1;
  
  float rs;      //wspolrz sferyczne
  float tet, fi,dtet,dfi;   //wspolrz sferyczne
  
  Particle( ) //constructor
  {
   
    tet = random (0,180);
    fi = random (-180,180);
    dtet = random (1,3);
    dfi = random (1,3);
    r = random(1,5);
    rs=800*round(random(1,3));
    
    int j = (int)random(0, 4);  //kolor kropki
    if (j==0)
    {
      c = color(0xff4B6AFF);
    }
    if (j==1)
    {
      c = color(0xff3247AA);
    }
    if (j==2)
    {
      c = color(0xff192355);
    }
    if (j==3)
    {
      c = color(0xffffffff);
    }
  }
 
 
  public void display()
  {
    pushStyle();
    stroke(c);
    fill(c,50);
    pushMatrix();
    z=rs*sin(radians(fi))*cos(radians(tet));
    x=rs*sin(radians(fi))*sin(radians(tet));
    y=rs*cos(radians(fi));
    translate(x, y, z); 
    rotateZ(radians(z));
    rotateX(radians(x));
    rotateY(radians(y));
    //rotate(radians(z));
    //ellipse(x, y, r, r);
    //rect(x, y, r, r);
    box(10+10*r);
    //sphere(10+5*r);
    //strokeWeight(1+r);
    //point(0, 0, 0);
    popMatrix();
    popStyle();
  }
 
  public void update()
  {
    tet+=i*dtet*0.0001f;
    fi+=i*dfi*0.0001f;
    
  }
}
int numBbobsx = 3;
int numBbobsy =3;
float cameraZ;
float perspFact=1.5f;
int l=0;
Bob[] bbobs;
  float  k=0; //t=0,

public void draw3()
{
 perspective(PI/perspFact, 21/9, cameraZ/1000.0f, cameraZ*100.0f); cameraZ = ((height/2.0f) / tan(PI*60.0f/360.0f));

t = sin(radians(k));
k+=1.2f;
camera(width/2.0f+t*2000, height/2.0f+t*2000, (1000*8)-k*9.5f / tan(PI*30.0f / 180.0f), width/2.0f-t*1000, height/2.0f, 900, 0, 1, 0);
 
 if(trig == 3.2f){ // zoomout at effect end
  perspFact-=0.02f;
   
 }

  background(0xff02030D);
  //resetMatrix();
translate(width/2, height/2);
  pushMatrix();
//fill(#E54141);
//rect(0, 0, 50, 50);

for (int i = 0; i < bbobs.length; i++) {
    
      bbobs[i].render();}
  
popMatrix();
 
//  to ROCKET!

for (int i=0; i<4; i++)
  bbobs[i].w=-1*(float)part_size;
  bbobs[4].w =(float)part_size; 
for (int i=5; i<9; i++)
  bbobs[i].w=-1*(float)part_size;


bbobs[0].xpos =-4000+(float)part_jump; 
bbobs[0].ypos =-4000+(float)part_jump;

bbobs[1].xpos =-4000-(float)part_jump;
bbobs[1].ypos =0; 

bbobs[2].xpos =-4000+(float)part_jump;
bbobs[2].ypos =4000-(float)part_jump; 

bbobs[3].xpos =0;
bbobs[3].ypos =-4000-(float)part_jump;

bbobs[4].xpos =0;
bbobs[4].ypos =0;

bbobs[5].xpos =0;
bbobs[5].ypos =4000+(float)part_jump;

bbobs[6].xpos =4000-(float)part_jump;
bbobs[6].ypos =-4000+(float)part_jump;

bbobs[7].xpos =4000+(float)part_jump;
bbobs[7].ypos =0;

bbobs[8].xpos =4000-(float)part_jump;
bbobs[8].ypos =4000-(float)part_jump;

println(frameRate,millis());
 


//camera(-mouseX*6, -mouseY*6, (height/2.0) , 0, 0, 0, 0, 1, 0); 
//camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, height/2.0, 0, 0, 1, 0);//default 

}

Tantacle[] tantacles;
 // float t=0, k=0;


public void fillTantacle()
{
  //size( 900, 900,P3D );
 // fullScreen(P3D);
 
 tantacles = new Tantacle[numBbobsx*numBbobsy];
    for (int i = 0; i < numBbobsx; i++) {
      for (int j = 0; j < numBbobsy; j++){
        
        tantacles[l] = new Tantacle((-numBbobsx/2+i)*1500,(-numBbobsy/2+j)*1500);
        l++; 
 
      }
  }
}

public void draw4()
{
  //camera(width/2.0+(float)cam_X, height/2.0+(float)cam_Y, (float)cam_Z / tan(PI*30.0 / 180.0), width/2.0+(float)cam_TX, height/2.0+(float)cam_TY, (float)cam_TZ, 0, 1, 0);    
  camera(t*8000, height/2.0f+(float)cam_Y, (float)cam_Z / tan(PI*30.0f / 180.0f), width/2.0f+(float)cam_TX, height/2.0f+(float)cam_TY, (float)cam_TZ, 0, 1, 0);    
  perspective(PI/(3.0f-(float)cam_PF), 1.7777778f, cameraZ/10.0f, cameraZ*100.0f);cameraZ=((height/2.0f) / tan(PI*60.0f/360.0f));

//camera(-mouseX*6, -mouseY*6, (height*2.0) , 0, 0, 0, 0, 1, 0); 
//perspective(PI/1.2, 21/9, cameraZ/10.0, cameraZ*100.0); cameraZ = ((height/2.0) / tan(PI*60.0/360.0));

t = sin(radians(k));
k++;
//camera(width/2.0+t*2000, -height*2+t*2000, (1000*7)-k / tan(PI*30.0 / 180.0), width/2.0-t*1000,00, 00, 0, 1, 0);

  
  
  
  background(0xff02030D);
  rotateX(radians(90));

//noStroke();

pushMatrix();
rectMode(CENTER);
translate(width/2, height/2);
translate(0,0,-1500);
//rotateX(radians(180));
for(int i=0; i<5;i++)
  {
translate(0,0,300);
  stroke(0xff3247AA);
  fill(0xff3247AA,10);
  //rect((-numBbobsx/2)*1500-750,(-numBbobsy/2)*1500-750,(numBbobsx)*1500,(numBbobsy)*1500);
  rect(0-1500,0-1500,(numBbobsx)*1500,(numBbobsy)*1500);
  }
  popMatrix();
for (int i = 0; i < tantacles.length; i++) {

      // variables to rocket
      tantacles[i].s=(int)part_size;
      
      if((float)part_jump==1) 
      tantacles[i].tZ+=random( 10, 20 );   
      else if((float)part_jump==-1) 
      tantacles[i].tZ-=random( 10, 20 );   
      if((float)part_rad==1) {
      tantacles[i].rotX=random( 0.9f, 2.2f );
      //tantacles[i].rotY=random( 0.9, 2.2 );
      }
      tantacles[i].render();
    }

println(frameRate);

 


 



  
}
class Tantacle
{

 


  int w =800, N=30, r=10, s=700;
  float t=0, k=0;
  //int numVert;
  int Fcolor;
  float rotX, rotY;
  float rZ,tZ;
  float xpos;
  float ypos;


Tantacle(float Txpos,float Typos)
{
 
 
  xpos =Txpos;
  ypos =Typos;
   //numVert= floor(random( 3, 10 ));
    Fcolor= floor(random(60, 99 ));
    rotX= random( 0.9f, 2.2f );
    rotY= random( 0.9f, 2.2f );
    rZ= random( -10, 10 );    
    tZ= random( 100, 200 );    
}

public void render()
{
 
  //float dw = w/N;
     colorMode(HSB,360, 100, 100);
    pushMatrix();
     translate(xpos, ypos); 
        noFill();
   
    for (int i=N; i>1; i--) { 
    
      rotateX(radians(t/2*(N/rotX-i)));
      rotateY(radians(t/2*(N/rotY-i/0.95f)));
      rotateZ(radians(t/2*(N/1.2f-i)));
      if (i%2==0){
         fill(229,69,Fcolor,60);
        stroke(229,69,Fcolor);
      }
      
      else if (i%3==0){
        fill(0,0,99,50);
        stroke(0,0,99);
      }
      else{ 
      noFill();
      stroke(229,69,Fcolor/2);
      }
      translate(0, 0, tZ);
      rotateZ(radians(rZ));

      //ellipse(0, 0, w-i*1.3*dw, w-i*2*dw);
      //box(200*cos(i/5)/i);
      box(s*sin(2*i)/i);
      //regularPolygon( 2000*cos(i)/i , numVert);
      //regularPolygon( 20*i*exp(1.0-0.1*i) , numVert);
    }
    popMatrix();
    t = sin(radians(k));
    k++;
  }

}
  public void settings() {  fullScreen(P3D);  smooth(); }
  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "Z_THE_DEMO13" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}
