Learn Python Visually

Book description

This beginners book introduces non-programmers to the fundamentals of computer coding within a visual, arts-focused context. Tristan Bunn’s remarkably effective teaching approach is designed to help you visualize core programming concepts while you make cool pictures, animations, and simulations using Python Mode for the open-source Processing development environment.

Right from the first chapter, you'll produce and manipulate colorful drawings, shapes and patterns as Bunn walks you through a series of easy-to-follow graphical coding projects that grow increasingly complex. You’ll go from drawing with code to animating a bouncing DVD screensaver and practicing data-visualization techniques. Along the way, you’ll encounter creative-yet-practical skill-building challenges that relate to everything from video games, cars, and coffee, to fine art, amoebas, and Pink Floyd. As you grow more fluent in both Python and programming in general, topics shift toward the mastery of algorithmic thinking, as you explore periodic motion, Lissajous curves, and using classes to create objects.

You’ll learn about:

•Basic coding theories and concepts, like variables, data types, pixel coordinates, control flow and algorithms
•Writing code that produces drawings, patterns, animations, data visualizations, user interfaces, and simulations
•Using conditional statements, iteration, randomness, lists and dictionaries
•Defining functions, reducing repetition, and making your code more modular
•How to write classes, and create objects to structure code more efficiently

In addition to giving you a good grounding in general programming, the skills and knowledge you’ll gain in this book are your entry point to coding for an ever-expanding horizon of creative technologies.

Table of contents

  1. Title Page
  2. Copyright
  3. About the Author
  4. Acknowledgments
  5. Introduction
    1. Who Is This Book For?
    2. What Is Python Mode for Processing?
    3. What Are Algorithms?
    4. What Is Creative Coding?
    5. Where Can I Find Help?
      1. Online Resources
      2. Source Code and Solutions
    6. What’s in This Book?
    7. Let’s Go!
  6. Chapter 1: Hello, World!
    1. Processing Installation and Python Mode Setup
    2. Your First Sketch
      1. Comments
      2. Whitespace
      3. Errors
      4. Color
      5. Fills and Strokes
      6. Background Color
    3. Color Modes
    4. 2D Primitives
      1. triangle()
      2. ellipse()
      3. quad()
      4. line()
    5. Variables
    6. Arithmetic Operators
      1. Basic Operations
      2. Modulo Operator
    7. Arcs
    8. Summary
  7. Chapter 2: Drawing More Complicated Shapes
    1. Displaying a Grid
    2. Drawing Curves Using Catmull-Rom Splines
      1. Curving Lines with curve()
      2. Changing Curves with curveTightness()
    3. Drawing Bézier Curves
      1. Using the bezier() Function
      2. Positioning Anchor and Control Points
    4. Drawing Shapes Using Vertices
      1. Bézier Vertices
    5. Using Vector Graphics Software for Generating Shapes
    6. Summary
  8. Chapter 3: Introduction to Strings and Working with Text
    1. Strings
      1. Creating Strings in Python
      2. Using Concatenation and String Formatting
      3. Working with String Length
    2. String Manipulation
      1. Slice Notation
      2. String Methods
    3. Typography
      1. Fonts
      2. Text Functions
    4. Summary
  9. Chapter 4: Conditional Statements
    1. Control Flow
    2. Conditional Statements
      1. The Boolean Data Type
      2. Relational Operators
      3. if Statements
      4. elif Statements
      5. else Statements
      6. Logical Operators
    3. Summary
  10. Chapter 5: Iteration and Randomness
    1. Iteration
      1. Using Iteration to Draw Concentric Circles
      2. while Loops
      3. for Loops
    2. break and continue Statements
    3. Randomness
      1. random() Function
      2. Random Seed
    4. Truchet Tiles
    5. Summary
  11. Chapter 6: Motion and Transformation
    1. Perceiving Motion
    2. Adding Motion to Processing Sketches
      1. The draw() and setup() Functions
      2. Global Variables
      3. Saving Frames
    3. Transformations
      1. Processing Transformation Functions
      2. translate()
      3. rotate()
      4. scale()
      5. shearX() and shearY()
      6. pushMatrix() and popMatrix()
    4. Summary
  12. Chapter 7: Working with Lists and Reading Data
    1. Introducing Lists
      1. Creating and Accessing Lists
      2. Modifying Lists
    2. Combining Loops and Lists
      1. Drawing Shapes by Using a List of Color Values
      2. Looping with enumerate()
    3. Creating Lists of Lists
    4. Reading Data
      1. File Formats
      2. CSV
    5. Summary
  13. Chapter 8: Dictionaries and JSON
    1. Introducing Dictionaries
      1. Accessing Dictionaries
      2. Modifying Dictionaries
    2. Nesting Dictionaries and Lists
    3. Combining Loops and Dictionaries
      1. Iterating Keys
      2. Iterating Values
      3. Iterating Items
    4. Working with JSON
      1. Understanding JSON Syntax
      2. Using Web APIs
      3. Reading in JSON Data
    5. Summary
  14. Chapter 9: Functions and Periodic Motion
    1. Defining Functions
      1. Creating a Simple Speech Bubble Function
      2. Drawing Compound Shapes Using a Function
      3. Adding Arguments and Parameters
      4. Using Keyword Arguments
      5. Setting Default Values
      6. Mixing Positional and Keyword Arguments
      7. Returning Values
    2. Defining Functions for Periodic Motion
      1. Circular and Elliptical Motion
      2. Sine Waves
      3. Lissajous Curves
      4. Creating Screensaver-Like Patterns with Lissajous Curves
    3. Summary
  15. Chapter 10: Object-Oriented Programming and PVector
    1. Working with Classes
      1. Defining a New Class
      2. Creating an Instance from a Class
      3. Adding Attributes to a Class
      4. Adding Methods to a Class
    2. Splitting Your Python Code into Multiple Files
    3. Programming Movement with Vectors
      1. The PVector Class
      2. Moving an Amoeba with PVector
    4. Adding Many Amoebas to the Simulation
    5. Summary
  16. Chapter 11: Mouse and Keyboard Interaction
    1. Mouse Interaction
      1. Mouse Variables
      2. Mouse Events
      3. Creating a Paint App
    2. Keyboard Interaction
      1. Adding Keyboard Shortcuts to the Paint App
    3. Summary
  17. Afterword
    1. More Python for Processing
    2. More Python
    3. Other Creative Coding Environments
  18. Index

Product information

  • Title: Learn Python Visually
  • Author(s): Tristan Bunn
  • Release date: April 2021
  • Publisher(s): No Starch Press
  • ISBN: 9781718500969