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

Combining sketches (one video player, one rain maker)

$
0
0
I have two sketches that I am trying to combine. I was trying to treat each sketch as a separate function but I am running into problems due to one of the sketches being one that simply plays a video. (Sound no picture etc.) The aim is for the video to play once and then move onto the rain straight after, although it seems latency is unavoidable. 

My attempts have all been a mess so I will upload the sketches separately in hopes someone may have a suggestion! 

Video:


  1. import processing.video.*;

  2. Movie myMovie;

  3. void setup() {  
  4.     
  5.  size(1280, 720);
  6.  background(0);
  7. // Load and play the video in a loop
  8.  myMovie = new Movie(this, "CBS.mov");
  9.  myMovie.loop();
  10.  
  11. }

  12. void movieEvent(Movie myMovie) {
  13.  myMovie.read();
  14. }

  15. void draw() {
  16.     
  17.  image(myMovie,0,0);
  18.  delay (25);
  19.   
  20.    }

Rain: 


  1. int rainNum = 100;
  2. ArrayList rain = new ArrayList();
  3. ArrayList splash = new ArrayList();
  4. float current;
  5. float reseed = random(0, .2);
  6. void setup()
  7. {
  8.   size(600, 600, P3D);
  9.   colorMode(HSB, 100);
  10.   background(0);
  11.   rain.add(new Rain());
  12.   current = millis();
  13. }
  14. void draw()
  15. {
  16.   background (0);
  17.   blur(50);
  18.   strokeWeight(9);
  19.   stroke(255, 2, 2);
  20.   line (width/2.0, 0, 100, 
  21.   width/2.0, 0, 200 );
  22.   if ((millis()-current)/1>reseed && 
  23.     rain.size()<150)
  24.   {
  25.     rain.add(new Rain());
  26.     float reseed = random(0, .2);
  27.     current = millis();
  28.   }
  29.   for (int i=0 ; i<rain.size() ; i++)
  30.   {
  31.     Rain rainT = (Rain) rain.get(i);
  32.     rainT.calculate();
  33.     rainT.draw();
  34.     if (rainT.position.y>height)
  35.     {
  36.       for (int k = 0 ; k<random(5,10) ; k++)
  37.       {
  38.         splash.add(new Splash(rainT.position.x, height, rainT.position.z));
  39.       }
  40.       rain.remove(i);
  41.       float rand = random(0, 100);
  42.       if (rand>10&&rain.size()<150)
  43.         rain.add(new Rain());
  44.     }
  45.   }
  46.   for (int i=0 ; i<splash.size() ; i++)
  47.   {
  48.     Splash spl = (Splash) splash.get(i);
  49.     spl.calculate();
  50.     spl.draw();
  51.     if (spl.position.y>height)
  52.       splash.remove(i);
  53.   }
  54. }
  55. void blur(float trans)
  56. {
  57.   noStroke();
  58.   fill(0, trans);
  59.   rect(0, 0, width, height);
  60. }
  61. // ==========================================
  62. public class Rain
  63. {
  64.   PVector position, pposition, speed;
  65.   float col;
  66.   public Rain()
  67.   {
  68.     position = new PVector(random(0, width), -500, random(0, 800));
  69.     pposition = position;
  70.     speed = new PVector(0, 0);
  71.     col = random(30, 100);
  72.   }
  73.   void draw()
  74.   {
  75.     stroke(100, col);
  76.     strokeWeight(2);
  77.     line(position.x, position.y, position.z, pposition.x, pposition.y, position.z);
  78.     //ellipse(position.x,position.y,5,5);
  79.   }
  80.   void calculate()
  81.   {
  82.     pposition = new PVector(position.x, position.y);
  83.     gravity();
  84.   }
  85.   void gravity()
  86.   {
  87.     speed.y += .2;
  88.     speed.x += .01;
  89.     position.add(speed);
  90.   }
  91. }
  92. public class Splash
  93. {
  94.   PVector position, speed;
  95.   public Splash(float x, float y, float z)
  96.   {
  97.     float angle = random(PI, TWO_PI);
  98.     float distance = random(1, 5);
  99.     float xx = cos(angle)*distance;
  100.     float yy = sin(angle)*distance;
  101.     position = new PVector(x, y, z);
  102.     speed = new PVector(xx, yy);
  103.   }
  104.   public void draw()
  105.   {
  106.     strokeWeight(1);
  107.     stroke(100, 50);
  108.     fill(100, 100);
  109.     // ellipse(position.x, position.y, 2, 2 );
  110.     point(position.x, position.y, position.z );
  111.   }
  112.   void calculate()
  113.   {
  114.     gravity();
  115.     speed.x*=0.98;
  116.     speed.y*=0.98;
  117.     position.add(speed);
  118.   }
  119.   void gravity()
  120.   {
  121.     speed.y+=.2;
  122.   }
  123. }   
  
Thanks,
Katie

Viewing all articles
Browse latest Browse all 1768

Trending Articles