Ex
Exerpad
🔥1
10 XP
Lv.1 Beginner

Intro to Pixels

You can create colorful pixel art with Python! Just set a special variable called __grid__ to a list of lists of color names, and you'll see your creation appear as colored pixels.

Your First Grid

Try running this code:

python
__grid__ = [
["red", "blue"],
["green", "yellow"]
]

You should see a 2x2 colored grid appear!

How It Works

__grid__ is a list of rows. Each row is a list of color names. You can use any CSS color name like "red", "blue", "green", "orange", "purple", "black", "white", "pink", "gold", and many more.

You can also use hex colors like "#ff0000" for red or "#00ff00" for green.

Building a Grid with Loops

Instead of typing every color by hand, use loops to build patterns:

python
grid = []
for row in range(5):
line = []
for col in range(5):
if (row + col) % 2 == 0:
line.append("dodgerblue")
else:
line.append("white")
grid.append(line)

__grid__ = grid

Bigger Grids

You can make grids as large as 200x200! Try making a bigger pattern:

python
grid = []
for row in range(20):
line = []
for col in range(20):
if row < 7:
line.append("red")
elif row < 14:
line.append("white")
else:
line.append("green")
grid.append(line)

__grid__ = grid
print("Italian flag!")

Now try the exercises to create your own pixel art!

Exerpad — Learn to Code with Fun!