Python - Turtle
Turtle nos permite crear dibujos utilizando una "tortuga" que funciona como un lápiz virtual, permitiéndonos entre otras mas funciones, movernos en 4 posiciones: atrás, adelante, izquierda y derecha.
Programa 1
from turtle import*
t=Turtle()
screen=t.getscreen()
shape("turtle")
t.penup()
t.write("inicio en 0,0")
t.goto(100,100)
t.write("Esta en 100,100")
t.goto(-100,-100)
t.write("Esta en -100,-100")
t.goto(100,-100)
t.write("Esta en 100,-100")
t.goto(-100,100)
t.write("Esta en -100,100")
screen.exitonclick()
t=Turtle()
screen=t.getscreen()
shape("turtle")
t.penup()
t.write("inicio en 0,0")
t.goto(100,100)
t.write("Esta en 100,100")
t.goto(-100,-100)
t.write("Esta en -100,-100")
t.goto(100,-100)
t.write("Esta en 100,-100")
t.goto(-100,100)
t.write("Esta en -100,100")
screen.exitonclick()
Programa 2
from turtle import*
t=Turtle()
screen=t.getscreen()
setup(450,150,0,0)
title("Tortuga Larissa")
screensize(300,300)
screen.exitonclick()
t=Turtle()
screen=t.getscreen()
setup(450,150,0,0)
title("Tortuga Larissa")
screensize(300,300)
screen.exitonclick()
Programa 3
lari=Turtle()
screen=lari.getscreen()
shape("turtle")
lari.goto(57,37)
lari.goto(-100,17)
lari.goto(-50,60)
lari.goto(50,60)
screen.exitonclick()
Programa 4
from turtle import*
l=Turtle()
screen=l.getscreen()
setup(450,200,0,0)
screensize(400,200)
l.forward(50) #Avanza desde el punto del origen
l.backward(-100) #Retrocede desde el valor anterior
screen.exitonclick()
l=Turtle()
screen=l.getscreen()
setup(450,200,0,0)
screensize(400,200)
l.forward(50) #Avanza desde el punto del origen
l.backward(-100) #Retrocede desde el valor anterior
screen.exitonclick()
Programa 5
t=Turtle()
screen=t.getscreen()
setup(450,200,0,0)
screensize(400,200)
#TRIANGULO
"""
t.forward(80)
t.right(120)
t.forward(80)
t.right(120)
t.forward(80)
t.backward(80)
t.write("Tan tan, es un TRIANGULO!")
screen.exitonclick()
"""
#LO MISMO PERO CON FOR
lados=8
distancia=80
angulo=(360/lados)
for c in range(lados):
t.forward(distancia)
t.right(angulo)
lados=8
distancia=80
angulo=(360/lados)
for c in range(lados):
t.forward(distancia)
t.right(angulo)
screen.exitonclick()
Programa 6
from turtle import*
t=Turtle()
screen=t.getscreen()
setup(450,200,0,0)
screensize(400,180)
t.circle(20)
t.left(90)
t.forward(50)
#RADIO Y LA MEDIDA
t.circle(50,200)
t.left(90)
t.forward(50)
#RADIO, MEDIDA, LADOS
t.circle(50,360,12)
#RESISTENCIA, PROYECTO
#t.circle(50,180,50)
screen.exitonclick()
Programa 7
from turtle import*
t=Turtle()
screen=getscreen()
setup(640,480,0,0)
screensize(600,500)
t.pencolor()
t.color("blue","purple")
t.begin_fill()
t.circle(80)
t.end_fill()
t.penup()
t.goto(100,200)
t.pendown()
t.write("Programacion visual", True, "center", ("Arial",32,"bold"))
screen.exitonclick()
Programa 8
t=Turtle()
def princ():
#PONER UN CIRCULO
title("Hola Mundo Tardio")
setup(1000,1000,0,0)
penup()
t.goto(0,0)
t.color("navy")
t.write("Hola mundo!!!", font=("Times New Roman",36,"bold"))
hideturtle()
princ()
exitonclick()
Programa 9
from turtle import*
t=Turtle()
screen=t.getscreen()
setup(450,150,0,0)
screensize(300,150)
title("www.ita.mx")
nombre=textinput("Nombre", "Cual es tu nombre?")
edad=numinput("Edad", "Cual es tu edad?")
write("Su nombre es: " +(nombre) + ", y tu edad es: " +str(edad))
screen.exitonclick()
Programa 10
from turtle import*
t=Turtle()
screen=t.getscreen()
setup(450,150,0,0)
screensize(300,200)
title("www.ita.mx")
edad=numinput("edad","Cual es tu edad?", 20,0,100)
write("Su edad es "+str(edad))
screen.exitonclick()
Programa 11
t=Turtle()
screen=t.getscreen()
setup(250,150,0,0)
screensize(300,150)
title("www.ita.mx")
size=int(numinput("Modulo turtle","Tamaño del dibujo (10-200): ",100,10,200))
t.penup()
t.goto(size//2, size//2)
t.pendown()
t.goto(-size//2, size//2) # // DIVISION ENTERA
t.goto(-size//2, -size//2)
t.goto(size//2, -size//2)
t.goto(size//2, size//2)
screen.exitonclick()
Programa 12
s=turtle.getscreen()
t=turtle.Pen()
turtle.bgcolor("black")
colores=["red","yellow","blue","green"]
nombre=turtle.textinput("Captura","tu nombre?")
for x in range(10):
t.pencolor(colores[x%4])
t.penup()
t.forward(x*4)
t.pendown()
t.pencolor(colores[x%4])
t.penup()
t.forward(x*4)
t.pendown()
t.write(nombre, font=("Arial", int(x)))
t.left(9)
s.exitonclick()
t.left(9)
s.exitonclick()
Programa 13
from turtle import*
t=Turtle()
screen=t.getscreen()
setup(450, 200, 0, 0)
screensize(300, 150)
colormode(255)
t.penup()
t.goto(100,50)
#funcion dot(grosor, color) color (rgb) 0-255
#grosor en pixeles y color en base a RGB
t.dot(10,255,0,0)
t.penup()
t.goto(100, -50)
t.dot(10,0,255,0)
t.penup()
screen.exitonclick()
t=Turtle()
screen=t.getscreen()
setup(450, 200, 0, 0)
screensize(300, 150)
colormode(255)
t.penup()
t.goto(100,50)
#funcion dot(grosor, color) color (rgb) 0-255
#grosor en pixeles y color en base a RGB
t.dot(10,255,0,0)
t.penup()
t.goto(100, -50)
t.dot(10,0,255,0)
t.penup()
screen.exitonclick()
Programa 14
from turtle import*
t=Turtle()
screen=t.getscreen()
setup(800,600,0,0)
t.dot()
t.fd(50)
t.color("blue")
t.fd(50)
t.dot(20,"pink")
print("rosa")
t.rt(30)
t.fd(50)
t.dot(30,"blue")
t.left(30)
t.fd(50)
t.home() #CASA
print("Azul")
screen.exitonclick()
t=Turtle()
screen=t.getscreen()
setup(800,600,0,0)
t.dot()
t.fd(50)
t.color("blue")
t.fd(50)
t.dot(20,"pink")
print("rosa")
t.rt(30)
t.fd(50)
t.dot(30,"blue")
t.left(30)
t.fd(50)
t.home() #CASA
print("Azul")
screen.exitonclick()
Programa 15
t=Turtle()
a=Turtle()
screen=t.getscreen()
setup(800,600,0,0)
a.shape("turtle")
t.shape("arrow")
t.dot()
t.fd(50)
t.color("blue")
t.fd(50)
t.dot(20,"pink")
t.position()
t.rt(30)
t.fd(50)
t.dot(30,"blue")
t.left(30)
t.fd(50)
t.home() #0,0
print(t.position())
a.color("blue")
a.fd(50)
a.stamp()
a.clearstamps()
#parece que no hace nada
screen.exitonclick()
a.color("blue")
a.fd(50)
a.stamp()
a.clearstamps()
#parece que no hace nada
screen.exitonclick()
Programa 16
t=Turtle()
a=Turtle()
screen=t.getscreen()
setup(800,600,0,0)
# shape("turtle") #SOLO LA PRIMERA TORTUGA
a.shape("turtle")
a.penup()
a.goto(0,-100)
for i in range(8):
t.stamp(); t.fd(30)
a.stamp(); a.fd(30)
t.stamp(); t.fd(30)
a.stamp(); a.fd(30)
#t.clearstamps(2)
#t.clearstamps(-2)
#t.clearstamps()
#SI NO TIENE PARAMETRO EN N DE clearstamp() BORRA TODAS LAS STAMP
#SI n>0 BORRA LOS PRIMEROS SEÑALADOS
#SI n ES MENOR QUE CERO, BORRA LOS ULTIMOS SEÑALADOS
screen.exitonclick()
#t.clearstamps(-2)
#t.clearstamps()
#SI NO TIENE PARAMETRO EN N DE clearstamp() BORRA TODAS LAS STAMP
#SI n>0 BORRA LOS PRIMEROS SEÑALADOS
#SI n ES MENOR QUE CERO, BORRA LOS ULTIMOS SEÑALADOS
screen.exitonclick()
Programa 17
t=Turtle()
a=Turtle()
screen=t.getscreen()
setup(800,600,0,0)
for i in range(4):
t.fd(100)
t.rt(90)
t.color("red")
t.fillcolor("red")
t.begin_fill()
t.fd(100)
t.rt(90)
t.color("red")
t.fillcolor("red")
t.begin_fill()
for i in range(4):
t.fd(100)
t.rt(90)
t.end_fill()
speed(1)
colormode(225)
#a.fillcolor(0,225,0)
a.shape("turtle")
a.begin_fill()
t.fd(100)
t.rt(90)
t.end_fill()
speed(1)
colormode(225)
#a.fillcolor(0,225,0)
a.shape("turtle")
a.begin_fill()
for i in range(4):
a.fd(100)
a.stamp()
a.rt(90)
a.end_fill()
screen.exitonclick()
a.fd(100)
a.stamp()
a.rt(90)
a.end_fill()
screen.exitonclick()
Programa 18
#ESPIRAL
import turtle
t=turtle.Pen()
screen=t.getscreen()
import turtle
t=turtle.Pen()
screen=t.getscreen()
for x in range(100):
t.fd(x)
t.lt(90)
screen.exitonclick()
t.fd(x)
t.lt(90)
screen.exitonclick()
Programa 19
t=Turtle()
screen=t.getscreen()
setup(450,150,0,0)
lados=numinput("numero", "De lados")
l=int(lados)
cl=["red","blue","green","gray","black","yellow","red","blue","gress","gray","black"]
speed(1)
shape("turtle")
pencolor("red")
pensize(5)
for count in range(10):
pencolor(cl[count])
#penup()
t.forward(10)
#pendown()
forward(20)
screen.exitonclick()
Programa 20
pv=Turtle()
lari=Turtle()
screen=pv.getscreen()
setup(450,400,0,0)
speed(5)
pv.forward(100)
lari.backward(100)
pv.lt(90)
lari.rt(90)
pv.fd(100)
lari.backward(100)
pv.left(90)
lari.right(90)
pv.forward(100)
lari.backward(100)
pv.left(90)
pv.right(90)
screen.exitonclick()
Programa 21
import turtle
turtle.setup(800,600)
t=turtle.Screen()
t.bgcolor("black")
t.title("Espiral in purpĺe")
a=turtle.Turtle()
a.shape("turtle")
a.color("purple")
a.penup()
size=20
for i in range(80):
a.stamp()
size=size+3
a.forward(size)
a.right(24)
a.stamp()
size=size+3
a.forward(size)
a.right(24)
t.exitonclick()
Programa 22
t=Turtle()
screen=t.getscreen()
setup(450,200,0,0)
screensize(400,200)
t.resizemode("user")
t.shapesize(4,4,5)
t.shape("turtle")
t.speed(1)
t.fd(200)
t.fd(100)
t.tilt(30)
t.forward(50)
t.tilt(30)
t.forward(150)
screen.exitonclick()
#tilt(angulo) rota la forma de la tortuga en determinado angulo
#desde su actual angulo de inclinacion, pero no cambia la direccion
Programa 23
from turtle import*
t=Turtle()
screen=t.getscreen()
shape("turtle")
t.penup()
t.begin_fill()
t.color("pink")
t.goto(30,-150)
t.circle(130)
t.penup()
t.end_fill()
t.color("white")
t.goto(0,0)
t.begin_fill()
t.pendown()
t.circle(20)
t.penup()
t.end_fill()
t.color("blue")
t.pendown()
t.circle(10)
t.penup()
t.end_fill()
t.forward(60)
t.right(45)
t.begin_fill()
t.color("white")
t.pendown()
t.circle(20)
t.penup()
t.end_fill()
t.right(45)
t.begin_fill()
t.color("white")
t.pendown()
t.circle(20)
t.penup()
t.end_fill()
t.begin_fill()
t.color("blue")
t.pendown()
t.circle(10)
t.penup()
t.end_fill()
t.color("blue")
t.pendown()
t.circle(10)
t.penup()
t.end_fill()
t.right(90)
t.forward(90)
t.begin_fill()
t.color("brown")
t.pendown()
t.circle(40)
t.pendown()
t.circle(40)
t.penup()
end_fill()
t.goto(25,-25)
t.forward(90)
t.begin_fill()
t.color("brown")
t.pendown()
t.circle(40)
t.pendown()
t.circle(40)
t.penup()
end_fill()
t.goto(25,-25)
screen.exitonclick()
Programa 24
t=Turtle()
screen=t.getscreen()
setup(450,200,0,0)
screensize(400,200)
tp=t.pos()
print(tp)
t.setpos(60,30)
tp=t.pos()
print(tp)
screen.exitonclick()
Programa 25
from turtle import*
t=Turtle()
t.shape("turtle")
lista_color=["black","blue","purple","green"]
t.left(90)
for color in lista_color:
t.forward(20)
t.color(color)
t.write("Que color ahora?")
t.forward(20)
t.color(color)
t.write("Que color ahora?")
exitonclick()
Programa 26
#OVALOS DE DOS COLORES
from turtle import*
t=Turtle()
screen=t.getscreen()
setup(400,300,0,0)
screensize(150,150)
t.penup()
t.goto(10,-150)
t.pendown()
shape("circle")
shapesize(2,1,1)
fillcolor("pink")
from turtle import*
t=Turtle()
screen=t.getscreen()
setup(400,300,0,0)
screensize(150,150)
t.penup()
t.goto(10,-150)
t.pendown()
shape("circle")
shapesize(2,1,1)
fillcolor("pink")
t.penup()
t.goto(30,0)
t.pendown()
t.shape("circle")
t.shapesize(2,1,1) #vertical, horizontal, grosor
t.fillcolor("black")
#t.reset()
exitonclick()
t.goto(30,0)
t.pendown()
t.shape("circle")
t.shapesize(2,1,1) #vertical, horizontal, grosor
t.fillcolor("black")
#t.reset()
exitonclick()
Programa 27
from turtle import*
t=Turtle()
screen=t.getscreen()
setup(450,200,0,0)
screensize(400,200)
t.setpos(60,30)
tp=t.pos()
print(tp)
print(t.position())
t.setx(10)
print(t.position())
t.sety(-10)
print(t.position())
t=Turtle()
screen=t.getscreen()
setup(450,200,0,0)
screensize(400,200)
t.setpos(60,30)
tp=t.pos()
print(tp)
print(t.position())
t.setx(10)
print(t.position())
t.sety(-10)
print(t.position())
"""
SE ORIENTA LA TORTUGA EN UN ANGULO, AQUI LAS DIRECCIONES:
0-east 0 north 90 north 90 east 180 west 180 south 270 south
"""
t.setheading(90)
print(t.heading())
t.home()
print(t.position())
SE ORIENTA LA TORTUGA EN UN ANGULO, AQUI LAS DIRECCIONES:
0-east 0 north 90 north 90 east 180 west 180 south 270 south
"""
t.setheading(90)
print(t.heading())
t.home()
print(t.position())
for i in range(4):
t.fd(50); t.lt(80)
t.fd(50); t.lt(80)
for i in range(8):
t.undo()
t.undo()
t.pendown()
t.pd()
t.down()
#DRAWING DE MOVING
t.penup()
t.pu()
t.up()
#PENUP NO GRAWING WHEN MOVING
t.pensize(width=None)
t.width(width=None)
t.write("casa es =", True, align="center")
#t.write()
t.pd()
t.down()
#DRAWING DE MOVING
t.penup()
t.pu()
t.up()
#PENUP NO GRAWING WHEN MOVING
t.pensize(width=None)
t.width(width=None)
t.write("casa es =", True, align="center")
#t.write()
exitonclick()
- Numpy = http://ind-programacion.blogspot.mx/2018/04/python-numpy.html
- Función "if" = http://ind-programacion.blogspot.mx/2018/04/python-ciclo-if.html
- Función "for" = http://ind-programacion.blogspot.mx/2018/04/python-ciclo-for.html
- Función "while" = http://ind-programacion.blogspot.mx/2018/04/python-ciclo-while.html
- Graficas y cadenas = http://ind-programacion.blogspot.mx/2018/04/python-graficas-y-cadenas.html
- Funciones recursivas = http://ind-programacion.blogspot.mx/2018/04/python-funciones-recursivas.html
- Operaciones con números imaginarios = http://ind-programacion.blogspot.mx/2018/04/python-numeros-complejos.html

































Comentarios
Publicar un comentario