Draw pixel art with Python

Turn an 8 × 8 grid of numbers into a rocket you can download.

Try the project
An 8 by 8 mint and amber pixel-art rocket.

Give your rocket a palette

Pick a palette and compare the pictures. Every pixel stays in the same place.

Moonlight palette

How numbers become pixels

One row of the pattern00122100
Map a digit2 → window color
Build the image8 rows × 8 pixels

Think in rows.

Each string is one row of the image. There are eight strings, each with eight digits. Position tells Python where the pixel goes.

Look up each color.

The outer loop picks a row. The inner loop looks up a color for each digit. In this drawing, 0 is the background and 2 is the window.

Change color without changing shape.

A new palette gives the same digits new colors. The rows still put each pixel in the same position. Download either version to keep the drawing.

Run the Python version

The full script walks all eight rows and saves a PNG.

row = "00122100"
palette = ["background", "body", "window", "flame"]
for digit in row:
    print(palette[int(digit)])
python3 python-pixel-art.py --palette sunset
Download the Python script ↓

Sources

Make something else in Python