Learn to Code via Tutorials on Repl.it!

← Back to all posts
How to draw Pixel Art on Python with Turtle!
John_WardWard (364)

How to Draw Pixel Art on Python with Turtle!

In this Tutorial you shall learn how to create your own pixel art on Python with Turtle, I hope you enjoy.

The first step to creating our art is to import turtle and set a background. My personal tip is to use black as it works best with pixel art.

Here is model code:

import turtle
t=turtle.Turtle()
wn=turtle.Screen()
wn.bgcolor("Black")                     #Remember Speech Marks.

Then, for step 2, we will set the speed of your turtle to be a high value, using this command:
t.speed(0)
Then, now the technical aspects are over with, let us get into the real juicy code!

First, we must define square. My optimum size after a lot of testing was a 20 by 20 square. You define a function using this piece of code:

def square():
       for x in range(4):
             t.forward(20)
             t.right(90)                                              #Remember Indentation.

Then, After that step, we can start making pixel art!
To add colours to our squares, we use the begin_fill command. Let me show an example about how this works.

def Tetris_Piece_1():
  for x in range(4):
      t.begin_fill()
      square()
      t.color("Blue")
      t.end_fill()
      t.color("Black")
      t.forward(20)

We created this function. Now we may uses it whenever we like with this command:
Tetris_Piece_1().
This code will make a Horizontal line of 4 pixels, like the Tetris piece! Look at the example below to see Pac-Man also.

You've come to the end of the Tutorial. However, if you would like to extend this, here are some ideas.

Find a way to define Red_Square or Blue_Square.

Make a video-game character.

Create a model of a Tetris screen.

It has lots of uses, so try it today.

Remember to click on Python with Turtle and not python 2.7, Python or Django.

I recommend you watch the example in larger screen by pressing Open in Repl.it.

Special Credit to JSer for teaching me how to use markdown on this post!

Up the pensize to 4 if you want it really blocky using this command!
t.pensize(4)

Comments
hotnewtop
ChloeDaulby (2)

Hey everyone I am new to pixel art but I am very excited to try something different in my retirement.

Gegette (1)

pas fou fou ceci

JannisFreund (1)

it's nice to see that some people come up with the same idea i had. i did mine a bit differently though... but still very nice! :)

itspranshu (1)

Good Job John! Nice, People will like it very much👍

LitteJohn (6)

That is a nice drawing I will use for something as wee thank you so much!!!

Renise (15)

That is amazinggg

MOULYANAGARAJNA (1)

thanks for this I got a better idea how to draw\

[deleted]

Cool Beans!
Nice job!!

stubaduble (15)

@John_WardWard
how do you make the block appear?

Cookiezz (65)

@stubaduble He defined a "Tetris Piece". He then executes the command to draw the "Tetris Piece". Code to the "Tetris Piece":

def Tetris_Piece_1()
  for x in range(4):
      t.begin_fill()
      square()
      t.color("Blue")
      t.end_fill()
      t.color("Black")
      t.forward(20)

To execute the command, he writes Tetris_Piece_1() in his code.

stubaduble (15)

This does not work for me..

Wilke000 (625)

Wow, @John_WardWard, you did a great job!

bananajoe3 (0)

that was really cool! thanks

JellyBean85 (0)

omg. john the bomb