logo资料库

Learning Processing A Beginner's Guide to Programming Images, Animation 2nd.pdf

第1页 / 共525页
第2页 / 共525页
第3页 / 共525页
第4页 / 共525页
第5页 / 共525页
第6页 / 共525页
第7页 / 共525页
第8页 / 共525页
资料共525页,剩余部分请下载后查看
Learning Processing A Beginner’s Guide to Programming Images, Animation, and Interaction
Learning Processing A Beginner’s Guide to Programming Images, Animation, and Interaction Second Edition Daniel Shiffman
Morgan Kaufmann Publishers is an imprint of Elsevier 30 Corporate Drive, Suite 400, Burlington, MA 01803, USA Copyright © 2008, 2015 Elsevier Inc. All rights reserved. Designations used by companies to distinguish their products are often claimed as trademarks or registered trademarks. In all instances in which Morgan Kaufmann Publishers is aware of a claim, the product names appear in initial capital or all capital letters. All trademarks that appear or are otherwise referred to in this work belong to their respective owners. Neither Morgan Kaufmann Publishers nor the authors and other contributors of this work have any relationship or affiliation with such trademark owners nor do such trademark owners confirm, endorse, or approve the contents of this work. Readers, however, should contact the appropriate companies for more information regarding trademarks and any related registrations. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means— electronic, mechanical, photocopying, scanning, or otherwise—without prior written permission of the publisher. Permissions may be sought directly from Elsevier’s Science & Technology Rights Department in Oxford, UK: phone: (+44) 1865 843830, fax: (+ 44) 1865 853333, E-mail: permissions@elsevier.com. You may also complete your request online via the Elsevier homepage (http://www.elsevier.com) by selecting “Support & Contact” then “Copyright and Permission” and then “Obtaining Permissions.” Library of Congress Cataloging-in-Publication Data A catalog record for this book is available from the Library of Congress. ISBN: 978-0-12-394443-6 For information on all Morgan Kaufmann publications, visit our website at www.mkp.com or www.books.elsevier.com Printed in the United States of America.
In memoriam Red Burns was born in 1925 in Ottawa, Canada. In 1971, after having already led several full lives, she founded the Alternate Media Center at New York University. The center later became the Interactive Telecommunications Program (ITP) where she served as chair from 1982 until 2010. I met Red in 2001, when she introduced the program to me in what was likely her 20th year of student orientation. I was rather terrified of Red, but it didn’t last. I quickly discovered her warmth, and over the next twelve years I was incredibly lucky to experience her fierce intelligence, five-word e-mails, and unwavering protectiveness of humanity over technology. People were always at the center of her thinking, and the tools (like the one taught in this book) were just a means for expression and communication. The ideas in this book were born from her mentorship and friendship. As the ITP saying goes, “Red Burns Changed My Life.” http://itp.nyu.edu/redburns/
Acknowledgments In the fall of 2001, I wandered into the Interactive Telecommunications Program in the Tisch School of the Arts at New York University, having not written a line of code since the early 1980s, when I’d done some experimenting in BASIC on an AppleII+. There, in a first semester course entitled “Introduction to Computational Media,” I discovered programming. ITP has been my home ever since. Without the inspiration and support of the department, this book would never have been written. Red Burns, the department’s founder, encouraged and championed me for my first ten years at ITP. Sadly, she passed away in August 2013; this book is dedicated to her legacy. Dan O’Sullivan was the first to suggest that I try a course in Processing, giving me a reason to start putting together programming tutorials. Shawn Van Every sat next to me in the office throughout the majority of the writing of this book’s first edition, providing helpful suggestions, code, and a great deal of moral support along the way. Tom Igoe’s work with physical computing provided inspiration for this book, and he was particularly helpful as a resource while putting together examples on network and serial communication. And it was Clay Shirky who I can thank for stopping me in the hall one day to tell me I should write a book in the first place. Clay also provided a great deal of feedback on early drafts of the first edition. All of my fellow computational media teachers at ITP have provided helpful suggestions and feedback along the way: Danny Rozin (the inspiration behind Chapters 15 and 16), Mimi Yin, Lauren McCarthy (whose innovative work developing p5.js has opened my eyes up to the world of JavaScript and the web), Amit Pitaru (who helped in particular with the first edition’s chapter on sound), Nancy Lewis, James Tu, Mark Napier, Chris Kairalla, Luke Dubois, Roopa Vasudevan, Matt Parker, Heather Dewey-Hagborg, and Jim Moore (who was my teacher for that first semester course!). My gratitude goes to the following ITP full-time faculty members for continuously offering their insight and fortitude throughout the writing of this book: Marianne Petit, Nancy Hechinger, Marina Zurkow, Katherine Dillon, Eric Rosenthal, Gabe Barcia-Colombo, and Benedetta Piantella Simeonidis. And my full appreciation goes to the rest of the faculty and staff at ITP who have made this possible: George Agudow, Edward Gordon, Midori Yasuda, Rob Ryan, John Duane, Marlon Evans, Tony Tseng, Matthew Berger, Karl Ward, and Megan Demarest. The students of ITP, too numerous to mention, have been an amazing source of feedback, having used much of the material in this book in trial runs for various courses. I have stacks of pages with notes scrawled in the margins, as well as a vast archive of email exchanges with corrections, comments, and generous words of encouragement, all of which were integral to the development of this book’s ideas. I’m also indebted to the energetic and supportive community of Processing programmers and artists. I’d probably be out of a job if it weren’t for Casey Reas and Ben Fry who created Processing, to say the least. I’ve learned half of what I know simply from reading through the Processing source code; the elegant simplicity of the Processing language, website, and IDE has made programming accessible and fun for me and all of my students. I’ve received advice, suggestions, and comments from many Processing programmers including Andres Colubri, Scott Murray, Florian Jennet, Elie Zananiri, Scott Garner, Manindra Mohanara, Jer Thorp, Marius Watz, Robert Hodgin, Golan Levin, Tom Carden, Karsten Schmidt, Ariel Malka, Burak Arikan, and Ira Greenberg. The following teachers were also helpful in test- driving early versions of the first edition in their courses: Hector Rodriguez, Keith Lam, Liubo Borissov, Rick Giles, Amit Pitaru, David Maccarella, Jeff Gray, and Toshitaka Amaoka.
Acknowledgments x Peter Kirn and Douglas Edric Stanley provided extraordinarily detailed comments and feedback during the first edition’s technical review process; the book is a great deal better than it would have been without their efforts. Demetrie Tyler did a tremendous job working on the original visual design of the cover and interior of the book. And a thanks to David Hindman, who helped me organize the original screenshots and diagrams. My thanks to Rich Hauck who developed the website for the first edition. I’d also like to thank everyone at Morgan Kaufmann/Elsevier who worked on producing the first edition: Gregory Chalson, Tiffany Gasbarrini, Jeff Freeland, Danielle Monroe, Matthew Cater, Michele Cronin, Denise Penrose, and Mary James. For the second edition, I am incredibly grateful to everyone at Morgan Kaufmann/Elsevier and O’Reilly who were supportive of my choice in using the Atlas publishing platform (https://atlas.oreilly.com/) to create this book. Using Atlas allowed me to have a more fluid process and involve lots of contributors with feedback and advice. Wilm Thoben, Seth Kranzler, and Jason Sigal all provided sound feedback and edits on Chapter 20: Sound. Mark Sawula, Yong Bakos, and Kasper Kasperman read PDFs as they were generated and gave excellent critique and feedback. J. David Eisenberg acted as a de-facto technical editor, offering numerous and terrific suggestions for improving explanations and examples. A special thanks goes to Johanna Hedva who copy-edited almost the entire book during elaborate layout transformations. In addition, several key content changes exist because of her keen eye. From Elsevier, Todd Green went above and beyond in working out the details of the complex collaboration with O’Reilly and Atlas. Thanks also to Charlie Kent and Debbie Clark for their help in facilitating production details. I’d like to say, in general, that the Atlas platform and the team at O’Reilly are terrific to work with: This book has all sorts of strange layout quirks, and it’s amazing that the entire end product is generated from an HTML file using CSS and XSLT for layout. Thanks to Andrew Odewahn, Rune Madsen, Sanders Kleinfeld, Dan Fauxsmith, and Adam Zaremba for giving me early access to Atlas and teaching me its magic. Thanks to Rebecca Demarest for her help and advice with illustrations, and Ron Bilodeau for his feats of CSS. Last, but the opposite of least, I’d like to thank Kristen Brown who listened thoughtfully to every, single, tiny detail I asked about and applied the exact skills I lacked, knowing how to prioritize and keep a schedule to make sure this book actually met its deadline. You can see the scale of her contribution in this book’s Github repo’s pulse. Most importantly, I’d like to thank my wife, Aliki Caloyeras; my children, Elias and Olympia; my parents, Doris and Bernard Shiffman; and my brother, Jonathan Shiffman, for their moral support, advice, and encouragement, not only in the second edition of this book, but in everything else.
Introduction What is this book? This book tells a story. It is a story of liberation, of taking the first steps toward understanding the foundations of computing, writing your own code, and creating your own media without the bonds of existing software tools. This story is not reserved for computer scientists and engineers. This story is for you. Who is this book for? This book is for the beginner. If you have never written a line of code in your life, you’re in the right place. No assumptions are made, and the fundamentals of programming are covered slowly, one by one, in the first nine chapters of this book. You do not need any background knowledge besides the basics of operating a computer — turning it on, browsing the web, launching an application, that sort of thing. Because this book uses Processing (more on Processing in a moment), it’s especially good for someone studying or working in a visual field, such as graphic design, painting, sculpture, architecture, film, video, illustration, web design, and so on. If you’re in one of these fields (at least one that involves using a computer), you’re probably well-versed in a particular software package, possibly more than one, such as Photoshop, Illustrator, AutoCAD, Maya, After Effects, and so on. The point of this book is to release you, at least in part, from the confines of existing tools. What can you make, what can you design, if, instead of using someone else’s tools, you create your own? If you already have some programming experience but are interested in learning about Processing, this book could also be useful. The early chapters will provide you with a quick refresher (and solid foundation) for the more advanced topics found in the second half of the book. What is Processing? Let’s say you’re taking Computer Science 101, perhaps taught using the Java programming language. Here is the output of the first example program demonstrated in class:
xii Introduction Traditionally, programmers are taught the basics via command line output: 1. TEXT IN → You write your code as text. 2. TEXT OUT → Your code produces text output on the command line. 3. TEXT INTERACTION → The user can enter text on the command line to interact with the program. The output “Hello, World!” of this example program is an old joke, a programmer’s convention in which the text output of the first program you learn to write in any given language says “Hello, World!” It first appeared in a 1974 Bell Laboratories memorandum by Brian Kernighan entitled, “Programming in C: A Tutorial.” The strength of learning with Processing is its emphasis on a more intuitive and visually responsive environment, one that is more conducive to artists and designers learning programming. 1. TEXT IN → You write your code as text. 2. VISUALS OUT → Your code produces visuals in a window. 3. MOUSE INTERACTION → The user can interact with those visuals via the mouse (and more as you will see in this book!). Processing’s “Hello, World!” might look something like this:
分享到:
收藏