Introduction To Computational Media (ICM) : Week 5

Mostly Review

2 Dimensional Arrays

Break on through to another dimension

Arrays can be placed into arrays themselves. In other words, you can have an array of arrays.

            ------------------------------------------------
            | 1 | 2 | 4 | 8  | 16 | 32  | 64  | 128  | 256  |
            ------------------------------------------------
            | 1 | 3 | 9 | 27 | 81 | 243 | 729 | 2187 | 6561 |
            ------------------------------------------------
        
The code to create this 2 dimensional array might be something like the following:
            int[][] myArray = {{1,2,4,8,16,32,64,128,256},{1,3,9,27,81,243,729,2187,6561}};
        
or it could be done using a nested for loop
            int[][] myArray = new int[2][9];
            for (int j = 0; j < myArray.length; j++)
            {
                for (int i = 0; i < myArray[j].length; i++)
                {
                    myArray[j][i] = (int) pow(j+2,i);
                    println(myArray[j][i]);
                }
                println("");
            }
        

Movie Playback

The video library: processing.video not only contains a Capture class, it also contains a Movie class for movie playback. This class should support any movie that QuickTime supports.

A Quick Playback Example
            import processing.video.*; 
            Movie myMovie; 
             
            void setup() 
            { 
              size(160,120);
              //myMovie = new Movie(this, "fish.mov"); // Local File, remember to "Add File"
              myMovie = new Movie(this,"http://www.flowerpowerart.com/hc/media/qt/fish-ani-02.mov");  // Network Playback
            
              myMovie.loop(); 
            } 
             
            void draw() 
            { 
              image(myMovie, 0, 0); 
            } 
             
            // Called every time a new frame is available to read 
            void movieEvent(Movie m) 
            { 
              myMovie.read(); 
            } 
        


Try it
Download Fish Movie

Taking Pictures

            import processing.video.*; 
            
            Capture myCapture; 
            
            PImage newImage;
            
            void setup() 
            {
              size(640, 240);   
              newImage = new PImage(320,240);
              myCapture = new Capture(this, 320, 240, 15); 
            } 
             
            void captureEvent(Capture myCapture) 
            { 
              myCapture.read(); 
            } 
             
            void draw() 
            {
                image(myCapture, 0, 0); 
                image(newImage, 320, 0);
            }
            
            void mousePressed()
            {
                newImage.copy(myCapture,0,0,myCapture.width,myCapture.height,0,0,newImage.width,newImage.height);
                newImage.updatePixels();
            } 
        
The important thing here is the copy function in the PImage class.