Skip to content

Repository files navigation

The Nature of Code — pygame Examples

Every example from Daniel Shiffman's The Nature of Code, ported to Python 3.12+ and pygame-ce.

A collage of screenshots from The Nature of Code examples


Why this exists

The book's examples are written in p5.js and Processing. To make it possible for developers more familiar with python, I have translated the examples to pygame-ce. A community fork of the pygame game engine.

The port uses pygames ecosystem, and solves the problems in a pythonic way.

Quick start

You need Python 3.12+ and pygame-ce. The easiest setup uses uv:

git clone https://github.com/Hohnik/noc-examples-pygame.git
cd noc-examples-pygame
uv sync

Then run any example from the repo root:

uv run chapter5/Example_5_11_Flocking/main.py
Without uv (plain pip)
python -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate
pip install pygame-ce noise
python chapter5/Example_5_11_Flocking/main.py

Finding the p5.js original

To compare an example against the book's code, click the example's image or the pink book icon beneath it on natureofcode.com/examples, then choose Open in Web Editor.

The original Processing examples are here, along with ports to other languages.

License

Code is MIT licensed — see LICENSE.

This is a derivative work of The Nature of Code Examples (MIT, © 2014 Daniel Shiffman). The book's text and illustrations are separately licensed (CC BY-NC) and are not included here.

Credits

All of the ideas, and the structure of every example, come from Daniel Shiffman's The Nature of Code. If this repo is useful to you, buy the book and watch The Coding Train.

About

"Nature of Code" examples pygame port

Topics

Resources

Stars

17 stars

Watchers

1 watching

Forks

Sponsor this project

Used by

Contributors

Languages