Share your repls and programming experiences

← Back to all posts
DRAW with python turtle!
WiNDfaLLx (30)

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...)
https://storage.googleapis.com/replit/images/1536865435321_bd598138637586247b2433a96371534d.pn
https://storage.googleapis.com/replit/images/1536865448102_a542f76811f1df3d35a97ffd613c3e39.pn

Comments
hotnewtop
timmy_i_chen (1166)

That flower is so cool

WiNDfaLLx (30)

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

xXToluwaXx (58)

@WiNDfaLLx did you actually code that flower?

WiNDfaLLx (30)

@xXToluwaXx I drew it using the program :D

The_Emira (1)

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

WiNDfaLLx (30)

@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 :/

AnkurAhir (2)

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

WiNDfaLLx (30)

@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.

AnkurAhir (2)

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

WiNDfaLLx (30)

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

hayaodeh (198)

This is really nice<3

WiNDfaLLx (30)

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

DavynYong (2)

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()

housen (0)

how do you change color?

WiNDfaLLx (30)

@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 ^-^

3DKTH3PR0 (3)

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

WiNDfaLLx (30)

@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 ^-^

WiNDfaLLx (30)

@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! :))

raseekaK (1)

how to run the program

WiNDfaLLx (30)

@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.

rachelweatherall (0)

https://storage.googleapis.com/replit/images/1537345294173_16847063c521903a5b9e0ab0ba1ab3b9.web

WiNDfaLLx (30)

@rachelweatherall That's a pretty lit drawing!

WiNDfaLLx (30)

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

amasad (3404)

@WiNDfaLLx how do you change the colors?

amasad (3404)

@amasad Found the instructions in the console.

WiNDfaLLx (30)

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