Skip to content
← Back to Community
DRAW with python turtle!
Profile icon
WiNDfaLLx

I managed to program a basic drawing app using only the python turtle module! It was pretty fun to code. I attached some drawings I made ^-^

EDIT: WOW I'M IN THE NEWSLETTER!? I'm honoured! (https://replit-newsletter-16--timmy-i-chen.repl.co/?ref=newsletter)
I'm working on a couple games, so watch out! (Although they probably won't be done soon, because it's GCSE year, ugh...)
This file cannot be displayed: https://storage.googleapis.com/replit/images/1536865435321_bd598138637586247b2433a96371534d.pn
This file cannot be displayed: https://storage.googleapis.com/replit/images/1536865448102_a542f76811f1df3d35a97ffd613c3e39.pn

Voters
Profile icon
16Luong-QuynhQu
Profile icon
kristiandzn
Profile icon
DanyalALI3
Profile icon
NiaRubio
Profile icon
CorruptedIphone
Profile icon
NidhiVenugopal
Profile icon
XSK8
Profile icon
as18go
Profile icon
forceofyoda
Profile icon
TomsTrahovcevs
Comments
hotnewtop
Profile icon
timmy_i_chen

That flower is so cool

Profile icon
WiNDfaLLx

@timmy_i_chen Thank you! Yeah, I do some digital art in my free time :)

Profile icon
xXToluwaXx

@WiNDfaLLx did you actually code that flower?

Profile icon
WiNDfaLLx

@xXToluwaXx I drew it using the program :D

Profile icon
The_Emira

:) it would be cool if there were more then 2 (3?) colours but it's really cool!

Profile icon
WiNDfaLLx

@The_Emira Thanks so much! And you can change the colours by pressing X. There are instructions in the console. You need to put it into a weird box thing because for some reason the input module doesn't work, it refreshes the screen before the colour is saved for some reason :/

Profile icon
HoldenKirlan_St

Nicely done!

Profile icon
WiNDfaLLx

@HoldenKirlan_St Thanks so much!!!

Profile icon
AnkurAhir

This code was pretty cool. I would like to understand how you did your code. I am pretty recent into coding with Java

Profile icon
WiNDfaLLx

@AnkurAhir Thank you! I am self-taught and used a website called Codecademy to learn Python. I then read through the Python Turtle documentation for some interesting functions (the screen.onkey ones let you use keys!) and implemented them into my code. So yeah. Highly recommend Codecademy.

Profile icon
AnkurAhir

@WiNDfaLLx Thanks for the suggestion. I will use Codeacademy to learn Python. :D

Profile icon
WiNDfaLLx

@AnkurAhir :D You're welcome! Good luck!

Profile icon
hayaodeh

This is really nice<3

Profile icon
WiNDfaLLx

@hayaodeh Thank you! This means a lot, it's my first post ^u^

Profile icon
FortniteMincera

incredible

Profile icon
DavynYong

import turtle
t = turtle.Turtle()
y = turtle.Turtle()
t.penup
y.penup()
tsize = 10
screen = turtle.Screen()
t.speed("fastest")
t.color("black")
tcolour = (0,0,0)
t.pensize(10)
y.speed("fastest")
y.color("black")
t.goto(0,0)
y.goto(200,-200)
t.clear()
t.shape("triangle")
y.hideturtle()
y.pendown()
y.dot(5)

def colourset():
colour = input("Input colour string (DON'T TYPE IT HERE!) \n")
print(colour)
global tcolour
tcolour = (int(colour[0:3]), int(colour[3:6]), int(colour[6:9]))
t.color(tcolour)
y.color(tcolour)
y.dot(t.pensize()/2)

def peninc():
tsize = t.pensize() + 2
t.pensize(tsize)
y.clear()
y.dot(tsize/2)
def pendec():
tsize = t.pensize() - 2
t.pensize(tsize)
y.clear()
y.dot(tsize/2)

