• fullscreen
  • star.pde
  • star2.pde
  • tougou3.pde
  • word.pde
  • class Star {
    /* OpenProcessing Tweak of *@*http://www.openprocessing.org/sketch/41149*@* */
    /* !do not delete the line above, required for linking your tweak if you re-upload */
    /*
    This program draws a starry sky with stars that twinkle. It also includes 
    randomly occuring shooting stars.
    Author: Charlie McDowell
    */
    
    // the twinlking star locations
    int[] starX = new int[1000];
    int[] starY = new int[1000];
    color[] starColor = new color[1000];
    int starSize = 3; // the size of the twinkling stars
    
    // the tail of the shooting star
    int[] shootX = new int[30];
    int[] shootY = new int[30];
    int METEOR_SIZE = 10; // initial size when it first appears
    float meteorSize = METEOR_SIZE; // size as it fades
    
    // distance a shooting star moves each frame - varies with each new shooting star
    float ssDeltaX, ssDeltaY; 
    // -1 indicates no shooting star, this is used to fade out the star
    int ssTimer = -1;
    // starting point of a new shooting star, picked randomly
    int startX, startY;
    
    
    void setup() {
     // size(1000,800);
      // create the star locations
      for (int i = 0; i < starX.length; i++) {
        starX[i] =(int)random(width);
        starY[i] = (int)random(height);
        starColor[i] = color((int)random(100,255));
      }
    }
    
    void draw() {
      background(0,0,50); // dark blue night sky
      
      // draw the stars
      // the stars seem to show best with black outlines that aren't really perceived by the eye
      stroke(0);
      strokeWeight(1);
      for (int i = 0; i < starX.length; i++) {
        fill(random(50,255)); // makes them twinkle
        if (random(10) < 1) {
          starColor[i] = (int)random(100,255);
        }
        fill(starColor[i]);
        
        ellipse(starX[i], starY[i], starSize, starSize);
      }
    
      // draw the shooting star (if any)
      for (int i = 0; i < shootX.length-1; i++) {
        int shooterSize = max(0,int(meteorSize*i/shootX.length));
        // to get the tail to disappear need to switch to noStroke when it gets to 0
        if (shooterSize > 0) {
          strokeWeight(shooterSize);
          stroke(255);
        }
        else
          noStroke();
        line(shootX[i], shootY[i], shootX[i+1], shootY[i+1]);
        // ellipse(shootX[i], shootY[i], meteorSize*i/shootX.length,meteorSize*i/shootX.length);
      }
      meteorSize*=0.9; // shrink the shooting star as it fades
      
      // move the shooting star along it's path
      for (int i = 0; i < shootX.length-1; i++) {
        shootX[i] = shootX[i+1];
        shootY[i] = shootY[i+1];
      }
      
      // add the new points into the shooting star as long as it hasn't burnt out
      if (ssTimer >= 0 && ssTimer < shootX.length) {
        shootX[shootX.length-1] = int(startX + ssDeltaX*(ssTimer));
        shootY[shootY.length-1] = int(startY + ssDeltaY*(ssTimer));
        ssTimer++;
        if (ssTimer >= shootX.length) {
          ssTimer = -1; // end the shooting star
        }
      }
    
      // create a new shooting star with some random probability
      if (random(5) < 1 && ssTimer == -1) {
        newShootingStar();
      }
    }
    
    /*
      Starts a new shooting star by randomly picking start and end point.
    */
    void newShootingStar() {
      int endX, endY;
      startX = (int)random(width);
      startY = (int)random(height);
      endX = (int)random(width);
      endY = (int)random(height);
      ssDeltaX = (endX - startX)/(float)(shootX.length);
      ssDeltaY = (endY - startY)/(float)(shootY.length);
      ssTimer = 0; // starts the timer which ends when it reaches shootX.length
      meteorSize = METEOR_SIZE;
      // by filling the array with the start point all lines will essentially form a point initialy
      for (int i = 0; i < shootX.length; i++) {
        shootX[i] = startX;
        shootY[i] = startY;
      }
    }
    
    
    
    }
    
    
    class star2 {
    
    int nbEtoile= 3000;
    float speedX,speedY=0;
    float[] posX = new float [nbEtoile];
    float[] posY = new float [nbEtoile];
    float[] posZ = new float [nbEtoile];
    float[] opacite = new float[nbEtoile];
    
    void setup(){
      //size (640,480,P3D);
      //frameRate(60);
      background(0);
      stroke(255);
      for (int i=0;i<posX.length;i++){
        posX[i]=random(width+20);
        posY[i]=random(height+20);
        posZ[i]=random(255);
      }
    }
    void draw(){
     background(0);
      for(int i=0;i<posX.length;i++){
        stroke(posZ[i]+50);
        point(posX[i],posY[i],posZ[i]);
        posX[i]+=speedX;
        posY[i]+=speedY;
        if(posX[i]>width)posX[i]=random(10)*-1;
        else if (posX[i]<-10)posX[i]=random(10)+width;
        if(posY[i]>height)posY[i]=random(10)*-1;
        else if(posY[i]<-10)posY[i]=random(10)+height;
      }
      speedX=-(((mouseX-width/2)/float(width/2))*10);
      speedY=-(((mouseY-height/2)/float(height/2))*10);
    }
    
    }
    
    import traer.physics.*;
    ParticleSystem physics; // case1
    Particle points;
    Word w, w2, w3, w4;
    Star s;
    star2 s2;
    float a;   //X方向の重力
    float b;  //ドラッグ?ダンピング
    
    //////////////////////////////////////////////////////////////
    void setup() {
      size(1000, 600, P3D);
      physics = new ParticleSystem();
      w = new Word("?riaf os tey uoht tra yhw ,teiluJ raed ,hA", physics);//逆から書く
      //Ah, dear Juliet, why art thou yet so fair?
      // s = new Star(); 
      //s.setup();
      
      s2 = new star2(); 
      s2.setup();
      frameRate(30);
     // background(0);
    }
    ////////////////////////////////////////////////////////////////// 
    
    
    ////////////////////////////////////// 
    void draw()
    {
      physics.setGravity(a, 0, 0);    //void setGravity( float x, float, y, float z )
      physics.setDrag(b);           //void setDrag( float drag )
     
      fill(0, 0, 0, 100);
      rect(0, 0, width, height);
      // s.draw();
       
       
        s2.draw();
     
    
      if (mousePressed == true) {
        a=5;
        b=2;
        w.update();
        w.draw();
       
        // physics.tick();
    
        //////星屑描写////////////////////////////////////////
        // fadeToBrack();
        noStroke();
        fill(0, 0, 0, 100);
        rectMode(CORNER);
     //   rect(0, 0, width, height);
        //drawing
        for (int i = 0; i < 10; i++) {    
          float r = random(1, 10);
          int x = int (random(mouseX, mouseX+400));    //Pick a random spot in the composition to test
          int y = int (random(mouseY-70, mouseY+70));  
          fill(random(205, 230), random(5, 100), random(165, 210), random(0, 255));
          ellipse(x, y, r, r);      //ellipse(x, y, width, height)
         //delay(10);
        }
        //////星屑描写終わり///////////////////////////////////
      }  
      else {
        a=0.1;
        b=0.1;
        w.update();
        w.draw();
        // physics.tick();
      }
      physics.tick(0.8);
    }
    //////////////////////////////////////////
    
    
    import traer.physics.*;
    
    class Word {
      ParticleSystem physics;
      Particle[] lettersParticules;
      Spring[] lettersSpring;
      String wordString;
      //char[] charArray;
      float xPos;
      float yPos;
      int nbLetters;
      PFont font;
     
     ////////////////////////////////////////////////////////////////////////////////////////////
      Word(String wstr,ParticleSystem ps) {
        wordString = wstr;
        nbLetters =  wordString.length();
        physics = ps;
     
        // The font must be located in the sketch's
        // "data" directory to load successfully
        font = loadFont("ArialMT-48.vlw"); 
        xPos = random(width);
        yPos = random(height);
        
        lettersParticules = new Particle[nbLetters];
        lettersSpring =     new Spring[nbLetters];
        boolean firstTime=true;
        
        /////無理やりここで
        float[][]  particleStatus = { {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        {5,0.1,1},
        
                                      
                                     };
        
       ///////////////////////////////////////////
        for(int i=0;i<nbLetters;i++){
          xPos = random(width);
          yPos = random(height);
     
          lettersParticules[i] = physics.makeParticle(10,xPos,yPos,0.0);
          //解説:ぱーてぃくるを作る Particle makeParticle( float mass, float x, float y, float z )
           
          if(!firstTime)
          {  //解説:Spring makeSpring( Particle a, Particle b, float strength, float damping, float restLength )
               lettersSpring[i] = physics.makeSpring( lettersParticules[i], lettersParticules[i-1], particleStatus[i][0], particleStatus[i][1], particleStatus[i][2]);
               //lettersSpring[0] = physics.makeSpring(lettersParticules[1],lettersParticules[0], 1.2, 0.1, 10); 
               //lettersSpring[1] = physics.makeSpring(lettersParticules[2],lettersParticules[1], 1.2, 0.1, 10); 
               //lettersSpring[2] = physics.makeSpring(lettersParticules[3],lettersParticules[2], 1.2, 0.1, 20);
             //  lettersSpring[3] = physics.makeSpring(lettersParticules[3],lettersParticules[2], 1.2, 0.1, 20);
             //  lettersSpring[4] = physics.makeSpring(lettersParticules[4],lettersParticules[3], 1.2, 0.1, 10);
             //  lettersSpring[5] = physics.makeSpring(lettersParticules[5],lettersParticules[4], 1.2, 0.1, 10);
             //  lettersSpring[5] = physics.makeSpring(lettersParticules[6],lettersParticules[5], 1.2, 0.1, 10);
             
            //physics.makeAttraction(lettersParticules[i] , lettersParticules[i-1], -200 , -100 );       
              
     
            
          }
          else
          {
            firstTime=false;
          }
       } 
        ////////////////////////////////////////////////////////
        lettersParticules[0].makeFixed();
      }   
    //////////////////////////////////////////////////////////////////////////////////////////////////////  
     
     
      
      void draw()
      {
        fill(255,255,255, 100);
        for(int i=0;i<nbLetters;i++)
        {
          textFont(font, 20+i/10.0);
          text(wordString.charAt(nbLetters-i-1),lettersParticules[i].position().x(),lettersParticules[i].position().y());
        }
      }
    /////////////////////////////////////////////////////////////////////////////////  
    
    /////////////////////////////////////////////////////////////////////////  
      void update()
      {
        for(int i=0;i<nbLetters;i++)
        {
          if(lettersParticules[i].position().y() > height)
          {
            lettersParticules[i].velocity().set(lettersParticules[i].velocity().x(),-abs(lettersParticules[i].velocity().y()),lettersParticules[i].velocity().z());
          }
          
          
          if(lettersParticules[i].position().x() > width)
          {
            lettersParticules[i].velocity().set(-abs(lettersParticules[i].velocity().x()),lettersParticules[i].velocity().y(),lettersParticules[i].velocity().z());
          }
     
          ;
        }
        //lettersParticules[0].position().set( width-frameCount*2,height/2, 0);
    lettersParticules[0].position().set(mouseX,mouseY, 0);
        //lettersParticules[0].setX(mouseX);
        //lettersParticules[0].setY(mouseY);
      }
    ////////////////////////////////////////////////////////////////////////////////  
      
    }
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Midori Yamazaki

    tougou3

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    You need to login/register to comment.