|
| 1 | +import turtle |
| 2 | + |
| 3 | +turtle.setup(600,600) |
| 4 | + |
| 5 | +t = turtle.Pen() |
| 6 | + |
| 7 | +t.hideturtle() |
| 8 | + |
| 9 | +def pedirNumeroEntero(): |
| 10 | + |
| 11 | + correcto=False |
| 12 | + num=0 |
| 13 | + while(not correcto): |
| 14 | + try: |
| 15 | + num = int(input("")) |
| 16 | + correcto=True |
| 17 | + except ValueError: |
| 18 | + print('Error, introduce un numero entero') |
| 19 | + |
| 20 | + return num |
| 21 | + |
| 22 | +salir = False |
| 23 | +opcion = 0 |
| 24 | + |
| 25 | +while not salir: |
| 26 | + |
| 27 | + print ("1. Opcion 1 Traslación") |
| 28 | + print ("2. Opcion 2 Rotación") |
| 29 | + print ("3. Opcion 3 Escalamiento") |
| 30 | + print ("4. Salir") |
| 31 | + |
| 32 | + print ("Elige una opcion") |
| 33 | + |
| 34 | + opcion = pedirNumeroEntero() |
| 35 | + t.clear() |
| 36 | + if opcion == 1: |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + print ("1.- Una línea") |
| 41 | + print ("2.- Un cuadrado") |
| 42 | + |
| 43 | + opciones = pedirNumeroEntero() |
| 44 | + t.clear() |
| 45 | + if opciones == 1: |
| 46 | + print("Linea") |
| 47 | + longitud = int(input("Longitud de la linea ")) |
| 48 | + |
| 49 | + t.forward(longitud) |
| 50 | + x = int(input("Cambio en X ")) |
| 51 | + y = int(input("Cambio en Y ")) |
| 52 | + t.penup() |
| 53 | + t.goto(x,y) |
| 54 | + t.pendown() |
| 55 | + t.color(0,0,1) |
| 56 | + t.forward(longitud) |
| 57 | + t.penup() |
| 58 | + t.goto(0,0) |
| 59 | + t.pendown() |
| 60 | + t.color(0,0,0) |
| 61 | + if opciones == 2: |
| 62 | + print("Cuadrado") |
| 63 | + longitudC = int(input("Longitud del cuadrado")) |
| 64 | + t.forward(longitudC) |
| 65 | + t.left(90) |
| 66 | + t.forward(longitudC) |
| 67 | + t.left(90) |
| 68 | + t.forward(longitudC) |
| 69 | + t.left(90) |
| 70 | + t.forward(longitudC) |
| 71 | + xC = int(input("Cambio en X ")) |
| 72 | + yC = int(input("Cambio en Y ")) |
| 73 | + t.penup() |
| 74 | + t.goto(xC,yC) |
| 75 | + t.pendown() |
| 76 | + t.color(0,0,1) |
| 77 | + t.backward(longitudC) |
| 78 | + t.right(90) |
| 79 | + t.backward(longitudC) |
| 80 | + t.right(90) |
| 81 | + t.backward(longitudC) |
| 82 | + t.right(90) |
| 83 | + t.backward(longitudC) |
| 84 | + t.penup() |
| 85 | + t.goto(0,0) |
| 86 | + t.pendown() |
| 87 | + t.color(0,0,0) |
| 88 | + |
| 89 | + print ("") |
| 90 | + elif opcion == 2: |
| 91 | + print ("1.- Una línea") |
| 92 | + print ("2.- Un cuadrado") |
| 93 | + opciones2 = pedirNumeroEntero() |
| 94 | + t.clear() |
| 95 | + |
| 96 | + if opciones2 == 1: |
| 97 | + print("Linea") |
| 98 | + longitud = int(input("Longitud de la linea ")) |
| 99 | + |
| 100 | + t.forward(longitud) |
| 101 | + Rotar = int(input("Rotación de grados: ")) |
| 102 | + t.penup() |
| 103 | + t.goto(0,0) |
| 104 | + t.left(Rotar) |
| 105 | + t.color(1,0,1) |
| 106 | + t.pendown() |
| 107 | + t.forward(longitud) |
| 108 | + t.penup() |
| 109 | + t.right(Rotar) |
| 110 | + t.goto(0,0) |
| 111 | + t.pendown() |
| 112 | + t.color(0,0,0) |
| 113 | + |
| 114 | + if opciones2 == 2: |
| 115 | + print("Cuadrado") |
| 116 | + longitudC = int(input("Longitud del cuadrado")) |
| 117 | + t.forward(longitudC) |
| 118 | + t.left(90) |
| 119 | + t.forward(longitudC) |
| 120 | + t.left(90) |
| 121 | + t.forward(longitudC) |
| 122 | + t.left(90) |
| 123 | + t.forward(longitudC) |
| 124 | + RotarC = int(input("Rotación de grados: ")) |
| 125 | + t.penup() |
| 126 | + t.goto(0,0) |
| 127 | + t.left(RotarC) |
| 128 | + t.color(1,0,1) |
| 129 | + t.pendown() |
| 130 | + t.backward(longitudC) |
| 131 | + t.right(90) |
| 132 | + t.backward(longitudC) |
| 133 | + t.right(90) |
| 134 | + t.backward(longitudC) |
| 135 | + t.right(90) |
| 136 | + t.backward(longitudC) |
| 137 | + t.penup() |
| 138 | + t.right(RotarC) |
| 139 | + t.goto(0,0) |
| 140 | + t.pendown() |
| 141 | + t.color(0,0,0) |
| 142 | + print ("") |
| 143 | + |
| 144 | + elif opcion == 3: |
| 145 | + print ("1.- Una línea") |
| 146 | + print ("2.- Un cuadrado") |
| 147 | + opciones3 = pedirNumeroEntero() |
| 148 | + t.clear() |
| 149 | + |
| 150 | + if opciones3 == 1: |
| 151 | + print("Linea") |
| 152 | + longitud = float(input("Longitud de la linea ")) |
| 153 | + |
| 154 | + t.forward(longitud) |
| 155 | + Escala = float(input("Cambio de escala ")) |
| 156 | + t.penup() |
| 157 | + t.goto(0,0) |
| 158 | + t.pendown() |
| 159 | + t.color(1,0,0) |
| 160 | + t.forward(longitud*Escala) |
| 161 | + t.penup() |
| 162 | + t.goto(0,0) |
| 163 | + t.pendown() |
| 164 | + t.color(0,0,0) |
| 165 | + |
| 166 | + if opciones3 == 2: |
| 167 | + print("Cuadrado") |
| 168 | + longitudC = int(input("Longitud del cuadrado")) |
| 169 | + t.forward(longitudC) |
| 170 | + t.left(90) |
| 171 | + t.forward(longitudC) |
| 172 | + t.left(90) |
| 173 | + t.forward(longitudC) |
| 174 | + t.left(90) |
| 175 | + t.forward(longitudC) |
| 176 | + EscalaC = float(input("Cambio de escala ")) |
| 177 | + t.penup() |
| 178 | + t.goto(0,0) |
| 179 | + t.color(1,0,0) |
| 180 | + t.pendown() |
| 181 | + t.backward(longitudC*EscalaC) |
| 182 | + t.right(90) |
| 183 | + t.backward(longitudC*EscalaC) |
| 184 | + t.right(90) |
| 185 | + t.backward(longitudC*EscalaC) |
| 186 | + t.right(90) |
| 187 | + t.backward(longitudC*EscalaC) |
| 188 | + t.penup() |
| 189 | + t.goto(0,0) |
| 190 | + t.pendown() |
| 191 | + t.color(0,0,0) |
| 192 | + print ("") |
| 193 | + elif opcion == 4: |
| 194 | + salir = True |
| 195 | + else: |
| 196 | + print ("Introduce un numero entre 1 y 3") |
| 197 | + |
| 198 | +print ("Fin") |
0 commit comments