Ir al contenido principal

Programa Unidad 4

En esta entrada tenemos una serie de programas cuya principal función es demostrar las habilidades de la librería turtle, y como se puede utilizar para dibujar objetos.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#1

#mueve al apuntador de byte indicado
#archivo=open("C:/Users/Mario/Documents/","r")
#programa que 
archivo=open("prueba.txt","r")
contenido=archivo.read()
print(contenido)
archivo.seek(0)
archivo.close()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#2

#programa que imprime la primer linea del archivo
archivo=open("prueba.txt","r")
#linea1=archivo.readline()
for linea in archivo.readlines():
print(linea)

#print(linea1)
archivo.close()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#3

with open("prueba.txt","r") as arch:
contenido=arch.read()
print(contenido)
print(arch.closed)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#4

#agregar lineas al archivo
archivo=open("prueba.txt","a+")
contenido=archivo.read()
final=archivo.tell()

archivo.write('Nueva linea :)')
archivo.seek(final)
nuevo=archivo.read()
print(nuevo)

archivo.close()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#5

archivo=open("prueba.txt","a+")
archivo.write("Ejercicio")
contenido=archivo.read()
print(contenido)
archivo.close()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#6

from turtle import *
t=Turtle()
screen=t.getscreen()
#paso uno
home()
#paso dos
shape("turtle")
#shape("arrow")
#shape("classic")
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#7

from turtle import *
t=Turtle()
screen=t.getscreen()
t.left(90)
t.forward(200)
t.right(90)
t.forward(200)
t.right(90)
t.forward(200)
t.right(90)
t.forward(200)
t.right(90)
t.forward(200)
t.right(90)
t.forward(200)

t.penup()

t.home()
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#8

from turtle import *
t=Turtle()
screen=t.getscreen()
setup(450,100,0,)
#screensize(300,150)
title("Programacion Visual")
#t.showturtle()

t.goto(100,0)
dot(10,0,0,0)
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#9

from turtle import *
t=Turtle()
screen=t.getscreen()
shape("turtle")
t.penup()
t.goto(0,0)
t.write("inicio en 0,0")
t.goto(100,100)
t.write("Esta en 100,100")
t.goto(-100,-100)
t.write("Ahora en -100,-100")
t.goto(100,-100)
t.write("100,-100")
t.goto(80,-120)
t.write("80,-120")

screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#10

from turtle import *
t=Turtle()
screen=t.getscreen()
setup(450,150,0,0)
title("Tortuga Felix")
screensize(300,300)
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#11

from turtle import *
z=Turtle()
screen=z.getscreen()
shape("turtle")
z.goto(57,37)
z.goto(-100,17)
z.goto(-50,60)
z.goto(50,60)
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#12

from turtle import *
a=Turtle()
screen=a.getscreen()
setup(450,200,0,0)
screensize(400,200)
a.forward(50)
a.backward(100)
a.backward(-50)
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#13

from turtle import *
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")
l=4
d=80
ang=360/l
t.penup()
t.goto(10,10)
t.pendown()
for c in range(l):
t.forward(d)
t.right(ang)
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#14

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?",19,0,100)
write("Su edad es "+str(edad))
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#15

