You are previewing Learning Processing, 2nd Edition.
O'Reilly logo
Learning Processing, 2nd Edition

Book Description

This book teaches the basic building blocks of programming needed to create cutting-edge graphics applications including interactive art, live video processing, and data visualization.

A unique lab-style manual, this book gives graphic and web designers, artists, illustrators, and anyone interested in learning to code a jumpstart on working with the Processing programming environment by providing instruction on the basic principles of the language, followed by careful explanations of advanced techniques.

From algorithmic design to data visualization, to computer vision and 3D graphics, this book teaches object-oriented programming from the ground up within the fascinating context of interactive visual media and creative coding. It is also supported by a companion website (learningprocessing.com), which includes all examples running in the browser using HTML5 canvas and p5.js, downloadable versions of all source code, answers to select chapter exercises, and over twenty hours of companion video lessons.



    • A friendly start-up guide to Processing, a free, open-source alternative to expensive software and daunting programming languages
    • No previous experience required—this book is for the true programming beginner!
    • Step-by-step examples, thorough explanations, hands-on exercises, and sample code supports your learning curve

Table of Contents

  1. Cover image
  2. Title page
  3. Table of Contents
  4. Copyright
  5. In memoriam
  6. Acknowledgments
  7. Introduction
    1. What is this book?
    2. Who is this book for?
    3. What is Processing?
    4. But shouldn’t I be learning _________?
    5. Write in this book!
    6. How should I read this book?
    7. Is this a textbook?
    8. Will this be on the test?
    9. Do you have a website?
    10. Take It One Step at a Time
    11. Algorithms
  8. Lesson 1: The Beginning
    1. 1: Pixels
      1. 1-1 Graph paper
      2. 1-2 Simple shapes
      3. 1-3 Grayscale color
      4. 1-4 RGB color
      5. 1-5 Color transparency
      6. 1-6 Custom color ranges
    2. 2: Processing
      1. 2-1 Processing to the rescue
      2. 2-2 How do I get Processing?
      3. 2-3 The Processing application
      4. 2-4 The sketchbook
      5. 2-5 Coding in Processing
      6. 2-6 Errors
      7. 2-7 The Processing reference
      8. 2-8 The Run button
      9. 2-9 Your first sketch
    3. 3: Interaction
      1. 3-1 Go with the flow
      2. 3-2 Our good friends, <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">setup()</span> and and <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">draw()</span>
      3. 3-3 Variation with the mouse
      4. 3-4 Mouse clicks and key presses
  9. Lesson 2: Everything You Need to Know
    1. 4: Variables
      1. 4-1 What is a variable?
      2. 4-2 Variable declaration and initialization
      3. 4-3 Using a variable
      4. 4-4 Many variables
      5. 4-5 System variables
      6. 4-6 Random: variety is the spice of life
      7. 4-7 Variable Zoog
      8. 4-8 Translation
    2. 5: Conditionals
      1. 5-1 Boolean expressions
      2. 5-2 Conditionals: if, else, else if
      3. 5-3 Conditionals in a sketch
      4. 5-4 Logical operators
      5. 5-5 Multiple rollovers
      6. 5-6 Boolean variables
      7. 5-7 A bouncing ball
      8. 5-8 Physics 101
    3. 6: Loops
      1. 6-1 What is iteration? I mean, what is iteration? Seriously, what is iteration?
      2. 6-2 The <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">while</span> loop, the only loop you really need loop, the only loop you really need
      3. 6-3 “Exit” conditions
      4. 6-4 The <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">for</span> loop loop
      5. 6-5 Local vs. global variables (a.k.a. “variable scope”)
      6. 6-6 Loop inside the <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">draw()</span> loop loop
      7. 6-7 Zoog grows arms
  10. Lesson 3: Organization
    1. 7: Functions
      1. 7-1 Break it down
      2. 7-2 “User-defined” functions
      3. 7-3 Defining a function
      4. 7-4 Simple modularity
      5. 7-5 Arguments
      6. 7-6 Passing a copy
      7. 7-7 Return type
      8. 7-8 Zoog reorganization
    2. 8: Objects
      1. 8-1 I’m down with OOP
      2. 8-2 Using an object
      3. 8-3 Writing the cookie cutter
      4. 8-4 Using an object: the details
      5. 8-5 Putting it together with a tab
      6. 8-6 Constructor arguments
      7. 8-7 Objects are data types too!
      8. 8-8 Object-oriented Zoog
  11. Lesson 4: More of the Same
    1. 9: Arrays
      1. 9-1 Arrays, why do you care?
      2. 9-2 What is an array?
      3. 9-3 Declaring and creating an array
      4. 9-4 Initializing an array
      5. 9-5 Array operations
      6. 9-6 Simple array example: the snake
      7. 9-7 Arrays of objects
      8. 9-8 Interactive objects
      9. 9-9 Processing’s array functions
      10. 9-10 One thousand and one Zoogs
  12. Lesson 5: Putting It All Together
    1. 10: Algorithms
      1. 10-1 Where have we been? Where are we going?
      2. 10-2 Algorithms: Dance to the beat of your own drum
      3. 10-3 From idea to parts
      4. 10-4 Part 1: The catcher
      5. 10-5 Part 2: Intersection
      6. 10-6 Part 3: The timer
      7. 10-7 Part 4: Raindrops
      8. 10-8 Integration: Puttin’ on the ritz
      9. 10-9 Getting ready for Act II
    2. 11: Debugging
      1. 11-1 Tip #1: Take a break
      2. 11-2 Tip #2: Get another human being involved
      3. 11-3 Tip #3: Simplify
      4. 11-4 Tip #4: <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">println()</span> is your friend is your friend
    3. 12: Libraries
      1. 12-1 Libraries
      2. 12-2 Built-in libraries
      3. 12-3 Contributed libraries
      4. 12-4 Manually installing libraries
  13. Lesson 6: The World Revolves Around You
    1. 13: Mathematics
      1. 13-1 Mathematics and programming
      2. 13-2 Modulus
      3. 13-3 Random numbers
      4. 13-4 Probability review
      5. 13-5 Event probability in code
      6. 13-6 Perlin noise
      7. 13-7 The <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">map()</span> function function
      8. 13-8 Angles
      9. 13-9 Trigonometry
      10. 13-10 Oscillation
      11. 13-11 Recursion
      12. 13-12 Two-dimensional arrays
    2. 14: Translation and Rotation (in 3D!)
      1. 14-1 The z-axis
      2. 14-2 What is P3D exactly?
      3. 14-3 Vertex shapes
      4. 14-4 Custom 3D shapes
      5. 14-5 Simple rotation
      6. 14-6 Rotation around different axes
      7. 14-7 Scale
      8. 14-8 The matrix: pushing and popping
      9. 14-9 A Processing solar system
      10. 14-10 PShape
  14. Lesson 7: Pixels Under a Microscope
    1. 15: Images
      1. 15-1 Getting started with images
      2. 15-2 Animation with an image
      3. 15-3 My very first image processing filter
      4. 15-4 An array of images
      5. 15-5 Pixels, pixels, and more pixels
      6. 15-6 Intro to image processing
      7. 15-7 A second image processing filter, making your own <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">tint()</span>
      8. 15-8 Writing to another <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">PImage</span> object&#8217;s pixels object’s pixels
      9. 15-9 Level II: Pixel group processing
      10. 15-10 Creative visualization
    2. 16: Video
      1. 16-1 Live video 101
      2. 16-2 Recorded video
      3. 16-3 Software mirrors
      4. 16-4 Video as sensor, computer vision
      5. 16-5 Background removal
      6. 16-6 Motion detection
      7. 16-7 Computer vision libraries
  15. Lesson 8: The Outside World
    1. 17: Text
      1. 17-1 Where do strings come from?
      2. 17-2 What is a string?
      3. 17-3 Displaying text
      4. 17-4 Text animation
      5. 17-5 Text mosaic
      6. 17-6 Rotating text
      7. 17-7 Display text character by character
    2. 18: Data Input
      1. 18-1 Manipulating strings
      2. 18-2 Splitting and joining
      3. 18-3 Dealing with data
      4. 18-4 Working with text files
      5. 18-5 Tabular data
      6. 18-6 Data that is not in a standardized format
      7. 18-7 Text analysis
      8. 18-8 XML
      9. 18-9 Using the Processing XML class
      10. 18-10 JSON
      11. 18-11 <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">JSONObject</span> and and <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">JSONArray</span>
      12. 18-12 Threads
      13. 18-13 APIs
    3. 19: Data Streams
      1. 19-1 Network communication
      2. 19-2 Creating a server
      3. 19-3 Creating a client
      4. 19-4 Broadcasting
      5. 19-5 Multi-user communication, Part 1: The server
      6. 19-6 Multi-user communication, Part 2: The client
      7. 19-7 Multi-user communication, Part 3: All together now
      8. 19-8 Serial communication
      9. 19-9 Serial communication with handshaking
      10. 19-10 Serial communication with strings
  16. Lesson 9: Making Noise
    1. 20: Sound
      1. 20-1 Basic sound playback
      2. 20-2 A bit fancier sound playback
      3. 20-3 Sound synthesis
      4. 20-4 Sound analysis
      5. 20-5 Sound thresholding
      6. 20-6 Spectrum analysis
    2. 21: Exporting
      1. 21-1 Exporting to web
      2. 21-2 Stand-alone applications
      3. 21-3 High-resolution PDFs
      4. 21-4 Images and <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">saveFrame()</span>
      5. 21-5 Recording video
  17. Lesson 10: Beyond Processing
    1. 22: Advanced Object-Oriented Programming
      1. 22-1 Encapsulation
      2. 22-2 Inheritance
      3. 22-3 An inheritance example: shapes
      4. 22-4 Polymorphism
      5. 22-5 Overloading
    2. 23: Java
      1. 23-1 Revealing the wizard
      2. 23-2 If you did not have Processing, what would your code look like?
      3. 23-3 Exploring the Java API
      4. 23-4 Other useful Java classes: <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">ArrayList</span>
      5. 23-5 Other useful Java classes: <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="inlinecode">Rectangle</span>
      6. 23-6 Exception (error) handling
      7. 23-7 Java outside of Processing
  18. Appendix A: Common Errors
    1. Compile-time errors
    2. Runtime errors
    3. A-1 Compile-time errors
    4. A-2 Runtime errors
  19. Index