Gráficos: el módulo turtle - Soluciones (2)

Se ofrecen a continuación unas posibles soluciones de los ejercicios (2) del módulo turtle.

A. Figuras de tamaño variable

turtle (2) - A-1 - Figuras

Turtle (2) A-1 1B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 100, 10, 200))

penup()
goto(size, size)
pendown()
goto(-size, size)
goto(-size, -size)
goto(size, -size)
goto(size, size)

exitonclick()
Turtle (2) A-1 2B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 100, 10, 200))

penup()
goto(size // 2, size // 2)
pendown()
goto(-size // 2, size // 2)
goto(-size // 2, -size // 2)
goto(size // 2, -size // 2)
goto(size // 2, size // 2)

exitonclick()
Turtle (2) A-1 3B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 100, 10, 200))

goto(size // 2, size // 2)
goto(size, 0)
goto(0, -size)
goto(-size, 0)
goto(-size // 2, size // 2)
goto(0, 0)

exitonclick()
Turtle (2) A-1 4B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 100, 10, 200))

goto(size // 4, size // 4)
goto(size // 2, 0)
goto(0, -size // 2)
goto(-size // 2, 0)
goto(-size // 4, size // 4)
goto(0, 0)

exitonclick()
Turtle (2) A-1 5B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 100, 10, 200))

penup()
goto(size, size)
pendown()
goto(3 * size, size)
goto(3 * size, 3 * size)
goto(size, 3 * size)
goto(size, -3 * size)
goto(3 * size, -3 * size)
goto(3 * size, -size)
goto(-3 * size, -size)
goto(-3 * size, -3 * size)
goto(-size, -3 * size)
goto(-size, 3 * size)
goto(-3 * size, 3 * size)
goto(-3 * size, size)
goto(size, size)

exitonclick()
Turtle (2) A-1 6B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 100, 10, 200))

penup()
goto(size // 3, size //3)
pendown()
goto(size, size // 3)
goto(size, size)
goto(size // 3, size)
goto(size // 3, -size)
goto(size, -size)
goto(size, -size // 3)
goto(-size, -size // 3)
goto(-size, -size)
goto(-size // 3, -size)
goto(-size // 3, size)
goto(-size, size)
goto(-size, size // 3)
goto(size // 3, size // 3)

exitonclick()
Turtle (2) A-1 7B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 100, 10, 200))

penup()
goto(size, size)
pendown()
goto(3 * size, size)
goto(size, 0)
goto(3 * size, -size)
goto(size, -size)
goto(size, -3 * size)
goto(0, -size)
goto(-size, -3 * size)
goto(-size, -size)
goto(-3 * size, -size)
goto(-size, 0)
goto(-3 * size, size)
goto(-size, size)
goto(-size, 3 * size)
goto(0, size)
goto(size, 3 * size)
goto(size, size)

exitonclick()
Turtle (2) A-1 8B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 100, 10, 200))

penup()
goto(size // 3, size // 3)
pendown()
goto(size, size // 3)
goto(size // 3, 0)
goto(size, -size // 3)
goto(size // 3, -size // 3)
goto(size // 3, -size)
goto(0, -size // 3)
goto(-size // 3, -size)
goto(-size // 3, -size // 3)
goto(-size, -size // 3)
goto(-size // 3, 0)
goto(-size, size // 3)
goto(-size // 3, size // 3)
goto(-size // 3, size)
goto(0, size // 3)
goto(size // 3, size)
goto(size // 3, size // 3)

exitonclick()

turtle (2) A-2 - Letras

Turtle (2) A-2 1B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 20, 10, 200))

setup(10 * size , 13 * size, 0, 0)
screensize(9 * size , 12 * size)

goto(3 * size, 0)
goto(3 * size, size)
goto(size, size)
goto(size, 2 * size)
goto(3 * size, 2 * size)
goto(3 * size, 3 * size)
goto(size, 3 * size)
goto(size, 4 * size)
goto(3 * size, 4 * size)
goto(3 * size, 5 * size)
goto(0, 5 * size)
goto(0, 0)

exitonclick()
Turtle (2) A-2 2B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 20, 10, 200))

setup(3 * size , 3.5 * size, 0, 0)
screensize(2 * size , 3 * size)

goto(size, 0)
goto(size, size // 3)
goto(size // 3, size // 3)
goto(size // 3, 2 * size // 3)
goto(size, 2 * size // 3)
goto(size, size)
goto(size // 3, size)
goto(size // 3, 4 * size // 3)
goto(size, 4 * size // 3)
goto(size, 5 * size // 3)
goto(0, 5 * size // 3)
goto(0, 0)

exitonclick()
Turtle (2) A-2 3B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 20, 10, 200))

setup(8 * size , 8 * size, 0, 0)
screensize(7 * size , 7 * size)

penup()
goto(size, 0)
pendown()
goto(2 * size, 0)
goto(2 * size, 2 * size)
goto(3 * size, 2 * size)
goto(3 * size, 3 * size)
goto(0, 3 * size)
goto(0, 2 * size)
goto(size, 2 * size)
goto(size, 0)

exitonclick()
Turtle (2) A-2 4B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 20, 10, 200))

setup(2.5 * size , 2.5 * size, 0, 0)
screensize(size , size)

penup()
goto(size // 3, 0)
pendown()
goto(2 * size // 3, 0)
goto(2 * size // 3, 2 * size // 3)
goto(size, 2 * size // 3)
goto(size, size)
goto(0, size)
goto(0, 2 * size // 3)
goto(size // 3, 2 * size // 3)
goto(size // 3, 0)

exitonclick()
Turtle (2) A-2 5B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 20, 10, 200))

setup(14 * size , 9 * size, 0, 0)
screensize(13 * size , 4 * size)

goto(2 * size, 0)
goto(3 * size, size)
goto(4 * size, 0)
goto(6 * size, 0)
goto(4 * size, 2 * size)
goto(6 * size, 4 * size)
goto(4 * size, 4 * size)
goto(3 * size, 3 * size)
goto(2 * size, 4 * size)
goto(0, 4 * size)
goto(2 * size, 2 * size)
goto(0, 0)

exitonclick()
Turtle (2) A-2 6B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 20, 10, 200))

setup(2.5 * size , 1.5 * size, 0, 0)
screensize(size , size)

goto(size // 3, 0)
goto(size // 2, size // 6)
goto(2 * size // 3, 0)
goto(size, 0)
goto(2 * size // 3, size // 3)
goto(size, 2 * size // 3)
goto(2 * size // 3, 2 * size // 3)
goto(size // 2, size // 2)
goto(size // 3, 2 * size // 3)
goto(0, 2 * size // 3)
goto(size // 3, size // 3)
goto(0, 0)

exitonclick()
Turtle (2) A-2 7B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 20, 10, 200))

setup(7 * size , 7 * size, 0, 0)
screensize(6 * size , 6 * size)

goto(size, 0)
goto(size, 1.5 * size)
goto(2 * size, 0)
goto(3 * size, 0)
goto(3 * size, 3 * size)
goto(2 * size, 3 * size)
goto(2 * size, 1.5 * size)
goto(size, 3 * size)
goto(0, 3 * size)
goto(0, 0)

exitonclick()
Turtle (2) A-2 8B
from turtle import *

setup(250, 250, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()

size = int(numinput("Módulo turtle", "Tamaño del dibujo (10-200): ", 20, 10, 200))

setup(2.5 * size , 2.5 * size, 0, 0)
screensize(2 * size , 2 * size)

goto(size // 3, 0)
goto(size // 3, size // 3)
goto(2 * size // 3, 0)
goto(size, 0)
goto(size, size)
goto(2 * size // 3, size)
goto(2 * size // 3, 2 * size // 3)
goto(size // 3, size)
goto(0, size)
goto(0, 0)

exitonclick()

B. Bucles

turtle (2) - B-1 - Puntos en en semieje positivo

Turtle (2) B-1 1B
from turtle import *

setup(250, 150, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de puntos (0-10): ", 5, 0, 10))

for i in range(n):
    goto(50 * i, 0)
    dot(10, 0, 0, 0)

exitonclick()
Turtle (2) B-1 2C
from turtle import *

setup(250, 150, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de puntos (0-10): ", 5, 0, 10))
separacion = int(numinput("Módulo turtle","Separación entre puntos (10-50): ",
                          25, 10, 50))

for i in range(n):
    goto(separacion * i , 0)
    dot(10, 0, 0, 0)

exitonclick()
Turtle (2) B-1 3
from turtle import *

setup(250, 150, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de puntos: ", 5, 0, 10))
separacion = int(numinput("Módulo turtle", "Separación entre puntos: ", 25, 0, 50))

for i in range(n):
    goto(separacion * i , 0)
    dot(10, 0, 0, 0)
    goto(separacion * i + 1, 5)
    write(i + 1, False, "center")

exitonclick()
Turtle (2) B-1 4B
from turtle import *

setup(250, 150, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de puntos: ", 5, 0, 100))
separacion = int(numinput("Módulo turtle", "Separación entre puntos: ", 25, 0, 50))

screensize(2 * n * separacion, 120)
for i in range(n):
    goto(separacion * i , 0)
    dot(10, 0, 0, 0)
    goto(separacion * i + 1, 5)
    write(i + 1, False, "center")

exitonclick()
Turtle (2) B-1 5D
from turtle import *

setup(250, 150, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de puntos (0-100): ", 5, 0, 100))
grosor = int(numinput("Módulo turtle", "Grosor de los puntos (3-50)", 25, 3, 50))
separacion = int(numinput("Módulo turtle",
                          "Separación entre puntos ({grosor}-{5 * grosor}):",
                          3 * grosor, grosor, 5 * grosor))

screensize(2 * n * separacion, 120)
for i in range(n):
    goto(separacion * i , 0)
    dot(grosor, 0, 0, 0)
    goto(separacion * i + 1, grosor // 2)
    write(i + 1, False, "center")

exitonclick()

turtle (2) - B-2 - Puntos centrados

Turtle (2) B-2 ºB
from turtle import *

setup(250, 150, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de puntos: ", 5, 0, 10))

for i in range(n):
    goto(-50 * (n-1) / 2 + 50 * i , 0)
    dot(10, 0, 0, 0)

exitonclick()

turtle (2) - B-3 - Puntos

Turtle (2) B-3 1C
from turtle import *

setup(250, 150, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de puntos (5-20): ", 10, 0, 20))
grosor = int(numinput("Módulo turtle", "Grosor de los puntos (10-30)", 20, 10, 30))

for i in range(n):
    goto(grosor * i, 0)
    dot(grosor, 0, 0, 0)
    goto(grosor * i, grosor // 2)
    write(i+1, False, "center")

exitonclick()
Turtle (2) B-3 2
from turtle import *

setup(250, 150, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de puntos (5-20): ", 10, 0, 20))
grosor = int(numinput("Módulo turtle", "Grosor de los puntos (10-30)", 20, 10, 30))

color = 1 / n
for i in range(n):
    goto(grosor * i, 0)
    dot(grosor, color * i, color * i, color * i)
    goto(grosor * i, grosor // 2)
    write(i+1, False, "center")

exitonclick()
Turtle (2) B-3 3
from turtle import *

setup(250, 150, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de puntos (5-20): ", 10, 0, 20))
grosor = int(numinput("Módulo turtle", "Grosor de los puntos (10-30)", 20, 10, 30))

for i in range(n):
    goto(grosor * i, 0)
    dot(grosor, 0, 0, 0)
for i in range(n):
    goto(0, grosor * i)
    dot(grosor, 0, 0, 0)
for i in range(n):
    goto(grosor * i, grosor * (n-1))
    dot(grosor, 0, 0, 0)
for i in range(n):
    goto(grosor * (n-1), grosor * i)
    dot(grosor, 0, 0, 0)

exitonclick()
Turtle (2) B-3 4
from turtle import *

setup(250, 150, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de puntos (5-20): ", 10, 0, 20))
grosor = int(numinput("Módulo turtle", "Grosor de los puntos (10-30)", 20, 10, 30))

color = 1 / n
for i in range(n - 1):
    goto(grosor * i, 0)
    dot(grosor, color * i, color * i, color * i)
for i in range(n):
    goto(0, grosor * i)
    dot(grosor, color * i, color * i, color * i)
for i in range(n):
    goto(grosor * i, grosor * (n-1))
    dot(grosor, color * i, color * i, color * i)
for i in range(n):
    goto(grosor * (n-1), grosor * i)
    dot(grosor, color * i, color * i, color * i)

exitonclick()
Turtle (2) B-3 5
from turtle import *

setup(250, 150, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de puntos (5-20): ", 10, 0, 20))
grosor = int(numinput("Módulo turtle", "Grosor de los puntos (10-30)", 20, 10, 30))

color = 1 / n
for i in range(n): # abajo
    goto(grosor * i, 0)
    dot(grosor, color * i, color * i, color * i)
for i in range(n): # izquierda
    goto(0, grosor * i)
    dot(grosor, color * i, color * i, color * i)
for i in range(n): # arriba
    goto(grosor * (n-1) - grosor * i, grosor * (n-1))
    dot(grosor, color * i, color * i, color * i)
for i in range(n): # derecha
    goto(grosor * (n-1), grosor * (n-1) - grosor * i)
    dot(grosor, color * i, color * i, color * i)

exitonclick()
Turtle (2) B-3 6
from turtle import *

setup(250, 150, 0, 0)
screensize(120, 120)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de puntos (5-20): ", 10, 0, 20))
grosor = int(numinput("Módulo turtle", "Grosor de los puntos (10-30)", 20, 10, 30))

color = 1 / n
for i in range(n - 1): # abajo
    goto(grosor * i, 0)
    dot(grosor, color * i, color * i, color * i)
for i in range(n - 1): # izquierda
    goto(0, grosor * (n-1) - grosor * i)
    dot(grosor, color * i, color * i, color * i)
for i in range(n - 1): # arriba
    goto(grosor * (n-1) - grosor * i, grosor * (n-1))
    dot(grosor, color * i, color * i, color * i)
for i in range(n - 1): # derecha
    goto(grosor * (n-1), grosor * i)
    dot(grosor, color * i, color * i, color * i)

exitonclick()

turtle (2) - B-4 - Líneas

Turtle (2) B-4 1
from turtle import *

setup(420, 420, 0, 0)
screensize(400, 400)
title("www.mclibre.org")
hideturtle()
penup()

for i in range(11):
    goto(20 * i, 0)
    pendown()
    goto(20 * i, 200)
    penup()

exitonclick()
Turtle (2) B-4 2B
from turtle import *

setup(420, 420, 0, 0)
screensize(400, 400)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de líneas (2-20): ", 10, 2, 20))

for i in range(n):
    goto(20 * i, 0)
    pendown()
    goto(20 * i, 20 * (n-1))
    penup()

exitonclick()
Turtle (2) B-4 3C
from turtle import *

setup(420, 420, 0, 0)
screensize(400, 400)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de líneas (2-20): ", 10, 2, 20))
separa = int(numinput("Módulo turtle", "Separación entre líneas (2-30)", 15, 2, 30))

for i in range(n):
    goto(separa * i, 0)
    pendown()
    goto(separa * i, separa * (n-1))
    penup()

exitonclick()
Turtle (2) B-4 4C
from turtle import *

setup(420, 420, 0, 0)
screensize(400, 400)
title("www.mclibre.org")
hideturtle()
penup()

n = int(numinput("Módulo turtle", "Número de líneas (2-20): ", 10, 2, 20))
separa = int(numinput("Módulo turtle", "Separación entre líneas (2-30)", 15, 2, 30))

for i in range(n):
    goto(separa * i, 0)
    pendown()
    goto(separa * i, separa * (n-1))
    penup()

for i in range(n):
    goto(0, separa * i)
    pendown()
    goto(separa * (n-1) + 1, separa * i)
    penup()

exitonclick()
Turtle (2) B-4 5D
from turtle import *

setup(420, 420, 0, 0)
screensize(400, 400)
title("www.mclibre.org")
hideturtle()
penup()

separa = int(numinput("Módulo turtle", "Tamaño del cuadrado (2-40): ", 20, 2, 40))
nx = int(numinput("Módulo turtle", "Número de cuadrados en horizontal (1-20)", 15, 1, 20))
ny = int(numinput("Módulo turtle", "Número de cuadrados en vertical (1-20)", 15, 1, 20))

for i in range(nx + 1):
    goto(separa * i, 0)
    pendown()
    goto(separa * i, separa * ny)
    penup()

for i in range(ny + 1):
    goto(0, separa * i)
    pendown()
    goto(separa * nx + 1, separa * i)
    penup()

exitonclick()

turtle (2) - B-5 - Cuadrados

Turtle (2) B-5 1
from turtle import *

setup(420, 420, 0, 0)
screensize(400, 400)
title("www.mclibre.org")
hideturtle()
penup()

pendown()
goto(50, 0)
goto(50, 50)
goto(0, 50)
goto(0,0)

exitonclick()
Turtle (2) B-5 2B
from turtle import *

setup(420, 420, 0, 0)
screensize(400, 400)
title("www.mclibre.org")
hideturtle()
penup()

lado = int(numinput("Módulo turtle", "Tamaño del cuadrado (20-200): ", 100, 20, 200))

pendown()
goto(lado, 0)
goto(lado, lado)
goto(0, lado)
goto(0, 0)

exitonclick()
Turtle (2) B-5 3C
from turtle import *

setup(420, 420, 0, 0)
title("www.mclibre.org")
hideturtle()
penup()

lado = int(numinput("Módulo turtle", "Tamaño del cuadrado (20-200): ", 100, 20, 200))
n = int(numinput("Módulo turtle", "Número de cuadrados (1-20)", 10, 1, 20))

screensize(lado * n * 2 * 2, 300)

for i in range(n):
    origen = 2 * lado * i
    goto(origen, 0)
    pendown()
    goto(origen + lado, 0)
    goto(origen + lado, lado)
    goto(origen, lado)
    goto(origen, 0)
    penup()

exitonclick()
Turtle (2) B-5 4C
from turtle import *

setup(420, 420, 0, 0)
title("www.mclibre.org")
hideturtle()
penup()

lado = int(numinput("Módulo turtle", "Tamaño inicial del cuadrado (20-200): ", 60, 20, 100))
n = int(numinput("Módulo turtle", "Número de cuadrados (1-20)", 10, 1, 20))

screensize((lado + 2*20*n) + 30, 300)

pendown()
for i in range(n):
    goto(0, 0)
    goto(lado + 20*i, 0)
    goto(lado + 20*i, lado + 20*i)
    goto(0, lado + 20*i)
    goto(0, 0)

exitonclick()