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

No hay comentarios:

Publicar un comentario