Advertisement
AlfonsoPEREZ

DRAWING SIMULATOR

Apr 16th, 2020
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.04 KB | None | 0 0
  1. '''
  2. MADE BY ALFONSO PEREZ
  3.  
  4. BASIC PAINT LIKE PROGRAM
  5.  
  6. FEATURES:
  7. DRAG the mouse while doing left click to draw
  8. LEFT CLICK to erase all
  9. USE THE keys A and S to put the pen up and down
  10. USE THE keys 1 2 3 4 5 6 7 8 9 to adjust the witdh of line
  11. CLICK on the colors to change color
  12.  
  13. '''
  14. import turtle
  15. from turtle import Screen, Turtle
  16.  
  17. screen = turtle.Screen()
  18. screen.title("DRAWING SIMULATOR by Alfonso Perez")
  19. screen.setup(width=800, height=800)
  20.  
  21. t = Turtle("square")
  22. t.speed(10)
  23. def dragging(x, y):  # These parameters will be the mouse position
  24.     t.ondrag(None)
  25.     t.setheading(t.towards(x, y))
  26.     t.goto(x, y)
  27.     t.ondrag(dragging)
  28.  
  29. x = 0
  30.  
  31. def diags():
  32.     global x
  33.     x = 1
  34.  
  35. def diagg():
  36.     global x
  37.     x = 0
  38.  
  39.  
  40. def up():
  41.     if x == 1:
  42.         t.setheading(135)
  43.         t.forward(141.42)
  44.     else:
  45.         t.setheading(90)
  46.         t.forward(100)
  47.      
  48. def down():
  49.     if x == 1:
  50.         t.setheading(315)
  51.         t.forward(141.42)
  52.     else:
  53.         t.setheading(270)
  54.         t.forward(100)
  55.  
  56. def left():
  57.     if x == 1:
  58.         t.setheading(225)
  59.         t.forward(141.42)
  60.     else:
  61.         t.setheading(180)
  62.         t.forward(100)
  63.  
  64. def right():
  65.     if x == 1:
  66.         t.setheading(45)
  67.         t.forward(141.42)
  68.     else:
  69.         t.setheading(0)
  70.         t.forward(100)
  71.  
  72. def clickRight(x, y):
  73.     t.clear()
  74.  
  75. def pendown():
  76.     t.pendown
  77.  
  78.  
  79. def penup():
  80.     t.penup()
  81.  
  82. def pendown():
  83.     t.pendown()
  84. '''
  85. GETS COORDINATES FOR BUTTTONS
  86. def click(x, y):
  87.    print(x, y)
  88. '''
  89. def clicky(x, y):  
  90.     if x > 0 and x < 51 and y > 285 and y < 335:
  91.         t.color("red")
  92.     elif x > -50 and x < -1 and y > 285 and y < 335:
  93.         t.color("black")
  94.     elif x > -100 and x < -51 and y > 285 and y < 335:
  95.         t.color("blue")
  96.     elif x > 50 and x < 101 and y > 285 and y < 335:
  97.         t.color("green")
  98.     elif x > -17 and x < 17 and y > -334 and y < -317:
  99.         print(",-..-. .-.   .---.  _______ ,---.  .-. .-.  ,--, _______ ,-. .---.  .-. .-.   .---. ")
  100.         print("|(||  \| |  ( .-._)|__   __|| .-.\ | | | |.' .')|__   __||(|/ .-. ) |  \| |  ( .-._)")
  101.         print("(_)|   | | (_) \    )| |   | `-'/ | | | ||  |(_) )| |   (_)| | |(_)|   | | (_) \  ")
  102.         print("| || |\ | _  \ \  (_) |   |   (  | | | |\ \  (_) |   | || | | | | |\ | _  \ \ ")
  103.         print("| || | |)|( `-'  )    | |   | |\ \ | `-')| \ `-.  | |   | |\ `-' / | | |)|( `-'  ) ")
  104.         print("`-'/(  (_) `----'     `-'   |_| \)\`---(_)  \____\ `-'   `-' )---'  /(  (_) `----'  ")
  105.         print("  (__)                          (__)                        (_)    (__)             ")
  106.              
  107.         print("--------------------------------------------------------------------------")
  108.         print("DRAG THE MOUSE WHILE HOLDING LEFT CLICK TO DRAW")
  109.         print("YOU CAN ERASE THE DRAWN PICTURE BY PRESSING RIGHT CLICK")
  110.         print("BY PRESSING A KEY FROM NUMBERS FROM 1-9, YOU CAN CHANGE THE WIDTH OF LINE")
  111.         print("YOU CAN PUT THE PEN UP BY PRESSING THE A KEY")
  112.         print("YOU CAN PUT IT BACK DOWN BY PRESSING THE S KEY")
  113.         print("BY USING THE ARROW KEYS YOU CAN DRAW STRAIGHT LINES")
  114.         print("YOU CAN DRAW DIAGONALS BY PRESSING THE D KEY THEN THE ARROW KEY")
  115.         print("YOU CAN CHANGE IT BACK BY PRESSING THE F KEY")
  116.         print("BY PRESSING C YOU CAN TO THE CENTER")
  117.         print("BY PRESSING V YOU CAN DRAW A LINE FROM THE POINT YOU ARE IN TO THE CENTER")
  118.         print("YOU CAN CHANGE COLORS BY PRESSING THE BOX WITH THE COLOR YOU WANT FILLED IN\n")
  119. def width1():
  120.     t.width(1)
  121.  
  122. def width2():
  123.     t.width(2)
  124.  
  125. def width3():
  126.     t.width(3)
  127.  
  128. def width4():
  129.     t.width(4)
  130.  
  131. def width5():
  132.     t.width(5)
  133.  
  134. def width6():
  135.     t.width(6)
  136.  
  137. def width7():
  138.     t.width(7)
  139.  
  140. def width8():
  141.     t.width(8)
  142.  
  143. def width9():
  144.     t.width(9)
  145.  
  146. def center():
  147.     t.penup()
  148.     t.goto(0, 0)
  149.     t.pendown()
  150.  
  151. def centerButnoPenUpAndDown():
  152.     t.pendown()
  153.     t.goto(0, 0)
  154.     t.penup()
  155.  
  156. def main():  # This will run the program
  157.     #LAYOUT OF HEADER AND BUTTONS
  158.     t1=turtle.Turtle()
  159.     t1.color("black", "red")
  160.     t1.speed(-1)
  161.    
  162.     t2=turtle.Turtle()
  163.     t2.hideturtle()
  164.     t2.color("black", "black")
  165.     t2.speed(-1)
  166.    
  167.     t3=turtle.Turtle()
  168.     t3.hideturtle()
  169.     t3.color("black", "blue")
  170.     t3.speed(-1)
  171.    
  172.     t4=turtle.Turtle()
  173.     t4.hideturtle()
  174.     t4.color("black", "green")
  175.     t4.speed(-1)
  176.  
  177.     t5=turtle.Turtle()
  178.     t5.hideturtle()
  179.     t5.color("black", "green")
  180.     t5.speed(-1)
  181.    
  182.     t1.up()
  183.     t1.goto(0,350)
  184.     t1.down()
  185.     t1.write("MADE BY ALFONSO PEREZ",False,"center",font=("Arial Narrow",20,"bold"))
  186.     t1.up()
  187.     t1.goto(0,335)
  188.     t1.down()
  189.     t1.write("SPECIAL FEATURES: press |a| to pen up, press |s| to pen down",False,"center",font=("Arial Narrow",10))
  190.    
  191.     t1.up()
  192.     t1.goto(0,335)
  193.     t1.down()
  194.     t1.begin_fill()
  195.     t1.forward(50)
  196.     t1.right(90)
  197.     t1.forward(50)
  198.     t1.right(90)
  199.     t1.forward(50)
  200.     t1.right(90)
  201.     t1.forward(50)
  202.     t1.right(90)
  203.     t1.end_fill()
  204.    
  205.     t2.up()
  206.     t2.goto(0,335)
  207.     t2.down()
  208.     t2.begin_fill()
  209.     t2.backward(50)
  210.     t2.left(90)
  211.     t2.backward(50)
  212.     t2.left(90)
  213.     t2.backward(50)
  214.     t2.left(90)
  215.     t2.backward(50)
  216.     t2.left(90)
  217.     t2.end_fill()
  218.  
  219.     t3.up()
  220.     t3.goto(0,335)
  221.     t3.down()
  222.     t3.backward(50)
  223.     t3.begin_fill()
  224.     t3.backward(50)
  225.     t3.left(90)
  226.     t3.backward(50)
  227.     t3.left(90)
  228.     t3.backward(50)
  229.     t3.left(90)
  230.     t3.backward(50)
  231.     t3.left(90)
  232.     t3.end_fill()
  233.  
  234.     t4.up()
  235.     t4.goto(0,335)
  236.     t4.down()
  237.     t4.forward(50)
  238.     t4.begin_fill()
  239.     t4.forward(50)
  240.     t4.right(90)
  241.     t4.forward(50)
  242.     t4.right(90)
  243.     t4.forward(50)
  244.     t4.right(90)
  245.     t4.forward(50)
  246.     t4.right(90)
  247.     t4.end_fill()
  248.  
  249.     t5.up()
  250.     t5.goto(0,-333)
  251.     t5.down()
  252.    
  253.     t5.forward(17)
  254.     t5.left(90)
  255.     t5.forward(16)
  256.     t5.left(90)
  257.     t5.forward(34)
  258.     t5.left(90)
  259.     t5.forward(16)
  260.     t5.left(90)
  261.     t5.forward(17)
  262.    
  263.     t5.up()
  264.     t5.goto(0,-335)
  265.     t5.down()
  266.     t5.write("HELP",False,"center",font=("Arial Narrow",10,"bold"))
  267.    
  268.    
  269.     t1.forward(1000)
  270.     t1.right(180)
  271.     t1.forward(2000)
  272.  
  273.     turtle.onscreenclick(clicky, 1)
  274.     turtle.listen()
  275.    
  276.     turtle.onkey(up, 'Up')
  277.     turtle.onkey(down, 'Down')
  278.     turtle.onkey(left, 'Left')
  279.     turtle.onkey(right, 'Right')
  280.    
  281.     turtle.onkey(width1, '1')
  282.     turtle.onkey(width2, '2')
  283.     turtle.onkey(width3, '3')
  284.     turtle.onkey(width4, '4')
  285.     turtle.onkey(width5, '5')
  286.     turtle.onkey(width6, '6')
  287.     turtle.onkey(width7, '7')
  288.     turtle.onkey(width8, '8')
  289.     turtle.onkey(width9, '9')
  290.  
  291.     turtle.onkey(center, 'c')
  292.     turtle.onkey(centerButnoPenUpAndDown, 'v')
  293.  
  294.     turtle.onkey(diags, "d")
  295.     turtle.onkey(diagg, "f")
  296.    
  297.     t.ondrag(dragging)  # When we drag the turtle object call dragging
  298.     turtle.onscreenclick(clickRight, 3)
  299.     screen.onkey(penup, "a")
  300.     screen.onkey(pendown, "s")
  301.     screen.mainloop()  # This will continue running main()
  302.  
  303. main()
  304. #https://www.youtube.com/channel/UCQor7IURWM-lGT-tmFbFSCw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement