Create Interactive Art with Code
Total Page:16
File Type:pdf, Size:1020Kb
foreword by nathan seidle, founder of sparkfun electronics Processing is a free, beginner-friendly programming • Create visualizations that change based on sound, language designed to help non-programmers create light, and temperature readings interactive art with code. With a little imagination and Processing as your create interactive art with code The SparkFun Guide to Processing, the first in the paintbrush, you’ll be on your way to coding your own SparkFun Electronics series, will show you how to gallery of digital art in no time! Put on your artist’s hat, craft digital artwork and even combine that artwork and begin your DIY journey by learning some basic with hardware so that it reacts to the world around programming and making your first masterpiece with you. Start with the basics of programming and The SparkFun Guide to Processing. animation as you draw colorful shapes and make A B O U T T H E A U T H O R them bounce around the screen. Then move on to a series of hands-on, step-by-step projects that Derek Runberg works in the Department of Education will show you how to: at SparkFun Electronics, where he develops educational materials for workshops and classrooms across the coun- • Make detailed pixel art and scale it to epic try. Before joining SparkFun, Runberg taught a middle proportions school technology course on Processing and Arduino. • Write a maze game and build a MaKey MaKey A B O U T SPARKFUN ELECTRONICS controller with fruit buttons SparkFun Electronics is an online retail store that sells • Play, record, and sample audio to create your electronic parts for DIY projects. It offers classes for the own soundboard public as well as resources, tutorials, and professional • Fetch weather data from the Web and build a development for educators through its Department of custom weather dashboard Education. COVERS PROCESSING 2 TH E FINEST I N G EEK ENTERTAI N M ENT ™ www.nostarch.com $29.95 ($34.95 CDN) “I LI E FLAT.” COMPUTERS/PROGRAMMING IN: SHELVE This book uses a durable binding that won’t snap shut. THE SPARKFUN GUIDE TO PROCESSING THE SPARKFUN GUIDE TO PROCESSING CREATE INTERACTIVE ART WITH CODE BY DEREK RUNBERG SAN FRANCISCO THE SPARKFUN GUIDE TO PROCESSING. Copyright © 2015 by SparkFun Electronics. 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. Printed in USA First printing 19 18 17 16 15 1 2 3 4 5 6 7 8 9 ISBN-10: 1-59327-612-5 ISBN-13: 978-1-59327-612-6 Publisher: William Pollock Production Editor: Alison Law Cover Illustration: Pete Holm Interior Design: Beth Middleworth Developmental Editor: Jennifer Griffith-Delgado Technical Reviewer: Andres Colubri Copyeditor: Rachel Monaghan Compositor: Susan Glinert Stevens Proofreader: James Fraleigh For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly: No Starch Press, Inc. 245 8th Street, San Francisco, CA 94103 phone: 415.863.9900; [email protected] www.nostarch.com Library of Congress Cataloging-in-Publication Data: Runberg, Derek. The SparkFun guide to Processing : create interactive art with code / by Derek Runberg. pages cm Includes index. Summary: "A project-based guide for beginners that teaches how to use the programming language Processing. Covers digital artwork and hardware topics including pixel art, photo editing, video manipulation, 3D design, and using Processing to control an Arduino"-- Provided by publisher. ISBN 978-1-59327-612-6 -- ISBN 1-59327-612-5 1. Processing (Computer program language) 2. Computer art. 3. Digital video. 4. Arduino (Programmable controller)--Programming. I. SparkFun Electronics. II. Title. QA76.73.P75.R86 2015 776--dc23 2015024859 No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. 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 it. THIS BOOK IS DEDICATED TO THE EDUCATORS ACROSS THE UNITED STATES WHO ARE WORKING DILIGENTLY TO BRING COMPUTER SCIENCE AND ELECTRONICS TO THE FOREFRONT OF THEIR CLASSROOM PRACTICE. ABOUT THE AUTHOR Derek Runberg is the educational technologist at This website focused on SparkFun Electronics, a position dedicated to creating developing curricula for outstanding curriculum for electronics and computer teachers using Processing in science education. Before joining SparkFun, Derek the mainstream classroom. was a middle school technology and engineering Derek’s Processing activities educator for five years. During this time, he ran a were focused on getting number of after-school and summer programs on both students to be creative with programmable electronics and Processing. Derek’s code, for the sake of creating. time as an educator has culminated in this book, which In his free time, Derek likes to spend time with his takes computer science concepts and breaks them two children, Bear and Bridge, and his wife, Zondra. If into digestible chunks that everyone can understand. you ever run into Derek, he will talk your ear off about Derek documented his work with Processing either food or technology; choose wisely. He enjoys in the middle school classroom as the author of the the outdoors, writes code when it’s raining, and has website Processing and Interactivity for Educators. been known to do both at the same time! ABOUT SPARKFUN ELECTRONICS SparkFun is an online retailer that produces and sells them and all of the documentation you need to get up the widgets and parts that end up in a lot of maker and running at SparkFun. projects, prototypes, and even the International SparkFun’s Department of Education develops Space Station. Nathan Seidle started the company curricula and runs professional development programs after blowing a circuit board in 2003, while he was for educators of all kinds. The department is at the an undergraduate at Colorado University. At the time, forefront of a number of computer science and maker circuit boards were really hard to get; you had to fax initiatives that are making headway in the classroom. your credit card to another country and hope that you Processing is an everyday tool in the department got your hardware in six to eight weeks. Nathan felt and is a foundational part of SparkFun’s professional he could do better, and he did. SparkFun.com was development workshops around the country. You can born, and it now sells over 3,000 different parts of learn more about SparkFun and the Department of all shapes and sizes for your digital electronic needs. Education at https://www.sparkfun.com/ and https:// From a basic Arduino to GPS modules, you can find learn.sparkfun.com/. ABOUT THE TECHNICAL REVIEWER Andres Colubri is an active mathematics in Argentina and later received an MFA contributor to the Processing from UCLA’s Design Media Arts program. He uses project, as the main developer Processing as the main tool to bridge his interests of the OpenGL renderer and the in computer graphics, visualization, and statistical Video library in Processing 2 modeling. You can see some of his work at http:// and 3. He studied physics and andrescolubri.net/. CONTENTS Foreword by Nathan Seidle ............................................................ xvi Introduction........................................................................................ xx Project 0: Getting Started with Processing .............................. 2 Project 1: Pixel Art ............................................................................ 16 Project 2: Holiday Card .................................................................... 32 Project 3: A First Dynamic Sketch ................................................. 48 Project 4: Interactive Time-Based Art ......................................... 64 Project 5: Enter the Matrix ............................................................ 80 Project 6: Image Processing with a Collage ............................ 92 Project 7: Playing with Text ......................................................... 118 Project 8: Two Drawing Programs .............................................. 134 Project 9: A Maze Game .................................................................... 146 Project 10: Manipulating Movies and Capturing Video .......... 166 Project 11: Audio Processing with Minim .................................. 184 Project 12: Building a Weather Dashboard with JSON Data ........................................................... 208 Project 13: Using Sensors with Processing and Arduino .................................................................. 232 Index ..................................................................................................... 266 CONTENTS IN DETAIL Foreword by Nathan Seidle .......................................................