|
| 1 | +import turtle |
| 2 | + |
| 3 | +#Calcula as coordenadas e adiciona à lista points |
| 4 | +#Adds the coordinates to the "points" list |
| 5 | +def point(x,y): |
| 6 | + obj.forward(x*extension) |
| 7 | + obj.left(90) |
| 8 | + obj.forward(y*extension) |
| 9 | + points.append(obj.pos()) |
| 10 | + home(obj,1) |
| 11 | + |
| 12 | +#Returna o objeto ao seu ponto inicial. Se não esta calculando as coordenadas, a linha é marcada |
| 13 | +#Move the object to his initial point. If not calculating coordinates, the turtle line will appear |
| 14 | +def home(obj,isPoint): |
| 15 | + obj.up() |
| 16 | + obj.home() |
| 17 | + obj.goto(ObjectOrigin) |
| 18 | + if not isPoint: |
| 19 | + obj.down() |
| 20 | + |
| 21 | +#Desenha os pontos de espaço extension |
| 22 | +#Here, "obj" does the base of the graphic, using the unit "extension" |
| 23 | +def CreateBase(): |
| 24 | + for length in range(11): |
| 25 | + obj.left(90) |
| 26 | + obj.forward(length*extension) |
| 27 | + obj.stamp() |
| 28 | + obj.write(str(length)) |
| 29 | + home(obj,False) |
| 30 | + obj.forward(length*extension) |
| 31 | + obj.stamp() |
| 32 | + obj.write(str(length)) |
| 33 | + home(obj,False) |
| 34 | + |
| 35 | +#A coordenada inicial do objeto |
| 36 | +#The initial coordinate of the object |
| 37 | +ObjectOrigin = (-100,-100) |
| 38 | + |
| 39 | +#Lista para guardar as coordenadas |
| 40 | +#The coordinates will be saved in this list |
| 41 | +points = [] |
| 42 | + |
| 43 | +#Espaço entre pontos. Unidade de medida |
| 44 | +#Unit of measure. Space between points |
| 45 | +extension = 40 |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +#Pede a função matemática ao usuário. Deve ser inserida utilizando as regras matemáticas de Python. Exemplo: 2*x-7. Somente "x" pode ser usado. |
| 53 | +#Asks the user for the math function. Must be inserted with Python Math Rules. E.g. 2*x-7. Only "x" can be used. |
| 54 | +fx = input("Function: ") |
| 55 | + |
| 56 | +#Tela onde os desenhos serão feitos |
| 57 | +#Screen where the graphic will be constructed |
| 58 | +window = turtle.Screen() |
| 59 | +window.screensize(1000,1000) |
| 60 | + |
| 61 | +#"draw" desenhará a função |
| 62 | +#The "draw" object draws the graphic |
| 63 | +draw = turtle.Turtle() |
| 64 | +home(draw,0) |
| 65 | +draw.hideturtle() |
| 66 | +draw.speed(0) |
| 67 | + |
| 68 | +#obj será usado para calcular as coordenadas e desenhar a base do gráfico |
| 69 | +#The "obj" object calculates the coordinates. Also, draws a basic graphic structure |
| 70 | +obj = turtle.Turtle() |
| 71 | +home(obj,0) |
| 72 | +obj.speed(0) |
| 73 | + |
| 74 | +CreateBase() |
| 75 | + |
| 76 | +#"obj" e "draw" param de marcar suas trajetórias na tela |
| 77 | +#No more lines of "obj" or "draw" will be seen in the screen |
| 78 | +obj.up() |
| 79 | +draw.up() |
| 80 | + |
| 81 | +#Chama "point" para calcular as coordenadas e move "draw" para elas |
| 82 | +#Calls the "point" function to get the coordinates and, after that, moves "draw" to them |
| 83 | +for x in range(-5,10): |
| 84 | + y = eval(fx) |
| 85 | + point(x,y) |
| 86 | + draw.goto(points[x+5]) |
| 87 | + draw.down() |
| 88 | + |
| 89 | +#Espera o usuário clicar para fechar a tela |
| 90 | +#If the user click on the screen here, the program will finish the execution |
| 91 | +window.exitonclick() |
0 commit comments