from turtle import *
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)
t.goto(-size//2,-size//2)
t.goto(size//2,-size//2)
t.goto(size//2,size//2)

screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#16

import turtle
t=turtle.Pen()
screen=t.getscreen()
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.write(nombre,font=("Arial",int(x+4/4),"bold"))
t.left(9)
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#17

from turtle import *
t=Turtle()
screen=t.getscreen()
setup(450,200,0,0)
screensize(300,150)
colormode(255)
t.penup()
t.goto(100,50)
t.dot(30,255,0,0)
t.penup()
t.goto(100,0)
t.dot(30,255,255,0)
t.penup()
t.goto(100,-50)
t.dot(30,0,255,0)
t.penup()
t.goto(150,-200)
t.pendown()
t.right(280)
t.circle(50,200)
t.left(80)
t.forward(100)
t.penup()
t.goto(110,-143)
t.left(90)
t.pendown()
t.forward(50)
t.right(90)
t.forward(50)
t.left(90)
t.forward(200)
t.left(90)
t.forward(120)
t.left(90)
t.forward(200)
t.left(90)
t.forward(50)
t.right(90)
t.forward(50)
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#18

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()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#19

from turtle import *
t=Turtle()
a=Turtle()
screen=t.getscreen()
setup(800,600,0,0)
a.shape("turtle")
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()

print(t.position())
a.color("Blue")
a.fd(50)
a.stamp()
a.fd(30)
a.clearstamps()
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#20

from turtle import *
t=Turtle()
a=Turtle()
screen=t.getscreen()
setup(800,600,0,0)
a.shape("turtle")
a.penup()
a.goto(0,-100)
for i in range(8):
t.stamp(); t.fd(30)
a.stamp(); a.fd(30)
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#21

from turtle import *
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()
for i in range(4):
t.fd(100)
t.rt(90)
t.end_fill()
speed(1)
colormode(255)
a.fillcolor(227,207,87)
a.shape("turtle")
a.begin_fill()
for i in range(4):
a.fd(100)
a.stamp()
a.rt(90)
a.end_fill()
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#22

from turtle import *
py=Turtle()
r=Turtle()
screen=py.getscreen()
setup(450,400,0,0)
speed(5)
py.fd(100)
r.backward(100)
py.lt(90)
r.rt(90)
py.fd(100)
r.backward(100)
py.lt(90)
r.rt(90)
py.fd(100)
r.backward(100)
py.lt(90)
py.rt(90)
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#23

import turtle
turtle.setup(800,600)
t=turtle.Screen()
t.bgcolor("Black")
t.title("Spiral")
a=turtle.Turtle()
a.shape("turtle")
a.color("Red")
a.penup()
size=20
for i in range(40):
a.stamp()
size=size+3
a.forward(size)
a.rt(24)
t.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#24

from turtle import *
t=Turtle()
screen=t.getscreen()
setup(1440,720,0,0)
t.resizemode("user")
t.shapesize(4,4,5)
t.shape("turtle")
t.fd(200)
t.fd(100)
t.tilt(30)
t.fd(50)
t.tilt(30)
t.fd(150)
screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#25

from turtle import *
t=Turtle()
screen=t.getscreen()
shape("turtle")
t.begin_fill()
t.color('pink')
t.penup()
t.goto(30,-150)
t.pendown()
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.begin_fill()
t.color('blue')
t.pendown()
t.circle(10)
t.penup()
t.end_fill()

t.fd(60)
t.rt(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.rt(90)
t.fd(90)
t.begin_fill()
t.color('maroon')
t.pendown()
t.circle(40)
t.pendown()
t.circle(40)
t.penup()
t.end_fill()
t.goto(25,-25)

screen.exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#26

from turtle import *
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()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#27

#Colores de la tortuga
from turtle import *
t=Turtle()
t.shape('turtle')

lista_color=["black","blue","purple","green"]

t.left(90)

for color in lista_color:
t.fd(20)
t.color(color)
t.write("Que color tengo ahora?")

exitonclick()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Comentarios

Entradas populares de este blog

Funciones Geometricas

En este programa encontramos múltiples formulas para la obtención de área y volumen de una gran variedad de figuras geométricas. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> import math def cuadrado(): lado=float(input("Dame el valor de lado: ")) cuadrado=[] cuadrado.append(lado) area=cuadrado[0]*cuadrado[0] cuadrado.append(area) print("Lado= {}, Area= {}".format(cuadrado[0],cuadrado[1])) def triangulo(): triangulo=[] base=float(input("Dame la base: ")) altura=float(input("Dame la altura: ")) triangulo.append(base) triangulo.append(altura) area=(triangulo[0]*triangulo[1])/2 triangulo.append(area) print("Base= {}, Altura= {}, Area= {}".format(triangulo[0],triangulo[1],triangulo[2])) def rectangulo(): rectangulo...

Fotoresistencia y foco

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> from turtle import * import turtle  import numpy as np from pylab import* import random import time import RPi.GPIO as GPIO, time t=Turtle() screen=t.getscreen() setup(400,300,0,0) screensize(150,150) colormode(255) t=Turtle() t.speed(10) screen=t.getscreen() setup(900,620,0,0) screensize(500,150) colormode(255) turtle.bgcolor("darkgray") t.hideturtle() t.penup() t.pensize(5) t.goto(-250,-150) t.pendown() t.goto(450,-150) t.penup() t.goto(-250,-150) t.pendown() t.goto(-450,-300) t.penup() t.goto(-250,-150) t.pendown() t.goto(-250,500) t.penup() t.goto(100,300) t.pendown() t.dot(40,255,255,255) t.dot(40,255,250,0) t.bgcolor("darkgray") GPIO.setmode(GPIO.BCM) valor=0 def medida (): measu...

Radar de velocidad

Las siguientes líneas de código dibujan y actúan como un radar de velocidad en pequeña escala. El sensor lee dos distancias (una inicial y una final) entre 50 y 10 cm, es a los 50 cm cuando lee la inicial y a menos de 10 cuando obtiene la final, al mismo tiempo contara las décimas de segundo para obtener el tiempo. Ya teniendo las dos variables necesarias para calcular una velocidad solo realiza la operación y muestra el resultado en la interfaz.  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> import time import botbook_gpio as gpio from turtle import * t=Turtle() screen=t.getscreen() setup(720,720,0,0) t.speed(5) t.penup() screen.bgcolor("gray") t.fillcolor("white") t.begin_fill() t.goto(200,-200) t.pendown() t.goto(...