Getting Started with Processing.py
by Allison Parrish , Ben Fry , and Casey Reas
Copyright 2016 Maker Media. All rights reserved.
Printed in the United States of America.
Published by Maker Media, Inc. , 1160 Battery Street East, Suite 125, San Francisco, CA 94111.
Maker Media books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact OReilly Medias institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Editor: Patrick Di Justo
- Production Editor: Nicholas Adams
- Copyeditor: Jasmine Kwityn
- Proofreader: Gillian McGarvey
- Indexer: Angela Howard
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Rebecca Demarest
Revision History for the First Edition
- 2016-05-06: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781457186837 for release details.
Make:, Maker Shed, and Maker Faire are registered trademarks of Maker Media, Inc. The Maker Media logo is a trademark of Maker Media, Inc. Getting Started with Processing.py and related trade dress are trademarks of Maker Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and Maker Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
978-1-457-18683-7
[LSI]
Preface
Processing.py is an interactive programming and graphics framework for the Python programming language. Jonathan Feinberg created Processing.py in 2010, basing his work on an existing programming framework called Processing, created by Casey Reas and Ben Fry in 2001. Casey and Ben were inspired by how simple it was to write interesting programs with the languages of their childhood (Logo and BASIC), and intended their framework to be a way to sketch (prototype) full-screen, interactive software without the frustration of languages typically used for this purpose at the time (C++ and Java).
When the Processing project was first created, it was intended to be a language-agnostic, arts-oriented approach to interactive programming, taking inspiration from OpenGL, PostScript, and Design By Numbers, among other sources. Although early versions of Processing were compatible with the Python programming language, a decision was made to focus the teams limited resources on a Java-based syntax. Jonathan Feinbergs Processing.py project restored Python compatibility to the project. (For more information on the relationship between Processing, Processing.py, and Python, see .)
Processing was designed to be an ideal environment for teaching design and art students how to program and to give more technical students an easier way to work with graphics. The combination is a positive departure from the way programming is usually taught and, since 2001, Processing has been at the center of a growing movement to promote software literacy in the visual arts and visual literacy within technology.
Im a strong believer in the power of the Python programming language and have taught Python with great success to novice programmers in many disciplines, from software engineering to the humanities to the arts. For this reason, I was overjoyed when Casey and Ben approached me to help write this book, which brings together their time-tested creative coding framework with a programming language Ive found so friendly and productive for novice coders and experts alike. We believe that Processing.py is not just a great framework for learning how to program but an invaluable addition to the toolbox of Python programmers of all stripes who need a simple and clear means of making interactive applications.
This book is available in three slightly different versions. One version is an introduction to Processing using its traditional, Java-based syntax, and a second covers p5.js, a version of Processing reinterpreted for todays Web. The version you now have in your possession introduces Processing with the Python programming language, using Processing.py as the bridge between the two. The three books are organized in very similar ways, and much of the content is identical from one book to the other. The main difference, of course, is that the code examples in this book are all written in Python. This book also contains some additional information and educational material about Python-specific techniques, idioms, and data structures. We believe this book will work well as an introductory text for the Processing Development Environment, the Python programming language, and interactive programming in general.
We hope youll have fun with this book and be inspired to continue programming. Lets begin!
How This Book Is Organized
The chapters in this book are organized as follows:
Learn about Processing.py.
: Create your first Processing.py program.
Define and draw simple shapes.
Store, modify, and reuse data.
Control and influence programs with the mouse and the keyboard.
Transform the coordinates.
Load and display media, including images, fonts, and vector files.
Move and choreograph shapes.
Build new code modules.
Create code modules that combine variables and functions.
Simplify working with lists of variables.
Load and visualize data using the dictionary data structure.
Learn about sound, PDF export, and reading data from an Arduino board.
Who This Book Is For
This book is written for people who want a casual and concise introduction to computer programming so that they can create images and simple interactive programs. Its especially suited to beginning programmers who want to learn the Python programming language. Getting Started with Processing.py is not a programming textbook; as the title suggests, it will get you started. Its for teenagers, hobbyists, grandparents, and everyone in between.
This book is also appropriate for people with programming experience, particularly in the Python programming language, who want to learn the basics of interactive computer graphics. Getting Started with Processing.py contains techniques that can be applied to creating games, animation, and interfaces.
Conventions Used in This Book
The following typographical conventions are used in this book:
ItalicIndicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
Note
This type of paragraph signifies a general note.
Warning
This element indicates a warning or caution.
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from