Combining sketches (one video player, one rain maker)
in
Core Library Questions
•
6 months ago
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:
- import processing.video.*;
- Movie myMovie;
- void setup() {
- size(1280, 720);
- background(0);
- // Load and play the video in a loop
- myMovie = new Movie(this, "CBS.mov");
- myMovie.loop();
- }
- void movieEvent(Movie myMovie) {
- myMovie.read();
- }
- void draw() {
- image(myMovie,0,0);
- delay (25);
- }
Rain:
- int rainNum = 100;
- ArrayList rain = new ArrayList();
- ArrayList splash = new ArrayList();
- float current;
- float reseed = random(0, .2);
- void setup()
- {
- size(600, 600, P3D);
- colorMode(HSB, 100);
- background(0);
- rain.add(new Rain());
- current = millis();
- }
- void draw()
- {
- background (0);
- blur(50);
- strokeWeight(9);
- stroke(255, 2, 2);
- line (width/2.0, 0, 100,
- width/2.0, 0, 200 );
- if ((millis()-current)/1>reseed &&
- rain.size()<150)
- {
- rain.add(new Rain());
- float reseed = random(0, .2);
- current = millis();
- }
- for (int i=0 ; i<rain.size() ; i++)
- {
- Rain rainT = (Rain) rain.get(i);
- rainT.calculate();
- rainT.draw();
- if (rainT.position.y>height)
- {
- for (int k = 0 ; k<random(5,10) ; k++)
- {
- splash.add(new Splash(rainT.position.x, height, rainT.position.z));
- }
- rain.remove(i);
- float rand = random(0, 100);
- if (rand>10&&rain.size()<150)
- rain.add(new Rain());
- }
- }
- for (int i=0 ; i<splash.size() ; i++)
- {
- Splash spl = (Splash) splash.get(i);
- spl.calculate();
- spl.draw();
- if (spl.position.y>height)
- splash.remove(i);
- }
- }
- void blur(float trans)
- {
- noStroke();
- fill(0, trans);
- rect(0, 0, width, height);
- }
- // ==========================================
- public class Rain
- {
- PVector position, pposition, speed;
- float col;
- public Rain()
- {
- position = new PVector(random(0, width), -500, random(0, 800));
- pposition = position;
- speed = new PVector(0, 0);
- col = random(30, 100);
- }
- void draw()
- {
- stroke(100, col);
- strokeWeight(2);
- line(position.x, position.y, position.z, pposition.x, pposition.y, position.z);
- //ellipse(position.x,position.y,5,5);
- }
- void calculate()
- {
- pposition = new PVector(position.x, position.y);
- gravity();
- }
- void gravity()
- {
- speed.y += .2;
- speed.x += .01;
- position.add(speed);
- }
- }
- public class Splash
- {
- PVector position, speed;
- public Splash(float x, float y, float z)
- {
- float angle = random(PI, TWO_PI);
- float distance = random(1, 5);
- float xx = cos(angle)*distance;
- float yy = sin(angle)*distance;
- position = new PVector(x, y, z);
- speed = new PVector(xx, yy);
- }
- public void draw()
- {
- strokeWeight(1);
- stroke(100, 50);
- fill(100, 100);
- // ellipse(position.x, position.y, 2, 2 );
- point(position.x, position.y, position.z );
- }
- void calculate()
- {
- gravity();
- speed.x*=0.98;
- speed.y*=0.98;
- position.add(speed);
- }
- void gravity()
- {
- speed.y+=.2;
- }
- }
Thanks,
Katie
1