The Essential Guide to Processing for Flash Developers
Total Page:16
File Type:pdf, Size:1020Kb
The Essential Guide to Processing for Flash Developers Ira J. Greenberg THE ESSENTIAL GUIDE TO PROCESSING FOR FLASH DEVELOPERS Copyright © 2009 by Ira J. Greenberg All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-1979-8 ISBN-13 (electronic): 978-1-4302-1980-4 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or visit http://www.springeronline.com. For information on translations, please e-mail [email protected], or visit http://www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. Credits President and Publisher: Coordinating Editor: Paul Manning Fran Parnell Lead Editor: Copy Editor: Ben Renow-Clarke Mary Ann Fugate Technical Reviewer: Compositor: Ian Piper Mary Sudul Editorial Board: Indexer: Clay Andres, Steve Anglin, Mark Beckner, Ewan BIM Indexing & Proofreading Services Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Cover Image Designer: Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Corné van Dooren Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Cover Designer: Wade, Tom Welsh Kurt Krames To Robin, Ian, and Sophie Contents at a Glance Foreword ...................................................................................................................... ix About the Author ......................................................................................................... x About the Technical Reviewer ................................................................................... xi Acknowledgments ..................................................................................................... xii Introduction ............................................................................................................... xiii Chapter 1: Flash vs. Processing: Let the Death Match Begin! ................................ 1 Chapter 2: Processing Primer I: Just the Basics .................................................... 27 Chapter 3: Processing Primer II: Beyond the Basics ............................................. 73 Chapter 4: Object-Oriented Programming in Processing .................................... 133 Chapter 5: I Like Particle Engines! ......................................................................... 181 Chapter 6: A “Serious” Game ................................................................................. 253 Chapter 7: Hacking Life ........................................................................................... 331 Chapter 8: Creative Information Visualization ...................................................... 411 Index .......................................................................................................................... 479 iv Contents Foreword ...................................................................................................................... ix About the Author ......................................................................................................... x About the Technical Reviewer ................................................................................... xi Acknowledgments ..................................................................................................... xii Introduction ............................................................................................................... xiii Chapter 1: Flash vs. Processing: Let the Death Match Begin! ................................ 1 What You Should Know (Well, Sort of) ...................................................................... 2 The Complexity of Simplicity ...................................................................................... 3 Out-Yahoo’d ............................................................................................................... 4 K.I.S.S.—The Processing IDE ................................................................................... 5 File ......................................................................................................................... 7 Edit ....................................................................................................................... 10 Sketch .................................................................................................................. 13 Tools .................................................................................................................... 14 Help ...................................................................................................................... 18 Processing API from 30,000 Feet ............................................................................ 18 Procedural Elegance ............................................................................................ 18 Peeking Is Encouraged ........................................................................................ 19 Prototyping and Beyond ........................................................................................... 19 Summary .................................................................................................................. 25 Chapter 2: Processing Primer I: Just the Basics .................................................... 27 Graphic Primitives .................................................................................................... 27 Rendering ................................................................................................................ 29 A Primitive Sampler ................................................................................................. 35 Coding a Table ..................................................................................................... 35 Filling the Table .................................................................................................... 39 Transformations ....................................................................................................... 48 Drawing .................................................................................................................... 61 Arrays ................................................................................................................... 68 Summary .................................................................................................................. 71 v CONTENTS Chapter 3: Processing Primer II: Beyond the Basics ............................................. 73 Primitive vs. Reference Variables ............................................................................ 73 Curves .................................................................................................................. 76 Adding Motion ...................................................................................................... 92 Imaging .................................................................................................................... 98 Loading Images .................................................................................................... 98 Pixels .................................................................................................................. 109 Events .................................................................................................................... 115 Tiny Taste of Typography ...................................................................................... 129 Summary ................................................................................................................ 131 Chapter 4: Object-Oriented Programming in Processing .................................... 133 Some OOP Theory ................................................................................................ 134 Legs Class ............................................................................................................. 137 Running Amuck ...................................................................................................... 150 Composing Classes ............................................................................................... 156 Head Class: More Than Just a Pretty Face ......................................................