An Artists Guide to Programming
A Graphical Introduction
Jim Parker
An Artists Guide to Programming. Copyright 2022 by Jim Parker.
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.
First printing
25 24 23 22 1 2 3 4 5 6 7 8 9
ISBN-13: 978-1-7185-0164-5 (print)
ISBN-13: 978-1-7185-0165-2 (ebook)
Publisher: William Pollock
Production Manager: Rachel Monaghan
Production Editor: Paula Williamson
Developmental Editors: Athabasca Witschi and Nathan Heidelberger
Cover Illustration: Gina Redman
Interior Design: Octopod Studios
Technical Reviewer: Jeffrey Boyd
Copyeditor: Andy Carroll
Compositor: Jeff Lytle, Happenstance Type-O-Rama
Proofreader: Emelie Battaglia
The following images are reproduced with permission: Figure 96-1 by Brocken Inaglory, printed under the GNU Free Documentation License, Version 1.2.
For information on distribution, bulk sales, corporate sales, or translations, please contact No Starch Press, Inc. directly at info@nostarch.com or:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1-415-863-9900
www.nostarch.com
Library of Congress Cataloging-in-Publication Data
Names: Parker, J. R. (Jim R.), 1955- author.
Title: An artists guide to programming : a graphical introduction / Jim
Parker.
Description: San Francisco : No Starch Press, 2022. | Includes index. |
Identifiers: LCCN 2021046087 (print) | LCCN 2021046088 (ebook) | ISBN
9781718501645 (print) | ISBN 9781718501652 (ebook)
Subjects: LCSH: Multimedia systems. | Computer graphics. |
Microcomputers--Programming. | Processing (Computer program language) |
Java (Computer program language)
Classification: LCC QA76.575 .P357 2022 (print) | LCC QA76.575 (ebook) |
DDC 006.7--dc23
LC record available at https://lccn.loc.gov/2021046087
LC ebook record available at https://lccn.loc.gov/2021046088
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.
About the Author
Jim Parker is a professor, author, and artist who has published a dozen books and over 170 technical papers, in addition to writing short stories. He has degrees in mathematics and computer science, and a PhD from the State University of Ghent, Belgium. His areas of expertise include computer simulation, image processing, artificial intelligence, game design, and generative art. He has exhibited generative art, and even sent art into space. He lives on a small ranch in the foothills of the Rocky Mountains, where he helps raise small animals and Tennessee walking horses.
About the Technical Reviewer
Jeffrey Boyd received his PhD in computer science from the University of British Columbia and is currently an associate professor at the University of Calgary. His research focuses on sensing and computer vision, with applications in analyzing human motion, interactive art and music, sonification, and computational musicology. Dr. Boyd and his students do diverse work that includes wearable systems that provide real-time, sonic feedback to train and rehabilitate speed skaters; numerous art and sound installations; and the musicological study of contemporary composers through the analysis of ambisonic recordings of their work.
Authors Note
Processing is a programming language designed by Casey Reas and Ben Fry to be used by artists creating generative art. It is based on Java, and it extends Java in many useful ways: it allows the programmer to easily read, display, and write image files; it has functions for drawing elementary shapes and curves; it makes manipulating colors simple; and so on. Most importantly, it opens a window into which the programmer/artist will draw. All Processing programs are intended to create an image, a visual output.
This book presents the Processing language and its many applications in a set of graduated examples. The details of the syntax are not the focus, although they are explained briefly. The idea is to present a collection of programs that the reader can experiment with. When the book is open to any sketch, the left side of the page will have descriptive text, while the right will show the program and the result, as an image.
The code is available to you. Use it, change it, share it. You can download the code and all the necessary supporting files (images, sound files, and so on) at https://nostarch.com/artists-guide-programming/.
Some concepts will be more complex than others, of course. There is plenty of documentation for Processing on the internet, beginning with the https://processing.org/ site.
Processing can be used with Arduino computers too. It has modules for sound, video, and scientific calculations, and it can be used to present images in a browser. It is my hope that this book will allow you to start experimenting with programming and generative art.
Why are there few comments in the code? To save space on the right page! The entire left page is a description of the program and method, so it is in effect a large comment.
Jim Parker
Introduction
The Basics of a Programming Language: Processing
When someone programs a computer, they are really communicating with it. It is an imperative and precise communication. Imperative because the computer has no choice; it is being told what to do, and it will do exactly that. Precise because a computer does not apply any interpretation to what it is being told. Computers do not think and so cant evaluate a command that would amount to expose the patient to a fatal dose of radiation with any skepticism. So we, as programmers, must be careful and precise in what we instruct the machine to do.
When humans communicate with each other, we use a language. Similarly, humans use languages to communicate with computers, but these languages are artificial (humans invented them for this purpose), terse (there are few if any modifiersno way to express emotions or gradations of any feeling), precise (each item in the language means one thing), and written (we do not yet speak to computers in a programming language).