def black():
global tcolour
tcolour = (0,0,0)
t.color(tcolour)
y.color(tcolour)
y.dot(t.pensize()/2)
def jade():
global tcolour
tcolour = (0,255,200)
t.color(tcolour)
y.color(tcolour)
y.dot(t.pensize()/2)
def white():
global tcolour
tcolour = (255,255,255)
t.color(tcolour)
y.color(tcolour)
y.dot(t.pensize()/2)

def tclick(x,y):
t.penup()
t.goto(x,y)
#t.color(230,230,230)
#y.pencolor(230,230,230)
#y.clear()
y.dot(10)
t.pendown()
def tdrag(x,y):
global tcolour
t.pendown()
t.goto(x,y)
t.color(tcolour)
y.clear()
y.color(tcolour)
y.dot(tsize)

screen.onkey(peninc, "Right")
screen.onkey(pendec, "Left")
screen.onkey(t.clear, "space")
screen.onkey(black, "1")
screen.onkey(jade, "2")
screen.onkey(white, "3")
screen.onkey(colourset, "x")
t.ondrag(tdrag)
screen.onclick(tclick)

print("""Hey you! You're obviously really bored, since you're running my slightly trashy, slightly unfinished drawing program. (It's probably a rival to MS Paint though.)

Here are the controls:
Click to move the pen, click and drag to draw. Yes, click twice. Deal with it.
The left and right arrows decrease and increase pen size, respectively.
Space clears the canvas.
Pressing X lets you change the pen colour by inputting a colour string.
Quick colour shortcuts: 1-Black, 2-Jade, 3-White (eraser).
I have no idea how to program a 'save' so just screenshot the result.

A NOTE ON COLOUR STRINGS:
First, input them CORRECTLY. RRRGGGBBB, no spaces, no letters, no values over 255. I didn't bother babyproofing this, as common sense exists.
Second, DON'T TYPE THEM IN HERE. The enter key causes the program to refresh, clearing the input in the process. See that little arrow/box icon in the corner? Click it and type the colour string there instead, then hit the enter button. (Ignore the error message, the color would have changed on the 'result'.) I don't know why, but it works.""")

screen.listen()

Profile icon
WiNDfaLLx
Profile icon
housen

how do you change color?

Profile icon
WiNDfaLLx

@housen you can type 1, 2 or 3! there's also a colour input system I wrote about in the instruction comment in the code, but there was an update to repl's interface which might've broken it... oh well. the code is over 2 years old so I might just remake it from scratch ^-^

Profile icon
3DKTH3PR0

I can't change my color. WHy is that?

Profile icon
WiNDfaLLx

@3DKTH3PR0 I think there was an update which might've broken the input system... oh well. the code is over 2 years old so I might just remake it from scratch ^-^

Profile icon
3DKTH3PR0

@WiNDfaLLx Yay! Can I help? :D

Profile icon
WiNDfaLLx

@3DKTH3PR0 sure! or you can just copy all the code or "fork" the repl and use it for your own projects, I don't mind! :))

Profile icon
raseekaK

how to run the program

Profile icon
WiNDfaLLx

@raseekaK click 'open' in the embedded repl box thing at the bottom (or go here https://repl.it/@WiNDfaLLx/turtle-art-SMOOTHER-NO-SAVE), then click the big green 'run' button.

Profile icon
raseekaK

@WiNDfaLLx Thanks a lot :)

Profile icon
WiNDfaLLx

@raseekaK no problem! ^-^

Profile icon
rachelweatherall

This file cannot be displayed: https://storage.googleapis.com/replit/images/1537345294173_16847063c521903a5b9e0ab0ba1ab3b9.web

Profile icon
WiNDfaLLx

@rachelweatherall That's a pretty lit drawing!

Profile icon
WiNDfaLLx

Please let me know if you catch any bugs! I know you almost always have to click the pen twice to draw, this was inevitable since otherwise the pen won't move from place to place :O

Profile icon
amasad

@WiNDfaLLx how do you change the colors?

Profile icon
amasad

@WiNDfaLLx super cool btw

Profile icon
amasad

@amasad Found the instructions in the console.

Profile icon
WiNDfaLLx

@amasad Thank you very much! Yeah, the instructions should pretty much cover it all. :D