Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- MADE BY ALFONSO PEREZ
- BASIC PAINT LIKE PROGRAM
- FEATURES:
- DRAG the mouse while doing left click to draw
- LEFT CLICK to erase all
- USE THE keys A and S to put the pen up and down
- USE THE keys 1 2 3 4 5 6 7 8 9 to adjust the witdh of line
- CLICK on the colors to change color
- '''
- import turtle
- from turtle import Screen, Turtle
- screen = turtle.Screen()
- screen.title("DRAWING SIMULATOR by Alfonso Perez")
- screen.setup(width=800, height=800)
- t = Turtle("square")
- t.speed(10)
- def dragging(x, y): # These parameters will be the mouse position
- t.ondrag(None)
- t.setheading(t.towards(x, y))
- t.goto(x, y)
- t.ondrag(dragging)
- x = 0
- def diags():
- global x
- x = 1
- def diagg():
- global x
- x = 0
- def up():
- if x == 1:
- t.setheading(135)
- t.forward(141.42)
- else:
- t.setheading(90)
- t.forward(100)
- def down():
- if x == 1:
- t.setheading(315)
- t.forward(141.42)
- else:
- t.setheading(270)
- t.forward(100)
- def left():
- if x == 1:
- t.setheading(225)
- t.forward(141.42)
- else:
- t.setheading(180)
- t.forward(100)
- def right():
- if x == 1:
- t.setheading(45)
- t.forward(141.42)
- else:
- t.setheading(0)
- t.forward(100)
- def clickRight(x, y):
- t.clear()
- def pendown():
- t.pendown
- def penup():
- t.penup()
- def pendown():
- t.pendown()
- '''
- GETS COORDINATES FOR BUTTTONS
- def click(x, y):
- print(x, y)
- '''
- def clicky(x, y):
- if x > 0 and x < 51 and y > 285 and y < 335:
- t.color("red")
- elif x > -50 and x < -1 and y > 285 and y < 335:
- t.color("black")
- elif x > -100 and x < -51 and y > 285 and y < 335:
- t.color("blue")
- elif x > 50 and x < 101 and y > 285 and y < 335:
- t.color("green")
- elif x > -17 and x < 17 and y > -334 and y < -317:
- print(",-..-. .-. .---. _______ ,---. .-. .-. ,--, _______ ,-. .---. .-. .-. .---. ")
- print("|(|| \| | ( .-._)|__ __|| .-.\ | | | |.' .')|__ __||(|/ .-. ) | \| | ( .-._)")
- print("(_)| | | (_) \ )| | | `-'/ | | | || |(_) )| | (_)| | |(_)| | | (_) \ ")
- print("| || |\ | _ \ \ (_) | | ( | | | |\ \ (_) | | || | | | | |\ | _ \ \ ")
- print("| || | |)|( `-' ) | | | |\ \ | `-')| \ `-. | | | |\ `-' / | | |)|( `-' ) ")
- print("`-'/( (_) `----' `-' |_| \)\`---(_) \____\ `-' `-' )---' /( (_) `----' ")
- print(" (__) (__) (_) (__) ")
- print("--------------------------------------------------------------------------")
- print("DRAG THE MOUSE WHILE HOLDING LEFT CLICK TO DRAW")
- print("YOU CAN ERASE THE DRAWN PICTURE BY PRESSING RIGHT CLICK")
- print("BY PRESSING A KEY FROM NUMBERS FROM 1-9, YOU CAN CHANGE THE WIDTH OF LINE")
- print("YOU CAN PUT THE PEN UP BY PRESSING THE A KEY")
- print("YOU CAN PUT IT BACK DOWN BY PRESSING THE S KEY")
- print("BY USING THE ARROW KEYS YOU CAN DRAW STRAIGHT LINES")
- print("YOU CAN DRAW DIAGONALS BY PRESSING THE D KEY THEN THE ARROW KEY")
- print("YOU CAN CHANGE IT BACK BY PRESSING THE F KEY")
- print("BY PRESSING C YOU CAN TO THE CENTER")
- print("BY PRESSING V YOU CAN DRAW A LINE FROM THE POINT YOU ARE IN TO THE CENTER")
- print("YOU CAN CHANGE COLORS BY PRESSING THE BOX WITH THE COLOR YOU WANT FILLED IN\n")
- def width1():
- t.width(1)
- def width2():
- t.width(2)
- def width3():
- t.width(3)
- def width4():
- t.width(4)
- def width5():
- t.width(5)
- def width6():
- t.width(6)
- def width7():
- t.width(7)
- def width8():
- t.width(8)
- def width9():
- t.width(9)
- def center():
- t.penup()
- t.goto(0, 0)
- t.pendown()
- def centerButnoPenUpAndDown():
- t.pendown()
- t.goto(0, 0)
- t.penup()
- def main(): # This will run the program
- #LAYOUT OF HEADER AND BUTTONS
- t1=turtle.Turtle()
- t1.color("black", "red")
- t1.speed(-1)
- t2=turtle.Turtle()
- t2.hideturtle()
- t2.color("black", "black")
- t2.speed(-1)
- t3=turtle.Turtle()
- t3.hideturtle()
- t3.color("black", "blue")
- t3.speed(-1)
- t4=turtle.Turtle()
- t4.hideturtle()
- t4.color("black", "green")
- t4.speed(-1)
- t5=turtle.Turtle()
- t5.hideturtle()
- t5.color("black", "green")
- t5.speed(-1)
- t1.up()
- t1.goto(0,350)
- t1.down()
- t1.write("MADE BY ALFONSO PEREZ",False,"center",font=("Arial Narrow",20,"bold"))
- t1.up()
- t1.goto(0,335)
- t1.down()
- t1.write("SPECIAL FEATURES: press |a| to pen up, press |s| to pen down",False,"center",font=("Arial Narrow",10))
- t1.up()
- t1.goto(0,335)
- t1.down()
- t1.begin_fill()
- t1.forward(50)
- t1.right(90)
- t1.forward(50)
- t1.right(90)
- t1.forward(50)
- t1.right(90)
- t1.forward(50)
- t1.right(90)
- t1.end_fill()
- t2.up()
- t2.goto(0,335)
- t2.down()
- t2.begin_fill()
- t2.backward(50)
- t2.left(90)
- t2.backward(50)
- t2.left(90)
- t2.backward(50)
- t2.left(90)
- t2.backward(50)
- t2.left(90)
- t2.end_fill()
- t3.up()
- t3.goto(0,335)
- t3.down()
- t3.backward(50)
- t3.begin_fill()
- t3.backward(50)
- t3.left(90)
- t3.backward(50)
- t3.left(90)
- t3.backward(50)
- t3.left(90)
- t3.backward(50)
- t3.left(90)
- t3.end_fill()
- t4.up()
- t4.goto(0,335)
- t4.down()
- t4.forward(50)
- t4.begin_fill()
- t4.forward(50)
- t4.right(90)
- t4.forward(50)
- t4.right(90)
- t4.forward(50)
- t4.right(90)
- t4.forward(50)
- t4.right(90)
- t4.end_fill()
- t5.up()
- t5.goto(0,-333)
- t5.down()
- t5.forward(17)
- t5.left(90)
- t5.forward(16)
- t5.left(90)
- t5.forward(34)
- t5.left(90)
- t5.forward(16)
- t5.left(90)
- t5.forward(17)
- t5.up()
- t5.goto(0,-335)
- t5.down()
- t5.write("HELP",False,"center",font=("Arial Narrow",10,"bold"))
- t1.forward(1000)
- t1.right(180)
- t1.forward(2000)
- turtle.onscreenclick(clicky, 1)
- turtle.listen()
- turtle.onkey(up, 'Up')
- turtle.onkey(down, 'Down')
- turtle.onkey(left, 'Left')
- turtle.onkey(right, 'Right')
- turtle.onkey(width1, '1')
- turtle.onkey(width2, '2')
- turtle.onkey(width3, '3')
- turtle.onkey(width4, '4')
- turtle.onkey(width5, '5')
- turtle.onkey(width6, '6')
- turtle.onkey(width7, '7')
- turtle.onkey(width8, '8')
- turtle.onkey(width9, '9')
- turtle.onkey(center, 'c')
- turtle.onkey(centerButnoPenUpAndDown, 'v')
- turtle.onkey(diags, "d")
- turtle.onkey(diagg, "f")
- t.ondrag(dragging) # When we drag the turtle object call dragging
- turtle.onscreenclick(clickRight, 3)
- screen.onkey(penup, "a")
- screen.onkey(pendown, "s")
- screen.mainloop() # This will continue running main()
- main()
- #https://www.youtube.com/channel/UCQor7IURWM-lGT-tmFbFSCw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement