06.01.2013 Views

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Exporting 405<br />

Example 21-5 records a movie of a mouse drawing on the screen. Th e movie is fi nished when the space<br />

bar is pressed.<br />

Example 21-5: Making a QuickTime movie<br />

import processing.video.*;<br />

fi g. 21.6 Output of Example 21-5<br />

MovieMaker mm; // Declare MovieMaker object<br />

void setup() {<br />

size(320, 240);<br />

// Create MovieMaker object with size, filename,<br />

// framerate, compression codec and quality<br />

mm = new MovieMaker(this, width, height, "drawing.mov", 30, MovieMaker.H263,<br />

MovieMaker.HIGH);<br />

background(255);<br />

}<br />

void draw() {<br />

stroke(0);<br />

strokeWeight(4);<br />

if (mousePressed) {<br />

line(pmouseX, pmouseY, mouseX, mouseY);<br />

}<br />

mm.addFrame(); // Add window's pixels <strong>to</strong> movie<br />

}<br />

The MovieMaker class is part of<br />

<strong>Processing</strong>’s video library.<br />

A new frame is added <strong>to</strong> the movie<br />

every cycle through draw( ).<br />

void keyPressed() {<br />

if (key = = ' ') {<br />

println( "finishing movie ");<br />

mm.finish(); // Finish the movie if space bar is pressed!<br />

}<br />

}<br />

Do not forget <strong>to</strong> fi nish the movie! Otherwise, it will not play properly.<br />

Exercise 21-3: Create a movie from any <strong>Processing</strong> sketch you have made or any example<br />

in this book.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!