-
Notifications
You must be signed in to change notification settings - Fork 1
/
paint.py
117 lines (90 loc) · 2.61 KB
/
paint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""Paint, for drawing shapes.
Exercises
1. Add a color.
2. Complete circle.
3. Complete rectangle.
4. Complete triangle.
5. Add width parameter.
"""
#importa las librerias
from turtle import *
from freegames import vector
#dibuja una linea desde el primer punto hasta el segundo y ahi se queda.
def line(start, end):
"""Draw line from start to end."""
up()
goto(start.x, start.y)
down()
goto(end.x, end.y)
#dibuja un cuadrado desde el punto inicial y con un for loop gira a la izquierda y dibuja una linea
def square(start, end):
"""Draw square from start to end."""
up()
goto(start.x, start.y)
down()
begin_fill()
for count in range(4):
forward(end.x - start.x)
left(90)
end_fill()
def draw_circle(start, end):
"""Draw circle from start to end."""
up()
goto(start.x, start.y)
down()
begin_fill()
circle(end.x-start.x)
end_fill()
def rectangle(start, end):# Aqui estamos haciendo rectangle donde usamos un for loop para para hacer el dibujo desde start y moving left 90 angulo y eso repite hasta llegar el end
"""Draw rectangle from start to end."""
up()
goto(start.x, start.y)
down()
begin_fill()
for count in range(2):
forward(end.x - start.x)
left(90)
forward((end.x - start.x)/2)
left(90)
end_fill()
def triangle(start, end): #Aqui es Traingle usamos un for loop in count range of 2 y desde start moving to left 110 angulo hasta llegar end.
"""Draw triangle from start to end."""
up()
goto(start.x, start.y)
down()
begin_fill()
for count in range(2):
forward(end.x - start.x)
left(110)
end_fill()
def tap(x, y):
"""Store starting point or draw shape."""
start = state['start']
if start is None:
state['start'] = vector(x, y)
else:
shape = state['shape']
end = vector(x, y)
shape(start, end)
state['start'] = None
def store(key, value):
"""Store value in state at key."""
state[key] = value
state = {'start': None, 'shape': line}
setup(420, 420, 370, 0)
onscreenclick(tap)
listen()
onkey(undo, 'u')
onkey(lambda: color('black'), 'K')
onkey(lambda: color('yellow'), 'Y')
onkey(lambda: color('purple'), 'P')
onkey(lambda: color('white'), 'W')
onkey(lambda: color('green'), 'G')
onkey(lambda: color('blue'), 'B')
onkey(lambda: color('red'), 'R')
onkey(lambda: store('shape', line), 'l')
onkey(lambda: store('shape', square), 's')
onkey(lambda: store('shape', draw_circle), 'c')
onkey(lambda: store('shape', rectangle), 'r')
onkey(lambda: store('shape', triangle), 't')
done()