Es un objeto que se importa de la libreria turtle en python.
¿Qué finalidad tiene turtle?
Es
la introducción de gráficos en python en su nivel más básico, generalmente es para niños.
¿Comó importar la tortuga?
Escribiendo la libreria
from turtle import* o import turtle
Practica personal (Cara):
from turtle import *
shape('turtle')
#cara
penup()
begin_fill()
color('#FFC262')
goto(30,-150)
pendown()
circle(130)
penup()
end_fill()
#ojo 1
color('white')
goto(0,0)
begin_fill()
pendown()
circle(20)
penup()
end_fill()
begin_fill()
color('black')
pendown()
circle(10)
penup()
end_fill()
#ojo 2
forward(60)
right(45)
begin_fill()
color('white')
pendown()
circle(30)
penup()
end_fill()
begin_fill()
color('black')
pendown()
circle(10)
penup()
end_fill()
#boca y lengua
right(90)
forward(90)
begin_fill()
color('white')
pendown()
circle(40)
penup()
end_fill()
begin_fill()
color('#FF3A0C')
pendown()
circle(36)
penup()
end_fill()
#texto
color('blue')
goto(-65,-205)
begin_fill()
write('Woooooooow :v\n Python con tortuga :3', font=("Times New Roman", 20, "bold"))
done()
Captura:
Practica en clase (barquito):
from turtle import *
setup(700,500,0,0)
screensize(150,150)
colormode(255)
hideturtle()
fillcolor("white")
begin_fill()
goto(100,0)
goto(50,100)
goto(0,0)
end_fill()
goto(50,100)
pencolor("#FF7800")
pensize(3)
goto(50,-10)
fillcolor("#FF7800")
begin_fill()
goto(120,-10)
goto(100,-20)
goto(0,-20)
goto(-20,-10)
goto(50,-10)
end_fill()
penup()
pencolor("#0090FF")
pensize(3)
fillcolor("#0090FF")
begin_fill()
goto(-150,-20)
pendown()
goto(250,-20)
goto(250,-80)
goto(-150,-80)
goto(-150,-20)
end_fill()
penup()
goto(0,-120)
write('Jordi :,v', font=("Times New Roman", 20, "bold"))
done()
Captura:
Practica en clase (cuadro, triangulo , octágono y estrella):
import turtle
turtle.speed(10)
fondo=turtle.Screen()
fondo.bgcolor("#0000FF")
turtle.pencolor("white")
# En el for i right 90, en j right 80 cuadrado
# En el for i right 120, en j right 110 triangulo
# En el for i right 45, en j right 40 octagono
for i in range(28):
turtle.forward(100)
turtle.right(150)
for j in range(1):
turtle.forward(100)
turtle.right(140)
turtle.exitonclick()
Captura:
Practica en clase (preguntar colores):
import turtle
import tkSimpleDialog
t=turtle.Turtle()
c1=tkSimpleDialog.askstring("Color","Escribe el color del lapiz:")
c2=tkSimpleDialog.askstring("Color","Escribe el color del relleno:")
t.color(c1, c2)
t.begin_fill()
for _ in xrange(3):
t.fd(100)
t.left(120)
t.end_fill()
turtle.done()
Capturas:
Practica personal (Trifuerza):
import turtle
tort1=turtle.Turtle()
tort2=turtle.Turtle()
#tipos de shape: arrow, turtle, circle, square, triangle, classic
tort1.speed(2)
tort2.speed(2)
tort1.pensize(2)
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.penup()
tort1.sety(180)
tort1.pendown()
tort1.goto(30,230)
tort1.goto(60,180)
tort1.goto(0,180)
tort1.end_fill()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-30,130)
tort1.goto(30,130)
tort1.goto(0,180)
tort1.end_fill()
tort2.pensize(2)
tort2.penup()
tort2.goto(60,180)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(90,130)
tort2.goto(30,130)
tort2.goto(60,180)
tort2.end_fill()
tort1.penup()
tort1.goto(-30,130)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-60,80)
tort1.goto(0,80)
tort1.goto(-30,130)
tort1.end_fill()
tort2.penup()
tort2.goto(90,130)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(60,80)
tort2.goto(120,80)
tort2.goto(90,130)
tort2.end_fill()
tort1.penup()
tort1.goto(-60,80)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-90,30)
tort1.goto(-30,30)
tort1.goto(-60,80)
tort1.end_fill()
tort2.penup()
tort2.goto(120,80)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(90,30)
tort2.goto(150,30)
tort2.goto(120,80)
tort2.end_fill()
tort1.penup()
tort1.goto(0,80)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-30,30)
tort1.goto(30,30)
tort1.goto(0,80)
tort1.end_fill()
tort2.penup()
tort2.goto(60,80)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(90,30)
tort2.goto(30,30)
tort2.goto(60,80)
tort2.end_fill()
tort1.penup()
tort1.setx(-30)
tort1.goto(-90,30)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-125,-30)
tort1.goto(-60,-30)
tort1.goto(-90,30)
tort1.end_fill()
tort2.penup()
tort2.setx(120)
tort2.goto(150,30)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(185,-30)
tort2.goto(120,-30)
tort2.goto(150,30)
tort2.end_fill()
tort1.penup()
tort1.goto(-125,-30)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-160,-90)
tort1.goto(-95,-90)
tort1.goto(-125,-30)
tort1.end_fill()
tort2.penup()
tort2.goto(185,-30)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(220,-90)
tort2.goto(155,-90)
tort2.goto(185,-30)
tort2.end_fill()
tort1.penup()
tort1.goto(-60,-30)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-30,-90)
tort1.goto(-95,-90)
tort1.goto(-60,-30)
tort1.end_fill()
tort2.penup()
tort2.setx(120)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(155,-90)
tort2.goto(90,-90)
tort2.goto(120,-30)
tort2.end_fill()
tort1.penup()
tort1.setx(-125)
tort1.goto(-160,-90)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-195,-150)
tort1.goto(-130,-150)
tort1.goto(-160,-90)
tort1.end_fill()
tort2.penup()
tort2.setx(180)
tort2.goto(220,-90)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(255,-150)
tort2.goto(190,-150)
tort2.goto(220,-90)
tort2.end_fill()
tort1.penup()
tort1.goto(-195,-150)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-230,-210)
tort1.goto(-165,-210)
tort1.goto(-195,-150)
tort1.end_fill()
tort2.penup()
tort2.goto(255,-150)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(288,-210)
tort2.goto(225,-210)
tort2.goto(255,-150)
tort2.end_fill()
tort1.penup()
tort1.setx(-130)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-165,-210)
tort1.goto(-100,-210)
tort1.goto(-130,-150)
tort1.end_fill()
tort2.penup()
tort2.setx(190)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(160,-210)
tort2.goto(225,-210)
tort2.goto(190,-150)
tort2.end_fill()
tort1.penup()
tort1.goto(-100,-210)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-65,-150)
tort1.goto(-35,-210)
tort1.goto(-100,-210)
tort1.end_fill()
tort2.penup()
tort2.goto(160,-210)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(95,-210)
tort2.goto(125,-150)
tort2.goto(160,-210)
tort2.end_fill()
tort1.penup()
tort1.goto(-100,-210)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-30,-90)
tort1.goto(0,-150)
tort1.goto(-65,-150)
tort1.end_fill()
tort2.penup()
tort2.goto(125,-150)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(60,-150)
tort2.goto(90,-90)
tort2.goto(125,-150)
tort2.end_fill()
tort1.penup()
tort1.setx(0)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-35,-210)
tort1.goto(30,-210)
tort1.goto(0,-150)
tort1.end_fill()
tort2.penup()
tort2.setx(60)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(30,-210)
tort2.goto(95,-210)
tort2.goto(60,-150)
tort2.end_fill()
turtle.done()
Captura:
Practicas con hilos y turtle (Trifuerza una parte de la practica anterior):
ADVERTENCIA: El programa tiende a fallos por la libreria turtle al hacer la ejecucion de hilos puede llegan a congelarce o hacer mal el proceso.
import threading
import turtle
import time
tort1=turtle.Turtle()
tort2=turtle.Turtle()
#tipos de shape: arrow, turtle, circle, square, triangle, classic
tort1.shape("turtle")
tort2.shape("turtle")
tort1.speed(2)
tort2.speed(2)
tort1.pensize(2)
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort2.pensize(2)
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
def m1():
tort1.begin_fill()
tort1.penup()
tort1.sety(180)
tort1.pendown()
tort1.goto(30,230)
tort1.goto(60,180)
tort1.goto(0,180)
tort1.end_fill()
def m2():
tort2.begin_fill()
tort2.penup()
tort2.sety(180)
tort2.pendown()
tort2.goto(60,180)
tort2.goto(30,230)
tort2.goto(0,180)
tort2.end_fill()
t=threading.Thread(target=m1)
t.daemon=True
t.start()
t2=threading.Thread(target=m2)
t2.daemon=True
t2.start()
time.sleep(2)
def m3():
tort1.begin_fill()
tort1.goto(-30,130)
tort1.goto(30,130)
tort1.goto(0,180)
tort1.end_fill()
def m4():
tort2.penup()
tort2.goto(60,180)
tort2.pendown()
tort2.begin_fill()
tort2.goto(90,130)
tort2.goto(30,130)
tort2.goto(60,180)
tort2.end_fill()
t=threading.Thread(target=m3)
t.daemon=True
t.start()
t2=threading.Thread(target=m4)
t2.daemon=True
t2.start()
time.sleep(2)
tort1.penup()
tort2.penup()
tort1.pencolor("#0000FF")
tort2.pencolor("#0000FF")
def m5():
tort1.goto(-150,60)
tort1.write('Woooooow manejando tortugas', font=("Times New Roman", 20, "bold"))
def m6():
tort2.goto(-80,30)
tort2.write('al mismo tiempo :O', font=("Times New Roman", 20, "bold"))
t=threading.Thread(target=m5)
t.daemon=True
t.start()
t2=threading.Thread(target=m6)
t2.daemon=True
t2.start()
turtle.done()
Captura:
Practica personal con hilos en la trifuerza:
ADVERTENCIA: Al manejar una cantidad de hilos mayor tiende a fallar.
import threading
import time
import turtle
tort1=turtle.Turtle()
tort2=turtle.Turtle()
#tipos de shape: arrow, turtle, circle, square, triangle, classic
#tort1.hideturtle()
#tort2.hideturtle()
tort1.speed(3)
tort2.speed(3)
tort1.pensize(2)
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort2.pensize(2)
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
def m1():
tort1.begin_fill()
tort1.penup()
tort1.sety(180)
tort1.pendown()
tort1.goto(30,230)
tort1.goto(60,180)
tort1.goto(0,180)
tort1.end_fill()
def m2():
tort2.begin_fill()
tort2.penup()
tort2.sety(180)
tort2.pendown()
tort2.goto(60,180)
tort2.goto(30,230)
tort2.goto(0,180)
tort2.end_fill()
t=threading.Thread(target=m1)
t.daemon=True
t.start()
t2=threading.Thread(target=m2)
t2.daemon=True
t2.start()
time.sleep(2)
def m3():
tort1.begin_fill()
tort1.goto(-30,130)
tort1.goto(30,130)
tort1.goto(0,180)
tort1.end_fill()
def m4():
tort2.penup()
tort2.goto(60,180)
tort2.pendown()
tort2.begin_fill()
tort2.goto(90,130)
tort2.goto(30,130)
tort2.goto(60,180)
tort2.end_fill()
t=threading.Thread(target=m3)
t.daemon=True
t.start()
t2=threading.Thread(target=m4)
t2.daemon=True
t2.start()
time.sleep(2)
def m5():
tort1.penup()
tort1.goto(-30,130)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-60,80)
tort1.goto(0,80)
tort1.goto(-30,130)
tort1.end_fill()
def m6():
tort2.penup()
tort2.goto(90,130)
tort2.pendown()
tort2.begin_fill()
tort2.goto(60,80)
tort2.goto(120,80)
tort2.goto(90,130)
tort2.end_fill()
t=threading.Thread(target=m5)
t.daemon=True
t.start()
t2=threading.Thread(target=m6)
t2.daemon=True
t2.start()
time.sleep(2)
def m7():
tort1.penup()
tort1.goto(-60,80)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-90,30)
tort1.goto(-30,30)
tort1.goto(-60,80)
tort1.end_fill()
def m8():
tort2.penup()
tort2.goto(120,80)
tort2.pendown()
tort2.begin_fill()
tort2.goto(90,30)
tort2.goto(150,30)
tort2.goto(120,80)
tort2.end_fill()
t=threading.Thread(target=m7)
t.daemon=True
t.start()
t2=threading.Thread(target=m8)
t2.daemon=True
t2.start()
time.sleep(2)
def m9():
tort1.penup()
tort1.goto(0,80)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-30,30)
tort1.goto(30,30)
tort1.goto(0,80)
tort1.end_fill()
def m10():
tort2.penup()
tort2.goto(60,80)
tort2.pendown()
tort2.begin_fill()
tort2.goto(90,30)
tort2.goto(30,30)
tort2.goto(60,80)
tort2.end_fill()
t=threading.Thread(target=m9)
t.daemon=True
t.start()
t2=threading.Thread(target=m10)
t2.daemon=True
t2.start()
time.sleep(2)
def m11():
tort1.penup()
tort1.setx(-30)
tort1.goto(-90,30)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-125,-30)
tort1.goto(-60,-30)
tort1.goto(-90,30)
tort1.end_fill()
def m12():
tort2.penup()
tort2.setx(120)
tort2.goto(150,30)
tort2.pendown()
tort2.begin_fill()
tort2.goto(185,-30)
tort2.goto(120,-30)
tort2.goto(150,30)
tort2.end_fill()
t=threading.Thread(target=m11)
t.daemon=True
t.start()
t2=threading.Thread(target=m12)
t2.daemon=True
t2.start()
time.sleep(2)
def m13():
tort1.penup()
tort1.goto(-125,-30)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-160,-90)
tort1.goto(-95,-90)
tort1.goto(-125,-30)
tort1.end_fill()
def m14():
tort2.penup()
tort2.goto(185,-30)
tort2.pendown()
tort2.begin_fill()
tort2.goto(220,-90)
tort2.goto(155,-90)
tort2.goto(185,-30)
tort2.end_fill()
t=threading.Thread(target=m13)
t.daemon=True
t.start()
t2=threading.Thread(target=m14)
t2.daemon=True
t2.start()
time.sleep(2)
def m15():
tort1.penup()
tort1.goto(-60,-30)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-30,-90)
tort1.goto(-95,-90)
tort1.goto(-60,-30)
tort1.end_fill()
def m16():
tort2.penup()
tort2.setx(120)
tort2.pendown()
tort2.begin_fill()
tort2.goto(155,-90)
tort2.goto(90,-90)
tort2.goto(120,-30)
tort2.end_fill()
t=threading.Thread(target=m15)
t.daemon=True
t.start()
t2=threading.Thread(target=m16)
t2.daemon=True
t2.start()
time.sleep(2)
def m17():
tort1.penup()
tort1.setx(-125)
tort1.goto(-160,-90)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-195,-150)
tort1.goto(-130,-150)
tort1.goto(-160,-90)
tort1.end_fill()
def m18():
tort2.penup()
tort2.setx(180)
tort2.goto(220,-90)
tort2.pendown()
tort2.begin_fill()
tort2.goto(255,-150)
tort2.goto(190,-150)
tort2.goto(220,-90)
tort2.end_fill()
t=threading.Thread(target=m17)
t.daemon=True
t.start()
t2=threading.Thread(target=m18)
t2.daemon=True
t2.start()
time.sleep(2)
def m19():
tort1.penup()
tort1.goto(-195,-150)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-230,-210)
tort1.goto(-165,-210)
tort1.goto(-195,-150)
tort1.end_fill()
def m20():
tort2.penup()
tort2.goto(255,-150)
tort2.pendown()
tort2.begin_fill()
tort2.goto(288,-210)
tort2.goto(225,-210)
tort2.goto(255,-150)
tort2.end_fill()
t=threading.Thread(target=m19)
t.daemon=True
t.start()
t2=threading.Thread(target=m20)
t2.daemon=True
t2.start()
time.sleep(2)
def m21():
tort1.penup()
tort1.setx(-130)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-165,-210)
tort1.goto(-100,-210)
tort1.goto(-130,-150)
tort1.end_fill()
def m22():
tort2.penup()
tort2.setx(190)
tort2.pendown()
tort2.begin_fill()
tort2.goto(160,-210)
tort2.goto(225,-210)
tort2.goto(190,-150)
tort2.end_fill()
t=threading.Thread(target=m21)
t.daemon=True
t.start()
t2=threading.Thread(target=m22)
t2.daemon=True
t2.start()
time.sleep(2)
def m23():
tort1.penup()
tort1.goto(-100,-210)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-65,-150)
tort1.goto(-35,-210)
tort1.goto(-100,-210)
tort1.end_fill()
def m24():
tort2.penup()
tort2.goto(160,-210)
tort2.pendown()
tort2.begin_fill()
tort2.goto(95,-210)
tort2.goto(125,-150)
tort2.goto(160,-210)
tort2.end_fill()
t=threading.Thread(target=m23)
t.daemon=True
t.start()
t2=threading.Thread(target=m24)
t2.daemon=True
t2.start()
time.sleep(2)
def m25():
tort1.penup()
tort1.goto(-100,-210)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-30,-90)
tort1.goto(0,-150)
tort1.goto(-65,-150)
tort1.end_fill()
def m26():
tort2.penup()
tort2.goto(125,-150)
tort2.pendown()
tort2.begin_fill()
tort2.goto(60,-150)
tort2.goto(90,-90)
tort2.goto(125,-150)
tort2.end_fill()
t=threading.Thread(target=m25)
t.daemon=True
t.start()
t2=threading.Thread(target=m26)
t2.daemon=True
t2.start()
time.sleep(2)
def m27():
tort1.penup()
tort1.setx(0)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-35,-210)
tort1.goto(30,-210)
tort1.goto(0,-150)
tort1.end_fill()
def m28():
tort2.penup()
tort2.setx(60)
tort2.pendown()
tort2.begin_fill()
tort2.goto(95,-210)
tort2.goto(30,-210)
tort2.goto(60,-150)
tort2.end_fill()
t=threading.Thread(target=m27)
t.daemon=True
t.start()
t2=threading.Thread(target=m28)
t2.daemon=True
t2.start()
turtle.done()
Captura:
Practica en clase (3 figuras preguntando el color):
import turtle
import tkSimpleDialog
t=turtle.Turtle()
fondo=turtle.Screen()
fondo.bgcolor('#B400FF')
#t.speed(100)
def colores():
c1=tkSimpleDialog.askstring("Color","Escribe el color del lapiz:")
c2=tkSimpleDialog.askstring("Color","Escribe el color del relleno:")
return t.color(c1, c2)
# Comienza el triangulo
t.pensize(2)
colores()
t.begin_fill()
for _ in xrange(3):
t.fd(100)
t.left(120)
t.end_fill()
# Comienza el molino de viento
t.penup()
t.goto(40,100)
t.pendown()
t.pencolor('black')
t.pensize(4)
t.goto(40,220)
t.pensize(1)
colores()
t.begin_fill()
for i in range(30):
t.goto(40,220)
t.forward(100)
t.right(150)
for j in range(1):
t.forward(100)
t.right(145)
t.end_fill()
# Comienza la estrella
t.penup()
t.goto(80,-130)
colores()
t.begin_fill()
t.pendown()
for i in range(30):
t.forward(100)
t.right(150)
for j in range(1):
t.forward(100)
t.right(145)
t.penup()
t.hideturtle()
t.goto(175,220)
t.pencolor('white')
t.write('Molino de viento', font=("Times New Roman", 20, "bold"))
t.goto(215,40)
t.write('Triangulo', font=("Times New Roman", 20, "bold"))
t.goto(230,-100)
t.write('Estrella', font=("Times New Roman", 20, "bold"))
turtle.done()
Capturas:
Ejercicios de turtle:
from turtle import *
shape('turtle')
#cara
penup()
begin_fill()
color('#FFC262')
goto(30,-150)
pendown()
circle(130)
penup()
end_fill()
#ojo 1
color('white')
goto(0,0)
begin_fill()
pendown()
circle(20)
penup()
end_fill()
begin_fill()
color('black')
pendown()
circle(10)
penup()
end_fill()
#ojo 2
forward(60)
right(45)
begin_fill()
color('white')
pendown()
circle(30)
penup()
end_fill()
begin_fill()
color('black')
pendown()
circle(10)
penup()
end_fill()
#boca y lengua
right(90)
forward(90)
begin_fill()
color('white')
pendown()
circle(40)
penup()
end_fill()
begin_fill()
color('#FF3A0C')
pendown()
circle(36)
penup()
end_fill()
#texto
color('blue')
goto(-65,-205)
begin_fill()
write('Woooooooow :v\n Python con tortuga :3', font=("Times New Roman", 20, "bold"))
done()
Captura:
Practica en clase (barquito):
from turtle import *
setup(700,500,0,0)
screensize(150,150)
colormode(255)
hideturtle()
fillcolor("white")
begin_fill()
goto(100,0)
goto(50,100)
goto(0,0)
end_fill()
goto(50,100)
pencolor("#FF7800")
pensize(3)
goto(50,-10)
fillcolor("#FF7800")
begin_fill()
goto(120,-10)
goto(100,-20)
goto(0,-20)
goto(-20,-10)
goto(50,-10)
end_fill()
penup()
pencolor("#0090FF")
pensize(3)
fillcolor("#0090FF")
begin_fill()
goto(-150,-20)
pendown()
goto(250,-20)
goto(250,-80)
goto(-150,-80)
goto(-150,-20)
end_fill()
penup()
goto(0,-120)
write('Jordi :,v', font=("Times New Roman", 20, "bold"))
done()
Captura:
Practica en clase (cuadro, triangulo , octágono y estrella):
import turtle
turtle.speed(10)
fondo=turtle.Screen()
fondo.bgcolor("#0000FF")
turtle.pencolor("white")
# En el for i right 90, en j right 80 cuadrado
# En el for i right 120, en j right 110 triangulo
# En el for i right 45, en j right 40 octagono
for i in range(28):
turtle.forward(100)
turtle.right(150)
for j in range(1):
turtle.forward(100)
turtle.right(140)
turtle.exitonclick()
Captura:
Practica en clase (preguntar colores):
import turtle
import tkSimpleDialog
t=turtle.Turtle()
c1=tkSimpleDialog.askstring("Color","Escribe el color del lapiz:")
c2=tkSimpleDialog.askstring("Color","Escribe el color del relleno:")
t.color(c1, c2)
t.begin_fill()
for _ in xrange(3):
t.fd(100)
t.left(120)
t.end_fill()
turtle.done()
Capturas:
Practica personal (Trifuerza):
import turtle
tort1=turtle.Turtle()
tort2=turtle.Turtle()
#tipos de shape: arrow, turtle, circle, square, triangle, classic
tort1.speed(2)
tort2.speed(2)
tort1.pensize(2)
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.penup()
tort1.sety(180)
tort1.pendown()
tort1.goto(30,230)
tort1.goto(60,180)
tort1.goto(0,180)
tort1.end_fill()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-30,130)
tort1.goto(30,130)
tort1.goto(0,180)
tort1.end_fill()
tort2.pensize(2)
tort2.penup()
tort2.goto(60,180)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(90,130)
tort2.goto(30,130)
tort2.goto(60,180)
tort2.end_fill()
tort1.penup()
tort1.goto(-30,130)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-60,80)
tort1.goto(0,80)
tort1.goto(-30,130)
tort1.end_fill()
tort2.penup()
tort2.goto(90,130)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(60,80)
tort2.goto(120,80)
tort2.goto(90,130)
tort2.end_fill()
tort1.penup()
tort1.goto(-60,80)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-90,30)
tort1.goto(-30,30)
tort1.goto(-60,80)
tort1.end_fill()
tort2.penup()
tort2.goto(120,80)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(90,30)
tort2.goto(150,30)
tort2.goto(120,80)
tort2.end_fill()
tort1.penup()
tort1.goto(0,80)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-30,30)
tort1.goto(30,30)
tort1.goto(0,80)
tort1.end_fill()
tort2.penup()
tort2.goto(60,80)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(90,30)
tort2.goto(30,30)
tort2.goto(60,80)
tort2.end_fill()
tort1.penup()
tort1.setx(-30)
tort1.goto(-90,30)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-125,-30)
tort1.goto(-60,-30)
tort1.goto(-90,30)
tort1.end_fill()
tort2.penup()
tort2.setx(120)
tort2.goto(150,30)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(185,-30)
tort2.goto(120,-30)
tort2.goto(150,30)
tort2.end_fill()
tort1.penup()
tort1.goto(-125,-30)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-160,-90)
tort1.goto(-95,-90)
tort1.goto(-125,-30)
tort1.end_fill()
tort2.penup()
tort2.goto(185,-30)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(220,-90)
tort2.goto(155,-90)
tort2.goto(185,-30)
tort2.end_fill()
tort1.penup()
tort1.goto(-60,-30)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-30,-90)
tort1.goto(-95,-90)
tort1.goto(-60,-30)
tort1.end_fill()
tort2.penup()
tort2.setx(120)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(155,-90)
tort2.goto(90,-90)
tort2.goto(120,-30)
tort2.end_fill()
tort1.penup()
tort1.setx(-125)
tort1.goto(-160,-90)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-195,-150)
tort1.goto(-130,-150)
tort1.goto(-160,-90)
tort1.end_fill()
tort2.penup()
tort2.setx(180)
tort2.goto(220,-90)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(255,-150)
tort2.goto(190,-150)
tort2.goto(220,-90)
tort2.end_fill()
tort1.penup()
tort1.goto(-195,-150)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-230,-210)
tort1.goto(-165,-210)
tort1.goto(-195,-150)
tort1.end_fill()
tort2.penup()
tort2.goto(255,-150)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(288,-210)
tort2.goto(225,-210)
tort2.goto(255,-150)
tort2.end_fill()
tort1.penup()
tort1.setx(-130)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-165,-210)
tort1.goto(-100,-210)
tort1.goto(-130,-150)
tort1.end_fill()
tort2.penup()
tort2.setx(190)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(160,-210)
tort2.goto(225,-210)
tort2.goto(190,-150)
tort2.end_fill()
tort1.penup()
tort1.goto(-100,-210)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-65,-150)
tort1.goto(-35,-210)
tort1.goto(-100,-210)
tort1.end_fill()
tort2.penup()
tort2.goto(160,-210)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(95,-210)
tort2.goto(125,-150)
tort2.goto(160,-210)
tort2.end_fill()
tort1.penup()
tort1.goto(-100,-210)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-30,-90)
tort1.goto(0,-150)
tort1.goto(-65,-150)
tort1.end_fill()
tort2.penup()
tort2.goto(125,-150)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(60,-150)
tort2.goto(90,-90)
tort2.goto(125,-150)
tort2.end_fill()
tort1.penup()
tort1.setx(0)
tort1.pendown()
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort1.begin_fill()
tort1.goto(-35,-210)
tort1.goto(30,-210)
tort1.goto(0,-150)
tort1.end_fill()
tort2.penup()
tort2.setx(60)
tort2.pendown()
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
tort2.begin_fill()
tort2.goto(30,-210)
tort2.goto(95,-210)
tort2.goto(60,-150)
tort2.end_fill()
turtle.done()
Captura:
Practicas con hilos y turtle (Trifuerza una parte de la practica anterior):
ADVERTENCIA: El programa tiende a fallos por la libreria turtle al hacer la ejecucion de hilos puede llegan a congelarce o hacer mal el proceso.
import threading
import turtle
import time
tort1=turtle.Turtle()
tort2=turtle.Turtle()
#tipos de shape: arrow, turtle, circle, square, triangle, classic
tort1.shape("turtle")
tort2.shape("turtle")
tort1.speed(2)
tort2.speed(2)
tort1.pensize(2)
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort2.pensize(2)
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
def m1():
tort1.begin_fill()
tort1.penup()
tort1.sety(180)
tort1.pendown()
tort1.goto(30,230)
tort1.goto(60,180)
tort1.goto(0,180)
tort1.end_fill()
def m2():
tort2.begin_fill()
tort2.penup()
tort2.sety(180)
tort2.pendown()
tort2.goto(60,180)
tort2.goto(30,230)
tort2.goto(0,180)
tort2.end_fill()
t=threading.Thread(target=m1)
t.daemon=True
t.start()
t2=threading.Thread(target=m2)
t2.daemon=True
t2.start()
time.sleep(2)
def m3():
tort1.begin_fill()
tort1.goto(-30,130)
tort1.goto(30,130)
tort1.goto(0,180)
tort1.end_fill()
def m4():
tort2.penup()
tort2.goto(60,180)
tort2.pendown()
tort2.begin_fill()
tort2.goto(90,130)
tort2.goto(30,130)
tort2.goto(60,180)
tort2.end_fill()
t=threading.Thread(target=m3)
t.daemon=True
t.start()
t2=threading.Thread(target=m4)
t2.daemon=True
t2.start()
time.sleep(2)
tort1.penup()
tort2.penup()
tort1.pencolor("#0000FF")
tort2.pencolor("#0000FF")
def m5():
tort1.goto(-150,60)
tort1.write('Woooooow manejando tortugas', font=("Times New Roman", 20, "bold"))
def m6():
tort2.goto(-80,30)
tort2.write('al mismo tiempo :O', font=("Times New Roman", 20, "bold"))
t=threading.Thread(target=m5)
t.daemon=True
t.start()
t2=threading.Thread(target=m6)
t2.daemon=True
t2.start()
turtle.done()
Captura:
Practica personal con hilos en la trifuerza:
ADVERTENCIA: Al manejar una cantidad de hilos mayor tiende a fallar.
import time
import turtle
tort1=turtle.Turtle()
tort2=turtle.Turtle()
#tipos de shape: arrow, turtle, circle, square, triangle, classic
#tort1.hideturtle()
#tort2.hideturtle()
tort1.speed(3)
tort2.speed(3)
tort1.pensize(2)
tort1.pencolor("#FFF715")
tort1.fillcolor("#FCFF00")
tort2.pensize(2)
tort2.pencolor("#FFF715")
tort2.fillcolor("#FCFF00")
def m1():
tort1.begin_fill()
tort1.penup()
tort1.sety(180)
tort1.pendown()
tort1.goto(30,230)
tort1.goto(60,180)
tort1.goto(0,180)
tort1.end_fill()
def m2():
tort2.begin_fill()
tort2.penup()
tort2.sety(180)
tort2.pendown()
tort2.goto(60,180)
tort2.goto(30,230)
tort2.goto(0,180)
tort2.end_fill()
t=threading.Thread(target=m1)
t.daemon=True
t.start()
t2=threading.Thread(target=m2)
t2.daemon=True
t2.start()
time.sleep(2)
def m3():
tort1.begin_fill()
tort1.goto(-30,130)
tort1.goto(30,130)
tort1.goto(0,180)
tort1.end_fill()
def m4():
tort2.penup()
tort2.goto(60,180)
tort2.pendown()
tort2.begin_fill()
tort2.goto(90,130)
tort2.goto(30,130)
tort2.goto(60,180)
tort2.end_fill()
t=threading.Thread(target=m3)
t.daemon=True
t.start()
t2=threading.Thread(target=m4)
t2.daemon=True
t2.start()
time.sleep(2)
def m5():
tort1.penup()
tort1.goto(-30,130)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-60,80)
tort1.goto(0,80)
tort1.goto(-30,130)
tort1.end_fill()
def m6():
tort2.penup()
tort2.goto(90,130)
tort2.pendown()
tort2.begin_fill()
tort2.goto(60,80)
tort2.goto(120,80)
tort2.goto(90,130)
tort2.end_fill()
t=threading.Thread(target=m5)
t.daemon=True
t.start()
t2=threading.Thread(target=m6)
t2.daemon=True
t2.start()
time.sleep(2)
def m7():
tort1.penup()
tort1.goto(-60,80)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-90,30)
tort1.goto(-30,30)
tort1.goto(-60,80)
tort1.end_fill()
def m8():
tort2.penup()
tort2.goto(120,80)
tort2.pendown()
tort2.begin_fill()
tort2.goto(90,30)
tort2.goto(150,30)
tort2.goto(120,80)
tort2.end_fill()
t=threading.Thread(target=m7)
t.daemon=True
t.start()
t2=threading.Thread(target=m8)
t2.daemon=True
t2.start()
time.sleep(2)
def m9():
tort1.penup()
tort1.goto(0,80)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-30,30)
tort1.goto(30,30)
tort1.goto(0,80)
tort1.end_fill()
def m10():
tort2.penup()
tort2.goto(60,80)
tort2.pendown()
tort2.begin_fill()
tort2.goto(90,30)
tort2.goto(30,30)
tort2.goto(60,80)
tort2.end_fill()
t=threading.Thread(target=m9)
t.daemon=True
t.start()
t2=threading.Thread(target=m10)
t2.daemon=True
t2.start()
time.sleep(2)
def m11():
tort1.penup()
tort1.setx(-30)
tort1.goto(-90,30)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-125,-30)
tort1.goto(-60,-30)
tort1.goto(-90,30)
tort1.end_fill()
def m12():
tort2.penup()
tort2.setx(120)
tort2.goto(150,30)
tort2.pendown()
tort2.begin_fill()
tort2.goto(185,-30)
tort2.goto(120,-30)
tort2.goto(150,30)
tort2.end_fill()
t=threading.Thread(target=m11)
t.daemon=True
t.start()
t2=threading.Thread(target=m12)
t2.daemon=True
t2.start()
time.sleep(2)
def m13():
tort1.penup()
tort1.goto(-125,-30)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-160,-90)
tort1.goto(-95,-90)
tort1.goto(-125,-30)
tort1.end_fill()
def m14():
tort2.penup()
tort2.goto(185,-30)
tort2.pendown()
tort2.begin_fill()
tort2.goto(220,-90)
tort2.goto(155,-90)
tort2.goto(185,-30)
tort2.end_fill()
t=threading.Thread(target=m13)
t.daemon=True
t.start()
t2=threading.Thread(target=m14)
t2.daemon=True
t2.start()
time.sleep(2)
def m15():
tort1.penup()
tort1.goto(-60,-30)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-30,-90)
tort1.goto(-95,-90)
tort1.goto(-60,-30)
tort1.end_fill()
def m16():
tort2.penup()
tort2.setx(120)
tort2.pendown()
tort2.begin_fill()
tort2.goto(155,-90)
tort2.goto(90,-90)
tort2.goto(120,-30)
tort2.end_fill()
t=threading.Thread(target=m15)
t.daemon=True
t.start()
t2=threading.Thread(target=m16)
t2.daemon=True
t2.start()
time.sleep(2)
def m17():
tort1.penup()
tort1.setx(-125)
tort1.goto(-160,-90)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-195,-150)
tort1.goto(-130,-150)
tort1.goto(-160,-90)
tort1.end_fill()
def m18():
tort2.penup()
tort2.setx(180)
tort2.goto(220,-90)
tort2.pendown()
tort2.begin_fill()
tort2.goto(255,-150)
tort2.goto(190,-150)
tort2.goto(220,-90)
tort2.end_fill()
t=threading.Thread(target=m17)
t.daemon=True
t.start()
t2=threading.Thread(target=m18)
t2.daemon=True
t2.start()
time.sleep(2)
def m19():
tort1.penup()
tort1.goto(-195,-150)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-230,-210)
tort1.goto(-165,-210)
tort1.goto(-195,-150)
tort1.end_fill()
def m20():
tort2.penup()
tort2.goto(255,-150)
tort2.pendown()
tort2.begin_fill()
tort2.goto(288,-210)
tort2.goto(225,-210)
tort2.goto(255,-150)
tort2.end_fill()
t=threading.Thread(target=m19)
t.daemon=True
t.start()
t2=threading.Thread(target=m20)
t2.daemon=True
t2.start()
time.sleep(2)
def m21():
tort1.penup()
tort1.setx(-130)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-165,-210)
tort1.goto(-100,-210)
tort1.goto(-130,-150)
tort1.end_fill()
def m22():
tort2.penup()
tort2.setx(190)
tort2.pendown()
tort2.begin_fill()
tort2.goto(160,-210)
tort2.goto(225,-210)
tort2.goto(190,-150)
tort2.end_fill()
t=threading.Thread(target=m21)
t.daemon=True
t.start()
t2=threading.Thread(target=m22)
t2.daemon=True
t2.start()
time.sleep(2)
def m23():
tort1.penup()
tort1.goto(-100,-210)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-65,-150)
tort1.goto(-35,-210)
tort1.goto(-100,-210)
tort1.end_fill()
def m24():
tort2.penup()
tort2.goto(160,-210)
tort2.pendown()
tort2.begin_fill()
tort2.goto(95,-210)
tort2.goto(125,-150)
tort2.goto(160,-210)
tort2.end_fill()
t=threading.Thread(target=m23)
t.daemon=True
t.start()
t2=threading.Thread(target=m24)
t2.daemon=True
t2.start()
time.sleep(2)
def m25():
tort1.penup()
tort1.goto(-100,-210)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-30,-90)
tort1.goto(0,-150)
tort1.goto(-65,-150)
tort1.end_fill()
def m26():
tort2.penup()
tort2.goto(125,-150)
tort2.pendown()
tort2.begin_fill()
tort2.goto(60,-150)
tort2.goto(90,-90)
tort2.goto(125,-150)
tort2.end_fill()
t=threading.Thread(target=m25)
t.daemon=True
t.start()
t2=threading.Thread(target=m26)
t2.daemon=True
t2.start()
time.sleep(2)
def m27():
tort1.penup()
tort1.setx(0)
tort1.pendown()
tort1.begin_fill()
tort1.goto(-35,-210)
tort1.goto(30,-210)
tort1.goto(0,-150)
tort1.end_fill()
def m28():
tort2.penup()
tort2.setx(60)
tort2.pendown()
tort2.begin_fill()
tort2.goto(95,-210)
tort2.goto(30,-210)
tort2.goto(60,-150)
tort2.end_fill()
t=threading.Thread(target=m27)
t.daemon=True
t.start()
t2=threading.Thread(target=m28)
t2.daemon=True
t2.start()
turtle.done()
Captura:
Practica en clase (3 figuras preguntando el color):
import turtle
import tkSimpleDialog
t=turtle.Turtle()
fondo=turtle.Screen()
fondo.bgcolor('#B400FF')
#t.speed(100)
def colores():
c1=tkSimpleDialog.askstring("Color","Escribe el color del lapiz:")
c2=tkSimpleDialog.askstring("Color","Escribe el color del relleno:")
return t.color(c1, c2)
# Comienza el triangulo
t.pensize(2)
colores()
t.begin_fill()
for _ in xrange(3):
t.fd(100)
t.left(120)
t.end_fill()
# Comienza el molino de viento
t.penup()
t.goto(40,100)
t.pendown()
t.pencolor('black')
t.pensize(4)
t.goto(40,220)
t.pensize(1)
colores()
t.begin_fill()
for i in range(30):
t.goto(40,220)
t.forward(100)
t.right(150)
for j in range(1):
t.forward(100)
t.right(145)
t.end_fill()
# Comienza la estrella
t.penup()
t.goto(80,-130)
colores()
t.begin_fill()
t.pendown()
for i in range(30):
t.forward(100)
t.right(150)
for j in range(1):
t.forward(100)
t.right(145)
t.penup()
t.hideturtle()
t.goto(175,220)
t.pencolor('white')
t.write('Molino de viento', font=("Times New Roman", 20, "bold"))
t.goto(215,40)
t.write('Triangulo', font=("Times New Roman", 20, "bold"))
t.goto(230,-100)
t.write('Estrella', font=("Times New Roman", 20, "bold"))
turtle.done()
Capturas:
Ejercicios de turtle:
Pagina web de los ejercicios: http://www.mclibre.org/consultar/python/lecciones/python-turtle-1.html
Código #1:
from turtle import *
setup(640, 480, 0, 0)
done()
Captura:
Código #2:
from turtle import *
setup(450, 150, 0, 0)
title("Ejemplo de ventana")
done()
Captura:
Código #3:
from turtle import *
setup(250, 100, 0, 0)
title("Ejemplo de ventana")
hideturtle()
dot(10, 0, 0, 0)
setup(450, 150, 0, 0)
done()
Captura:
Código #4:
from turtle import *
setup(450, 150, 0, 0)
screensize(10, 10)
done()
Captura:
Código #5:
from turtle import *
setup(250, 100, 0, 0)
screensize(100, 100)
hideturtle()
dot(10, 0, 0, 0)
screensize(200, 100)
done()
Captura:
Código #6:
from turtle import *
setup(450, 150, 0, 0)
screensize(300, 150)
showturtle()
done()
Captura:
Código #7:
from turtle import *
setup(450, 150, 0, 0)
screensize(300, 150)
goto(100, 0)
done()
Captura:
Código #8:
from turtle import *
setup(450, 200, 0, 0)
screensize(300, 150)
goto(100, 50)
goto(100, -50)
goto(50, -50)
done()
Captura:
Código # 9:
from turtle import *
setup(450,
200, 0, 0)
screensize(300,
150)
goto(100,
50)
pensize(4)
goto(100,
-50)
pensize(8)
goto(50,
-50)
done()
Captura:
Código #10:
from turtle
import *
setup(450,
200, 0, 0)
screensize(300,
150)
colormode(255)
pencolor(128,
0, 0)
goto(100,
50)
pencolor(0, 128, 0)
goto(100, -50)
pencolor(0, 0, 128)
goto(50, -50)
done()
Captura:
Código #11:
from turtle
import *
setup(450,
200, 0, 0)
screensize(300,
150)
colormode(255)
goto(100,
50)
dot(10,
255, 0, 0)
goto(100,
-50)
dot(10, 0,
255, 0)
goto(50,
-50)
dot(10, 0,
0, 255)
goto(0,0)
done()
Captura:
Código #12:
from turtle
import *
setup(450,
200, 0, 0)
screensize(300,
150)
colormode(255)
penup()
goto(100,
50)
dot(10,
255, 0, 0)
goto(100,
-50)
dot(10, 0, 255,
0)
goto(50,
-50)
dot(10, 0,
0, 255)
goto(0,0)
done()
Captura:
Código #13:
from turtle
import *
setup(450,
200, 0, 0)
screensize(300,
150)
hideturtle()
pensize(5)
fillcolor("red")
begin_fill()
goto(100,
0)
goto(100,
50)
goto(0, 50)
goto(0, 0)
end_fill()
done()
Captura:
Código #14:
from turtle
import *
setup(450,
200, 0, 0)
screensize(300,
150)
hideturtle()
pensize(5)
fillcolor("red")
begin_fill()
goto(100,
0)
goto(100,
50)
goto(0, 50)
end_fill()
done()
Captura:
Código #15:
from turtle
import *
setup(450,
200, 0, 0)
screensize(300,
150)
hideturtle()
pensize(5)
fillcolor("blue")
begin_fill()
goto(50,
50)
goto(100,
-50)
goto(150,
0)
goto(0, 0)
end_fill()
done()
Captura:
Código #16:
from turtle
import *
setup(450,
200, 0, 0)
screensize(300,
150)
hideturtle()
pensize(5)
fillcolor("blue")
begin_fill()
goto(0, 75)
goto(100,
0)
goto(100,
75)
end_fill()
done()
Captura:
Código #17:
from turtle
import *
setup(450,
200, 0, 0)
screensize(300,
150)
hideturtle()
pensize(5)
fillcolor("blue")
begin_fill()
goto(75, 0)
goto(75,
75)
end_fill()
penup()
goto(-100,
75)
pendown()
begin_fill()
goto(-100,0)
goto(-25,
0)
end_fill()
done()
Código #18:
from turtle
import *
setup(450,
200, 0, 0)
screensize(300,
150)
hideturtle()
pensize(5)
fillcolor("blue")
begin_fill()
goto(75, 0)
goto(75,
75)
goto(0,0)
end_fill()
penup()
goto(-100,
75)
pendown()
begin_fill()
goto(-100,0)
goto(-25,
0)
goto(-100,75)
end_fill()
done()
Captura:
Comentarios
Publicar un comentario