Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Combining sketches (one video player, one rain maker)

$
0
0
Hey, I have update the video sketch since this attempt and now I am even more confused! 

  1. ////// VIDEO ///////////////////////////////////////////

  2. int maxMovies = 2; // Total number of movies
  3. int myMoviesIndex = 0; // Initial movie to be displayed



  4. ////// RAIN ///////////////////////////////////////////

  5. int rainNum = 100;
  6. ArrayList rain = new ArrayList();
  7. ArrayList splash = new ArrayList();
  8. float current;
  9. float reseed = random(0, .2);

  10. videoSketch sketch;
  11. //rainSketch sketch2;

  12. void setup() {
  13.   size(1280, 720);
  14.   background(0);
  15.   //instatiate our classes
  16.   sketch = new videoSketch(width, height);
  17.   sketch2 = new rainSketch(width, height);
  18. }

  19. void draw() {
  20.   background(0);
  21.   //call the happen function (also called a method) within each sketch
  22.   sketch.happen();
  23.   sketch2.happen();
  24. }

  25. public class videoSketch {
  26.   
  27.   private int w, h;
  28.   
  29.   Movie[] myMovies;

  30.   void loadMovie() { 

  31.     myMovies = new Movie[maxMovies]; //array of movies

  32.     for (int i = 0; i < myMovies.length; i ++ ) {
  33.       println(i);
  34.       myMovies[i] = new Movie(this, i+1 + ".mov");
  35.       myMovies[i].loop();
  36.       myMovies[i].pause();
  37.     }
  38.   }

  39.     void playMovie() { 

  40.       myMovies[myMoviesIndex].play();
  41.       image(myMovies[myMoviesIndex], 0, 0); // Displays image
  42.       println(myMovies[myMoviesIndex].time());
  43.       float mt = myMovies[myMoviesIndex].time();
  44.       float md = myMovies[myMoviesIndex].duration();
  45.       if (mt == md) {
  46.         myMovies[myMoviesIndex].pause();
  47.         myMoviesIndex ++;
  48.         if (myMoviesIndex == maxMovies) {
  49.           myMoviesIndex = 0;
  50.         }
  51.         myMovies[myMoviesIndex].jump(0);
  52.         myMovies[myMoviesIndex].play();
  53.       }
  54.     }
  55.   }

  56.   void movieEvent(Movie myMovies) {
  57.     myMovies.read();
  58.   }

  59. public class rainSketch {
  60.   
  61.   size(600, 600, P3D);
  62.   colorMode(HSB, 100);
  63.   background(0);
  64.   rain.add(new Rain());
  65.   current = millis();
  66.   
  67.   
  68.   void rain() {
  69.     
  70.     background (0);
  71.   blur(50);
  72.   strokeWeight(9);
  73.   stroke(255, 2, 2);
  74.   line (width/2.0, 0, 100, 
  75.   width/2.0, 0, 200 );
  76.   if ((millis()-current)/1>reseed && 
  77.     rain.size()<150)
  78.   {
  79.     rain.add(new Rain());
  80.     float reseed = random(0, .2);
  81.     current = millis();
  82.   }
  83.   for (int i=0 ; i<rain.size() ; i++)
  84.   {
  85.     Rain rainT = (Rain) rain.get(i);
  86.     rainT.calculate();
  87.     rainT.draw();
  88.     if (rainT.position.y>height)
  89.     {
  90.       for (int k = 0 ; k<random(5,10) ; k++)
  91.       {
  92.         splash.add(new Splash(rainT.position.x, height, rainT.position.z));
  93.       }
  94.       rain.remove(i);
  95.       float rand = random(0, 100);
  96.       if (rand>10&&rain.size()<150)
  97.         rain.add(new Rain());
  98.     }
  99.   }
  100.   for (int i=0 ; i<splash.size() ; i++)
  101.   {
  102.     Splash spl = (Splash) splash.get(i);
  103.     spl.calculate();
  104.     spl.draw();
  105.     if (spl.position.y>height)
  106.       splash.remove(i);
  107.   }
  108.   
  109. }


  110. public class Rain
  111. {
  112.   PVector position, pposition, speed;
  113.   float col;
  114.   public Rain()
  115.   {
  116.     position = new PVector(random(0, width), -500, random(0, 800));
  117.     pposition = position;
  118.     speed = new PVector(0, 0);
  119.     col = random(30, 100);
  120.   }
  121.   void draw()
  122.   {
  123.     stroke(100, col);
  124.     strokeWeight(2);
  125.     line(position.x, position.y, position.z, pposition.x, pposition.y, position.z);
  126.     //ellipse(position.x,position.y,5,5);
  127.   }
  128.   void calculate()
  129.   {
  130.     pposition = new PVector(position.x, position.y);
  131.     gravity();
  132.   }
  133.   void gravity()
  134.   {
  135.     speed.y += .2;
  136.     speed.x += .01;
  137.     position.add(speed);
  138.   }
  139. }
  140. public class Splash
  141. {
  142.   PVector position, speed;
  143.   public Splash(float x, float y, float z)
  144.   {
  145.     float angle = random(PI, TWO_PI);
  146.     float distance = random(1, 5);
  147.     float xx = cos(angle)*distance;
  148.     float yy = sin(angle)*distance;
  149.     position = new PVector(x, y, z);
  150.     speed = new PVector(xx, yy);
  151.   }
  152.   public void draw()
  153.   {
  154.     strokeWeight(1);
  155.     stroke(100, 50);
  156.     fill(100, 100);
  157.     // ellipse(position.x, position.y, 2, 2 );
  158.     point(position.x, position.y, position.z );
  159.   }
  160.   void calculate()
  161.   {
  162.     gravity();
  163.     speed.x*=0.98;
  164.     speed.y*=0.98;
  165.     position.add(speed);
  166.   }
  167.   void gravity()
  168.   {
  169.     speed.y+=.2;
  170.   }
  171. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles