Python Pixel Art
 
Pixel Art in Python - CodeHS Tutorial

๐ŸŽจ Pixel Art in Python

Master the art of creating pixel designs with CodeHS and Python Graphics

๐Ÿงฉ
STEP 1

Open a Python Graphics Program

โ–ผ
1.

Go to CodeHS.com

2.

From your dashboard, click "Sandbox" โ†’ "+ New Program" โ†’ choose Python (Graphics)

3.

Give your program a name like "Pixel Art Project"

๐Ÿช„
STEP 2

Understand the Canvas

โ–ผ
โ€ข

CodeHS graphics uses a grid of pixels that can be colored individually

โ€ข

The command for drawing one pixel is: set_pixel(x, y, color)

set_pixel(x, y, color)
โ€ข

x and y are coordinates on the canvas

โ€ข

color is the color you want (like "red", "blue", "yellow", or a custom RGB value)

๐ŸŽฏ
STEP 3

Choose Your Canvas Size

โ–ผ

You can control how large the art will be by limiting your x and y values.

Example:

width = 20 height = 20

That means your art will fit in a 20 x 20 grid of pixels.

๐Ÿงฑ
STEP 4

Use Loops to Fill Pixels

โ–ผ

You can use nested loops to fill multiple pixels at once.

Example - Make a checkerboard pattern:

for x in range(20): for y in range(20): if (x + y) % 2 == 0: set_pixel(x, y, Color.red) else: set_pixel(x, y, Color.white)
๐ŸŒˆ
STEP 5

Use RGB Colors for Custom Looks

โ–ผ

You can mix your own color by using:

color = Color(r, g, b)

Each value (r, g, b) can be between 0 and 255.

Example:

my_blue = Color(50, 100, 255) set_pixel(5, 5, my_blue)
๐Ÿ–Œ๏ธ
STEP 6

Design Your Pixel Pattern

โ–ผ

You can map out your design first on graph paper or an online pixel grid, then code each pixel.

Example - A small heart:

set_pixel(2, 0, Color.red) set_pixel(3, 0, Color.red) set_pixel(1, 1, Color.red) set_pixel(4, 1, Color.red) set_pixel(0, 2, Color.red) set_pixel(5, 2, Color.red) set_pixel(1, 3, Color.red) set_pixel(4, 3, Color.red) set_pixel(2, 4, Color.red) set_pixel(3, 4, Color.red)
๐Ÿงช
STEP 7

Test, Adjust, and Add Detail

โ–ผ
โ€ข

Run your code often to preview the result

โ€ข

Adjust your x/y positions or colors to improve your design

โ€ข

Add comments to label each section of your art:

# Draw top of heart set_pixel(2, 0, Color.red)
๐Ÿ
STEP 8

Save and Share

โ–ผ
โ€ข

Click "Run" to test your art

โ€ข

Once done, click "Share" โ†’ copy the link

โ€ข

Submit your CodeHS project link to Canvas or your class assignment page

๐Ÿ’ก Bonus Tips

โœ…

Start simple โ€” small icons like hearts, smiley faces, or initials

โšก

Use loops to save time when drawing repeating patterns

๐Ÿ†

Challenge: Use functions to organize your code (e.g., draw_eye(), draw_hat())

Ready to Create? ๐Ÿš€

Head over to CodeHS.com and start building your pixel art masterpiece!

Go to CodeHS
Last updated  2025/10/20 10:01:00 PDTHits  61