martes, 31 de octubre de 2017
martes, 24 de octubre de 2017
Programa Final
Tropa de tortugas
from turtle import * import tkSimpleDialog wn = Screen() tess = Turtle() b=tkSimpleDialog.askstring("hola","Dame el color de las tortugas") c=tkSimpleDialog.askstring("hola","Dame el color del fondo") a=tkSimpleDialog.askinteger("hola","Dame el numero de tortugas") tess.color(b) wn.bgcolor(c) tess.shape("turtle") tess.up() # otra forma de levantar el lapizfor dist in range(2,a): # dist = "1" , cantidad = "2" tess.stamp() # deja una impresion tess.forward(dist) # move tess along tess.right(24) # voltear wn.exitonclick()
Arbol
import turtle
lapiz2=turtle.Turtle()
lapiz2.speed(100)
lapiz2.hideturtle()
c=1
def arbol(tam,lapiz,i):
if tam > 5:
lapiz.forward(tam)
lapiz.right(20)
a=lapiz.pos()
if i==1:
hojas(a,lapiz2)
elif i==2:
hojasoto(a, lapiz2)
elif i==3:
hojasinvi(a, lapiz2)
arbol(tam-15,lapiz,i)
lapiz.left(40)
arbol(tam-15,lapiz,i)
lapiz.right(20)
lapiz.up
lapiz.backward(tam)
lapiz.down
def dibujar():
i=1
lapiz1 = turtle.Turtle()
lapiz1.hideturtle()
pantalla = turtle.Screen()
lapiz1.speed(100)
lapiz1.pensize(1)
lapiz1.left(90)
lapiz1.up()
lapiz1.backward(50)
lapiz1.down()
lapiz1.color("black")
for i in range (4):
arbol(120,lapiz1,i)
pantalla.exitonclick()
def hojas(a,lapiz):
lapiz.fillcolor("green")
lapiz.penup()
lapiz.goto(a)
lapiz.pendown()
lapiz.begin_fill()
lapiz.circle(5)
lapiz.end_fill()
def hojasoto(a,lapiz):
lapiz.fillcolor("brown")
lapiz.begin_fill()
lapiz.penup()
lapiz.goto(a)
lapiz.pendown()
lapiz.circle(5)
lapiz.end_fill()
def hojasinvi(a,lapiz):
lapiz.reset()
dibujar()
Planetas
from turtle import Turtle, Screen """ Simulate motion of Mercury, Venus, Earth, and Mars """ planets = { 'mercury': {'diameter': 0.383, 'orbit': 58, 'speed': 7.5, 'color': 'gray'}, 'venus': {'diameter': 0.949, 'orbit': 108, 'speed': 3, 'color': 'yellow'}, 'earth': {'diameter': 1.0, 'orbit': 150, 'speed': 2, 'color': 'blue'}, 'mars': {'diameter': 0.532, 'orbit': 228, 'speed': 1, 'color': 'red'}, } def setup_planets(planets): for planet in planets: dictionary = planets[planet] turtle = Turtle(shape='circle') turtle.speed("fastest") # speed controlled elsewhere, disable here turtle.shapesize(dictionary['diameter']) turtle.color(dictionary['color']) turtle.pu() turtle.sety(-dictionary['orbit']) turtle.pd() dictionary['turtle'] = turtle screen.ontimer(revolve, 50) def revolve(): for planet in planets: dictionary = planets[planet] dictionary['turtle'].circle(dictionary['orbit'], dictionary['speed']) screen.ontimer(revolve, 50) screen = Screen() setup_planets(planets) screen.exitonclick()
miércoles, 18 de octubre de 2017
Figuras con for
cuadrado
import turtle
turtle.speed(1)
fonde = turtle.Screen()
fonde.bgcolor("yellow")
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.exitonclick()
cuadrado con for
import turtle
turtle.speed(100)
fonde = turtle.Screen()
fonde.bgcolor("yellow")
a=0
for x in range (40):
turtle.forward(100)
turtle.right(90)
for i in range(1):
turtle.forward(100)
turtle.right(80)
turtle.exitonclick()
triangulo con for
import turtle
turtle.speed(100)
fonde = turtle.Screen()
fonde.bgcolor("yellow")
a=0
for x in range (40):
turtle.forward(100)
turtle.left(120)
#for i in range(10):
# turtle.forward(130)
# turtle.right(110)
turtle.exitonclick()
Rombo con for
import turtle
turtle.speed(1)
fonde = turtle.Screen()
fonde.bgcolor("yellow")
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.exitonclick()
cuadrado con for
import turtle
turtle.speed(100)
fonde = turtle.Screen()
fonde.bgcolor("yellow")
a=0
for x in range (40):
turtle.forward(100)
turtle.right(90)
for i in range(1):
turtle.forward(100)
turtle.right(80)
turtle.exitonclick()
triangulo con for
import turtle
turtle.speed(100)
fonde = turtle.Screen()
fonde.bgcolor("yellow")
a=0
for x in range (40):
turtle.forward(100)
turtle.left(120)
#for i in range(10):
# turtle.forward(130)
# turtle.right(110)
turtle.exitonclick()
Rombo con for
import turtle turtle.speed(1) fonde = turtle.Screen() fonde.bgcolor("yellow") a=0for x in range (3): turtle.forward(100) turtle.left(120) turtle.home() for x in range (3): turtle.forward(100) turtle.right(120) turtle.exitonc
Figuras que piden color
Capturas:
Código:
Triangulo
import turtle import tkSimpleDialog turtle.speed(100) fonde = turtle.Screen() b=tkSimpleDialog.askstring("hola","Dame el color") c=tkSimpleDialog.askstring("hola","Dame el color del fondo") a=tkSimpleDialog.askstring("hola","Dame el color del relleno") fonde.bgcolor(c) turtle.pencolor(b) turtle.fillcolor(a) turtle.begin_fill() for x in range (3): turtle.forward(100) turtle.left(120) turtle.end_fill() turtle.exitonclick()
Cuadrado
import turtle import tkSimpleDialog turtle.speed(100) fonde = turtle.Screen() b=tkSimpleDialog.askstring("hola","Dame el color") c=tkSimpleDialog.askstring("hola","Dame el color del fondo") a=tkSimpleDialog.askstring("hola","Dame el color del relleno") fonde.bgcolor(c) turtle.pencolor(b) turtle.fillcolor(a) turtle.begin_fill() for x in range (4): turtle.forward(100) turtle.left(90) turtle.end_fill() turtle.exitonclick()
Octagono
import turtle import tkSimpleDialog turtle.speed(100) fonde = turtle.Screen() b=tkSimpleDialog.askstring("hola","Dame el color") c=tkSimpleDialog.askstring("hola","Dame el color del fondo") a=tkSimpleDialog.askstring("hola","Dame el color del relleno") fonde.bgcolor(c) turtle.pencolor(b) turtle.fillcolor(a) turtle.begin_fill() for x in range (8): turtle.forward(100) turtle.left(45) turtle.end_fill() turtle.exitonclick()
lunes, 16 de octubre de 2017
Barquito
Programa del Barquito
Captura:
Código:
from turtle import * setup(600,600,0,0) pencolor("black") pensize(2) hideturtle() fillcolor("brown") begin_fill() goto(-120, 0) pendown() goto(-80, -60) goto(80, -60) goto(120, 0) goto(0,0) end_fill() fillcolor("black") begin_fill() penup() goto(-20, 0) pendown() goto(-20,140) goto(0,140) goto(0,0) end_fill() fillcolor("white") begin_fill() penup() goto(0,140) pendown() goto(80,100) goto(0,60) end_fill() done()
martes, 10 de octubre de 2017
Figura propia con Turtle
Captura:
Código:
from turtle import * setup(600,600,0,0) pencolor("black") pensize(2) hideturtle() penup() goto(-40,185) pendown() goto(-40,100) goto(-80,100) goto(-80,-20) goto(-40,-20) goto(-40,-140) goto(40,-140) goto(40,-20) goto(80,-20) goto(80,100) goto(40,100) goto(40,185) goto(-40,185) penup() #ojosgoto(-10, 150) pendown() goto(-30, 150) goto(-30, 140) goto(-10, 140) goto(-10, 150) penup() goto(10, 150) pendown() goto(30, 150) goto(30, 140) goto(10, 140) goto(10, 150) penup() #cabellogoto(-40, 160) pendown() goto(-30, 160) goto(-30, 170) goto(30, 170) goto(30, 160) goto(40, 160) penup() #Bocagoto(0,120) pendown() goto(10,120) goto(10,130) goto(20,130) goto(20,110) goto(0,110) penup() goto(0,120) pendown() goto(-10,120) goto(-10,130) goto(-20,130) goto(-20,110) goto(0,110) penup() #brazosgoto(-80,60) pendown() goto(-40,60) goto(-40,-20) penup() goto(80, 60) pendown() goto(40,60) goto(40,-20) penup() #piesgoto(-40, -120) pendown() goto(40, -120) penup() #cintogoto(-40, 0) pendown() goto(40, 0) penup() #pgoto(0, -40) pendown() goto(0, -140) penup() #cuellogoto(-40, 100) pendown() goto(-20, 100) goto(0, 80) penup() goto(40, 100) pendown() goto( 20, 100) goto(0, 80) penup() done()
domingo, 8 de octubre de 2017
Turtle
Programas con TURTLE
Tamaño y posición de la ventana
from turtle import *
setup(640, 480, 0, 0)
done()
__________________________________________________________________________
Definir titulo
from turtle import * setup(450, 150, 0, 0) title("Ejemplo de ventana")}
done()
__________________________________________________________________________
Sin setup la ventana se crea en el centro
from turtle import * title("Ejemplo de ventana")
done()__________________________________________________________________________from turtle import * setup(250, 100, 0, 0) title("Ejemplo de ventana") hideturtle() dot(10, 0, 0, 0) setup(450, 150, 0, 0)
done()
__________________________________________________________________________
Screensize define el tamaño del área de dibujo
from turtle import * setup(450, 150, 0, 0) screensize(10, 10)
done()
__________________________________________________________________________
Si la ventana es mas chica que el área de dibujo aparecerá una barra de desplazamiento
from turtle import * setup(150, 150, 0, 0) screensize(300, 300)
done ()
solo barra vertical:
from turtle import * setup(450, 150, 0, 0) screensize(400, 300)
done()
_________________________________________________________________________
Crear un punto
from turtle import * setup(250, 100, 0, 0) screensize(100, 100) hideturtle() dot(10, 0, 0, 0) screensize(200, 100)
done()
__________________________________________________________________________Mostrar cursor
from turtle import * setup(450, 150, 0, 0) screensize(300, 150) showturtle()
done()
__________________________________________________________________________
Crear linea
from turtle import * setup(450, 150, 0, 0) screensize(300, 150)
goto(100, 0)
done()
__________________________________________________________________________
Oculta cursor
from turtle import * setup(450, 150, 0, 0) screensize(300, 150) goto(100, 0) hideturtle()
done()
_________________________________________________________________________
Ocultar tortuga desde el comienzo
from turtle import * setup(450, 150, 0, 0) screensize(300, 150) hideturtle() goto(100, 0)
done()__________________________________________________________________________from turtle import * setup(450, 200, 0, 0) screensize(300, 150) goto(0, 0)
done()
__________________________________________________________________________
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) goto(100, 50)
done()
__________________________________________________________________________
Dibujar segmentos
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) goto(100, 50) goto(100, -50) goto(50, -50)
done()
__________________________________________________________________________
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) goto(100, 50) sety(-50) setx(50)
done()
__________________________________________________________________________
Levantar y bajar
lápiz
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) goto(100, 50) penup() goto(100, -50) pendown() goto(50, -50)
done()
__________________________________________________________________________
Cambiar grosor de trazo
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()
__________________________________________________________________________
Color del trazo:
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) colormode(255) pencolor(255, 0, 0) goto(100, 50) pencolor(0, 255, 0) goto(100, -50) pencolor(0, 0, 255) goto(50, -50)
done()
__________________________________________________________________________
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) colormode(1) pencolor(1, 0, 0) goto(100, 50) pencolor(0, 1, 0) goto(100, -50) pencolor(0, 0, 1) goto(50, -50)
done()
__________________________________________________________________________
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()
__________________________________________________________________________
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) colormode(1) pencolor(0.5, 0, 0) goto(100, 50) pencolor(0, 0.5, 0) goto(100, -50) pencolor(0, 0, 0.5) goto(50, -50)
done()
__________________________________________________________________________
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) pencolor("red") goto(100, 50) pencolor("green") goto(100, -50) pencolor("blue") goto(50, -50)
done()
__________________________________________________________________________
Crear puntos de colores bajando lapiz
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()
__________________________________________________________________________
Crear puntos de colores subiendo el lapiz (sin lineas)
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()
__________________________________________________________________________
Rellenar figura
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) title("relleno") hideturtle() pensize(5) fillcolor("red") begin_fill() goto(100, 0) goto(100, 50) goto(0, 50) goto(0, 0) end_fill()
done()
__________________________________________________________________________
Si no se establece color de relleno, el predeterminado es el negro.
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) title("relleno predeterminado") hideturtle() pencolor("red") pensize(5) begin_fill() goto(100, 0) goto(100, 50) goto(0, 50) goto(0, 0) end_fill()
done()
__________________________________________________________________________
Python rellena figuras aunque no estén completas.
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) title("relleno") hideturtle() pensize(5) fillcolor("red") begin_fill() goto(100, 0) goto(100, 50) goto(0, 50) end_fill()
done()
__________________________________________________________________________
Si las líneas de la figura se cruzan, Python rellena cada una de las partes cerradas.
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) title("relleno") hideturtle() pensize(5) fillcolor("red") begin_fill() goto(50, 50) goto(100, -50) goto(150, 0) goto(0, 0) end_fill()
done()__________________________________________________________________________Otra figura con lineas cruzadas
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) title("relleno") hideturtle() pensize(5) fillcolor("red") begin_fill() goto(0, 75) goto(100, 0) goto(100, 75) end_fill()
done()
__________________________________________________________________________
Rectangulo
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) title("relleno") hideturtle() pensize(5) fillcolor("red") begin_fill() goto(75, 0) goto(75, 75) penup() goto(-100, 75) pendown() goto(-100,0) goto(-25, 0) end_fill()
done()
__________________________________________________________________________
Rellenar 2 figuras separadas
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) title("relleno") hideturtle() pensize(5) fillcolor("red") 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()
__________________________________________________________________________
Se pueden llenar 2 figuras separadas si están cerradas.
from turtle import * setup(450, 200, 0, 0) screensize(300, 150) title("www.mclibre.org") hideturtle() pensize(5) fillcolor("red") begin_fill() goto(75, 0) goto(75, 75) goto(0,0) penup() goto(-100, 75) pendown() goto(-100,0) goto(-25, 0) goto(-100, 75) end_fill()
done()
Suscribirse a:
Entradas (Atom)
-
Dibujar un corazón en Python Capturas : Código : from turtle import * def curvemove(): for i in range ( 200 ): ...
-
Instalacion Ir a : https://db.apache.org/derby/derby_downloads. Entrar en la versión mas reciente: Una vez ahí, descargamos solo los...
-
azul macro mov ah,0 mov al,3h int 10h mov ax,0600h mov bh,0fh mov cx,0000h mov dx,184Fh int ...