DRAW with python turtle!
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
:) it would be cool if there were more then 2 (3?) colours but it's really cool!
@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 :/
Nicely done!
@HoldenKirlan_St Thanks so much!!!
This code was pretty cool. I would like to understand how you did your code. I am pretty recent into coding with Java
@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.
@WiNDfaLLx Thanks for the suggestion. I will use Codeacademy to learn Python. :D
@AnkurAhir :D You're welcome! Good luck!
incredible
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()
how do you change color?
I can't change my color. WHy is that?
@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 Yay! Can I help? :D
@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! :))
how to run the program
@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.
@WiNDfaLLx Thanks a lot :)
This file cannot be displayed: https://storage.googleapis.com/replit/images/1537345294173_16847063c521903a5b9e0ab0ba1ab3b9.web
@rachelweatherall That's a pretty lit drawing!
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
@WiNDfaLLx how do you change the colors?
@WiNDfaLLx super cool btw
That flower is so cool
@timmy_i_chen Thank you! Yeah, I do some digital art in my free time :)
@WiNDfaLLx did you actually code that flower?
@xXToluwaXx I drew it using the program :D