• fullscreen
  • Alcys_Dauphin.pde
  • Attracteur.pde
  • Dauphin.pde
  • /* OpenProcessing Tweak of *@*http://www.openprocessing.org/sketch/60518*@* */
    /* !do not delete the line above, required for linking your tweak if you re-upload */
    /**Alcys_Dauphin
     *
     * Jacques Maire
     * 5 mai 2012
     */
    import remixlab.proscene.*;
    
    
    Scene scene;
    Dauphin cetacee;
    ArrayList lista;
    PVector[] etoiles;
    void setup() {
         size(890, 700, P3D);
         scene=new Scene(this); 
         scene.setGridIsDrawn(false);
         scene.setAxisIsDrawn(false);
     
         lista=new ArrayList();
         lista.add(new Attracteur(new PVector(0, 0, 500)));
         lista.add(new Attracteur(new PVector(500, -400, -200)));
         lista.add(new Attracteur(new PVector(-700, -200, -200)));
         lista.add(new Attracteur(new PVector(-500, 400, 300)));
         lista.add(new Attracteur(new PVector(800, 700, 0)));
         cetacee=new Dauphin();
         etoiles=new PVector[50];
         for (int i=0;i<20;i++){
         etoiles[i]=new PVector(random(-10,10), random(-5,-10), random(1,5 ));
        etoiles[i].normalize();
        etoiles[i].mult(3000);
      rectMode(CENTER);
       scene.camera().setOrientation(new Quaternion(new PVector(1, 0, 0), -PI/3.5)); 
       scene.camera().setPosition(new PVector(0, 2000, 2500));
       frameRate(40);
    }
    }
    void draw() {
         background(180, 180, 255);
          lights();
         directionalLight(255, 255, 255, 2, -1, -1);
         directionalLight(255, 255, 255, 0, 1, -1);
         fill(20,20,135);
          rect(0,0,12000,6000);
         // scene.drawAxis(1000);
         stroke(255);
    
            strokeWeight(10);  
       for (int i=0;i<20;i++) {
                   line(etoiles[i].x-5, etoiles[i].y-5, etoiles[i].z,etoiles[i].x+5, etoiles[i].y+5, etoiles[i].z);
                    line(etoiles[i].x, etoiles[i].y, etoiles[i].z-5,etoiles[i].x, etoiles[i].y, etoiles[i].z+5);
         }
    
         fill(255, 0, 0);
         noStroke();
         for (int i=0;i<lista.size();i++) {
              pushMatrix();
              ((Attracteur)lista.get(i)).repere.applyTransformation();
              sphere(40);
              popMatrix();
         }
         cetacee.draw();
       
    }
    
    
    PVector comb(float t1, PVector v1, float t2, PVector v2) {
         PVector res=PVector.add(PVector.mult(v1, t1), PVector.mult(v2, t2));
         return res;
    }
    
    void ligne(PVector u, PVector v) { 
         line(u.x, u.y, u.z, v.x, v.y, v.z);
    }
    
    
    class Attracteur {
         InteractiveFrame repere;
    
         Attracteur() {
              repere=new InteractiveFrame(scene);
              repere.setPosition(new PVector(random(-1000, 1000), random(-1000, 1000),300+ random(-1000, 1000)));
         }
         Attracteur(PVector pos) {
              repere=new InteractiveFrame(scene);
              repere.setPosition(pos);
         }
    }
    
    
    class Dauphin {
    
         ArrayList trajet;
         InteractiveFrame  dauphin;
         PVector vitesse, rampe0, rampe1, oz;
         float masse0, masse1, tempo;
         float[] rayons={30,30,70,78,86,90.5,90,86,76,60,54,40,100}; 
         Dauphin() {
              dauphin=new InteractiveFrame(scene);
              rampe0=new PVector(640, 260, -200);
              rampe1=new PVector(820, -100, -110);
              dauphin.setPosition(rampe1.get());
              vitesse=comb(0.01, rampe1, -0.01, rampe0);
              masse0=10000;
              masse1=10 ;
              tempo=4;
              oz=new PVector(0, 0, 1);
              trajet= new ArrayList();
         }
    
         void draw() {
              PVector v=dauphin.position();
              PVector at1, ww;
              PVector force=new PVector(0, 0, 0);
              for (int i=0;i<lista.size();i++) {
                   InteractiveFrame frame=((Attracteur)lista.get(i)).repere;
    
                   ww=comb(-1, v, 1, frame.position());
                   force=comb(1, force, masse0*masse1/(ww.dot(ww)), ww);
              }
              vitesse=comb(1, vitesse, tempo/masse0, force);
              dauphin.setPosition(comb(1, dauphin.position(), tempo, vitesse));
    
              trajet.add(dauphin.position().get());
              dessineDauphin();
         }
    
    
    
    
         void dessineDauphin() {
              if (trajet.size()>50)trajet.remove(0);
              PVector v0,v1, diff;
              int tr=trajet.size ()-1;
             for(int k=0;k<tr/4 ;k++) { 
                 v0=(PVector)trajet.get(tr-k*4);
                   v1=(PVector)trajet.get(tr-k*4-4);
                   diff=PVector.sub(v0, v1);
                   float dis=diff.mag();
                   dauphin.setPosition(v1);
                   dauphin.setOrientation(new Quaternion(oz, diff));
                   pushMatrix();
                   dauphin.applyTransformation();
                   noStroke(); 
                   fill(150, 150, 180);
                   if(k==1){ translate(0, 20, 0);scale(1.200, 0.8, 1.00);sphere(80);}else { scale(1.00, 0.5, 1.00);}//sphere(rayons[k]);
                   fill(150,150, 185);
                   translate(0, 30, -dis);
                   scene.cone(15, rayons[k+1], rayons[k], 1.2*dis);
                   popMatrix();
                  
              }
              dauphin.setPosition((PVector)trajet.get(trajet.size()-1));
            
         }
    }
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    jacques maire

    Dauphin

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.
    Tweak of Dolphin by jacques maire

    Right click and drag the red spheres

    Built with Proscene

    You need to login/register to comment.