01.
import
turtle
02.
03.
def
pir_quadrados(n,posx, posy,lado):
04.
for
i
in
range(
1
,n
+
1
):
05.
# desenha linha i
06.
# posiciona
07.
turtle.penup()
08.
turtle.setx(posx
+
(n
-
i)
*
lado
/
2
)
09.
turtle.pendown()
10.
# desenha
11.
for
j
in
range(
1
,i
+
1
):
12.
quadrado(turtle.xcor(),turtle.ycor(), lado)
13.
turtle.setx(turtle.xcor()
+
lado)
14.
# muda de linha
15.
turtle.penup()
16.
turtle.goto(posx,turtle.ycor()
-
lado)
17.
turtle.pendown()
18.
turtle.hideturtle()
19.
20.
def
quadrado(posx, posy,lado):
21.
turtle.showturtle()
22.
# posicioan
23.
turtle.penup()
24.
turtle.goto(posx, posy)
25.
turtle.pendown()
26.
# desenha
27.
for
i
in
range(
4
):
28.
turtle.forward(lado)
29.
turtle.left(
90
)
30.
turtle.hideturtle()
01.
def
pir_quadrados_inv(n,posx, posy,lado):
02.
for
i
in
range(n,
0
,
-
1
):
# <-- só alterámos aqui!!
03.
# desenha linha i
04.
# posiciona
05.
turtle.penup()
06.
turtle.setx(posx
+
(n
-
i)
*
lado
/
2
)
07.
turtle.pendown()
08.
# desenha
09.
for
j
in
range(
1
,i
+
1
):
10.
quadrado(turtle.xcor(),turtle.ycor(), lado)
11.
turtle.setx(turtle.xcor()
+
lado)
12.
# muda de linha
13.
turtle.penup()
14.
turtle.goto(posx,turtle.ycor()
-
lado)
15.
turtle.pendown()
16.
turtle.hideturtle()
01.
def
triangulo(posx, posy, lado):
02.
turtle.showturtle()
03.
# posicioan
04.
turtle.penup()
05.
turtle.goto(posx, posy)
06.
turtle.pendown()
07.
# desenha
08.
for
i
in
range(
3
):
09.
turtle.forward(lado)
10.
turtle.left(
120
)
11.
turtle.hideturtle()
01.
def
pir_triangulos_inv(n,posx, posy,lado):
02.
for
i
in
range(n,
0
,
-
1
):
03.
# desenha linha i
04.
# posiciona
05.
turtle.penup()
06.
turtle.setx(posx
+
(n
-
i)
*
lado
/
2
)
07.
turtle.pendown()
08.
# desenha
09.
for
j
in
range(
1
,i
+
1
):
10.
triangulo(turtle.xcor(),turtle.ycor(), lado)
# <-- única mudança!!
11.
turtle.setx(turtle.xcor()
+
lado)
12.
# muda de linha
13.
turtle.penup()
14.
turtle.goto(posx,turtle.ycor()
-
lado)
15.
turtle.pendown()
16.
turtle.hideturtle()
01.
def
pir_hexagonos_inv(n,posx, posy,lado):
02.
for
i
in
range(n,
0
,
-
1
):
03.
# desenha linha i
04.
# posiciona
05.
turtle.penup()
06.
turtle.setx(posx
+
(n
-
i)
*
lado
/
2
)
07.
turtle.pendown()
08.
# desenha
09.
for
j
in
range(
1
,i
+
1
):
10.
hexagono(turtle.xcor(),turtle.ycor(), lado)
# <-- única mudança!
11.
turtle.setx(turtle.xcor()
+
lado)
12.
# muda de linha
13.
turtle.penup()
14.
turtle.goto(posx,turtle.ycor()
-
lado)
15.
turtle.pendown()
16.
turtle.hideturtle()
Agora, pode tentar com ... pentágonos??
Sem comentários:
Enviar um comentário