top of page
  • Writer's pictureRob George

Week 13: Movie Play + Function Review

In Class Task 1: Function Review

The task was to use a function to create a spaceship that can be repeated and placed around the screen at different sizes and colors.

//Spaceships

PImage space;


void setup(){

size(640, 360);

space=loadImage("space.jpg");

}


void draw(){

background(0);

image(space, 0, 0, 705, 471); //dimensions 5647x3770 divided by 8

spaceShip(100, 100, 100, 255, 0, 0, 0, 255, 0); //Red Ship

spaceShip(400, 150, 200, 0, 0, 255, 240, 100, 40); //Blue Ship

spaceShip(550, 80, 80, 37, 229, 205, 245, 238, 10); //Teal Ship

spaceShip(500, 300, 50, 245, 10, 222, 10, 245, 176); //Pink Ship

spaceShip(150, 250, 150, 245, 234, 10, 232, 10, 245); //Yellow Ship

}


void spaceShip (float x, float y, float diam, float r, float g, float b, float r2, float g2, float b2){

noStroke();

//Draw body of ship (the black part)

fill(r, g, b);

ellipse(x, y, diam/2, diam/2);

ellipse(x, y+diam/5, diam, diam/2);

//Windows

fill(r2, g2, b2);

ellipse(x, y+diam/5, diam/6, diam/6);

ellipse(x-diam/4, y+diam/5, diam/6, diam/6);

ellipse(x+diam/4, y+diam/5, diam/6, diam/6);

}


In Class Lesson 1: Movie Play

The last lesson was about uploading a movie to play on the screen using the movie library in Processing and crop it to a corner of the screen. I also learned that you can use keyPressed() to restart the video at a certain point. In this case it resets to the 15 second point when you press spacebar.


Short Playthrough of Video.

Pressing Spacebar to bring video back to 15 second mark.

// Movie Play


import processing.video.*;


//Movie Class


Movie movie;


void setup(){

size(1200, 800);

movie=new Movie(this, "sonybravia.mov");

movie.play(); //play only runs once: movie.;oop will loop forever

}


void draw(){

background(0);

//movie.speed(2.0); //1.0 is normal speed

image(movie, 0, 0, 600, 360);

}


void keyPressed(){ //key pressed, jumps to specific part of video

if(key==' '){

movie.jump(15); //jumps to 15 seconds

}

}


void movieEvent(Movie m){

m.read(); //to read the pixel data of the video

}



< Return to Coding Page

3 views0 comments
bottom of page