lunes, 23 de octubre de 2017

Proyecto, figura de colores.

# -*- coding: utf-8 -*-from Tkinter import *
import turtle
import tkSimpleDialog
turtle.speed(1000)
turtle.shape("arrow")

fondo=tkSimpleDialog.askstring("Color de fondo","Color de fondo")
grosorpincel=tkSimpleDialog.askinteger("Tamaño del pincel","Tamaño del pincel")
vueltas=tkSimpleDialog.askinteger("Número de vueltas","Número de vueltas")
figura=tkSimpleDialog.askinteger("Lado de figura","Puedes escoger una figura de 3 a 9 lados")
turtle.bgcolor(fondo)
turtle.pensize(grosorpincel)

colores=tkSimpleDialog.askstring("Número de colores,","¿Quieres dos colores?")

if colores == "SI":
    colorpincel = tkSimpleDialog.askstring("Color del pincel", "Escoge el color del pincel")
    turtle.pencolor(colorpincel)
    colorpincel2 = tkSimpleDialog.askstring("Color del pincel", "Escoge el otro color del pincel")
    turtle.pencolor(colorpincel2)


elif colores == "NO":
    colorpincel = tkSimpleDialog.askstring("Color del pincel", "Escoge el color del pincel")
    turtle.pencolor(colorpincel)
    colorpincel2 = colorpincel



x=60

def triangulo():
    global x
    global vueltas
    global colorpincel
    global colorpincel2
    color =""
    for i in range (vueltas):
        contador = i

        if contador%2 == 0:
            color=colorpincel
        elif contador%2 != 0:
            color=colorpincel2

        turtle.pencolor(color)

        for j in range (3):
            turtle.forward(x)
            turtle.left(120)
        turtle.left(10)
        x +=1

def cuadrado():
    global x
    global vueltas
    global colorpincel
    global colorpincel2
    color =""
    for i in range (vueltas):
        contador = i

        if contador%2 == 0:
            color=colorpincel
        elif contador%2 != 0:
            color=colorpincel2

        turtle.pencolor(color)

        for j in range (4):
            turtle.forward(x)
            turtle.left(90)
        turtle.left(8)
        x +=1


def pentagono():
    global x
    global vueltas
    global colorpincel
    global colorpincel2
    color =""
    for i in range (vueltas):
        contador = i

        if contador%2 == 0:
            color=colorpincel
        elif contador%2 != 0:
            color=colorpincel2

        turtle.pencolor(color)

        for j in range (5):
            turtle.forward(x)
            turtle.left(72)
        turtle.left(10)
        x +=1


def hexagono():
    global x
    global vueltas
    global colorpincel
    global colorpincel2
    color =""
    for i in range (vueltas):
        contador = i

        if contador%2 == 0:
            color=colorpincel
        elif contador%2 != 0:
            color=colorpincel2

        turtle.pencolor(color)

        for j in range (6):
            turtle.forward(x)
            turtle.left(60)
        turtle.left(10)
        x +=1


def heptagono():
    global x
    global vueltas
    global colorpincel
    global colorpincel2
    color =""
    for i in range (vueltas):
        contador = i

        if contador%2 == 0:
            color=colorpincel
        elif contador%2 != 0:
            color=colorpincel2

        turtle.pencolor(color)

        for j in range (7):
            turtle.forward(x)
            turtle.left(51.42)
        turtle.left(10)
        x +=1


def octagono():
    global x
    global vueltas
    global colorpincel
    global colorpincel2
    color =""
    for i in range (vueltas):
        contador = i

        if contador%2 == 0:
            color=colorpincel
        elif contador%2 != 0:
            color=colorpincel2

        turtle.pencolor(color)

        for j in range (8):
            turtle.forward(x)
            turtle.left(45)
        turtle.left(6)
        x +=1


def nonagono():
    global x
    global vueltas
    global colorpincel
    global colorpincel2
    color =""
    for i in range (vueltas):
        contador = i

        if contador%2 == 0:
            color=colorpincel
        elif contador%2 != 0:
            color=colorpincel2

        turtle.pencolor(color)

        for j in range (9):
            turtle.forward(x)
            turtle.left(40)
        turtle.left(6)
        x +=1


if(figura==3):
    triangulo()
    turtle.clear()
elif(figura==4):
    cuadrado()
    turtle.clear()
elif(figura==5):
    pentagono()
    turtle.clear()
elif(figura==6):
    hexagono()
    turtle.clear()
elif(figura==7):
    heptagono()
    turtle.clear()
elif(figura==8):
    octagono()
    turtle.clear()
elif(figura==9):
    nonagono()
else:
    tkSimpleDialog("No se encuentra la figura que desea")

miércoles, 18 de octubre de 2017

Pentágono

import turtle
import tkSimpleDialog

turtle.speed(100)
turtle.pensize(2)
fondo = turtle.Screen()
fondo.bgcolor("white") #Es el color del fondo de la pantalla
colorfigura = tkSimpleDialog.askstring("Color de la figura","Escoge el color de la figura")
colorpincel = tkSimpleDialog.askstring("Color del pincel","Escoge el color del pincel")
turtle.color(colorfigura) #Aqui obtiene el color de la figura y con el .color es con lo que se llenara la figura del color
turtle.pencolor(colorpincel) #Aqui se obtiene el color del pincel
for i in range (20):
    turtle.begin_fill() #Empieza rellenar la figura
    turtle.forward(100)
    turtle.right(10)

    for j in range (8):
        turtle.forward(100)
        turtle.right(72)
        turtle.end_fill() #Termina de rellenar la figura

turtle.exitonclick()

Triángulo

import turtle
import tkSimpleDialog

turtle.speed(100)
turtle.pensize(2)
fondo = turtle.Screen()
fondo.bgcolor("white") #Es el color del fondo de la pantalla
colorfigura = tkSimpleDialog.askstring("Color de la figura","Escoge el color de la figura")
colorpincel = tkSimpleDialog.askstring("Color del pincel","Escoge el color del pincel")
turtle.color(colorfigura) #Aqui obtiene el color de la figura y con el .color es con lo que se llenara la figura del color
turtle.pencolor(colorpincel) #Aqui se obtiene el color del pincel
for i in range (20):
    turtle.begin_fill() #Empieza rellenar la figura
    turtle.forward(100)
    turtle.right(90)

    for j in range (8):
        turtle.forward(100)
        turtle.right(120)
        turtle.end_fill() #Termina de rellenar la figura

turtle.exitonclick()

viernes, 13 de octubre de 2017

Ejemplos Python

from turtle import *

setup(640, 480, 0, 0)

--------------------------------------------------------------------------

from turtle import *

setup(450, 150, 0, 0)
title("Ejemplo de ventana")

--------------------------------------------------------------------------

from turtle import *

title("Ejemplo de ventana")

--------------------------------------------------------------------------

from turtle import *

setup(250, 100, 0, 0)
title("Ejemplo de ventana")
hideturtle()
dot(10, 0, 0, 0)
setup(450, 150, 0, 0)

--------------------------------------------------------------------------

from turtle import *

setup(450, 150, 0, 0)
screensize(10, 10)

--------------------------------------------------------------------------

from turtle import *

setup(150, 150, 0, 0)
screensize(300, 300)



from turtle import *

setup(450, 150, 0, 0)
screensize(400, 300)

--------------------------------------------------------------------------

from turtle import *

setup(250, 100, 0, 0)
screensize(100, 100)
hideturtle()
dot(10, 0, 0, 0)
screensize(200, 100)

--------------------------------------------------------------------------

from turtle import *

setup(450, 150, 0, 0)
screensize(300, 150)

showturtle()

--------------------------------------------------------------------------

from turtle import *

setup(450, 150, 0, 0)
screensize(300, 150)

goto(100, 0)

--------------------------------------------------------------------------

from turtle import *

setup(450, 150, 0, 0)
screensize(300, 150)

goto(100, 0)
hideturtle()

--------------------------------------------------------------------------

from turtle import *

setup(450, 150, 0, 0)
screensize(300, 150)

hideturtle()
goto(100, 0)

--------------------------------------------------------------------------

from turtle import *

setup(450, 200, 0, 0)
screensize(300, 150)

goto(0, 0)

--------------------------------------------------------------------------

from turtle import *

setup(450, 200, 0, 0)
screensize(300, 150)

goto(100, 50)

--------------------------------------------------------------------------

from turtle import *

setup(450, 200, 0, 0)
screensize(300, 150)

goto(100, 50)
goto(100, -50)
goto(50, -50)

--------------------------------------------------------------------------

from turtle import *

setup(450, 200, 0, 0)
screensize(300, 150)

goto(100, 50)
sety(-50)
setx(50)

--------------------------------------------------------------------------

from turtle import *

setup(450, 200, 0, 0)
screensize(300, 150)

goto(100, 50)
penup()
goto(100, -50)
pendown()
goto(50, -50)

--------------------------------------------------------------------------

from turtle import *

setup(450, 200, 0, 0)
screensize(300, 150)

goto(100, 50)
pensize(4)
goto(100, -50)
pensize(8)
goto(50, -50)

--------------------------------------------------------------------------

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)

--------------------------------------------------------------------------

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)

--------------------------------------------------------------------------

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)

--------------------------------------------------------------------------

from turtle import *

setup(450, 200, 0, 0)
screensize(300, 150)
title("www.mclibre.org")
hideturtle()

pensize(5)
fillcolor("red")
begin_fill()
goto(100, 0)
goto(100, 50)
goto(0, 50)
goto(0, 0)
end_fill()

--------------------------------------------------------------------------

from turtle import *

setup(450, 200, 0, 0)
screensize(300, 150)
title("www.mclibre.org")
hideturtle()

pencolor("red")
pensize(5)
begin_fill()
goto(100, 0)
goto(100, 50)
goto(0, 50)
goto(0, 0)
end_fill()

--------------------------------------------------------------------------

from turtle import *

setup(450, 200, 0, 0)
screensize(300, 150)
title("www.mclibre.org")
hideturtle()

pensize(5)
fillcolor("red")
begin_fill()
goto(100, 0)
goto(100, 50)
goto(0, 50)
end_fill()

--------------------------------------------------------------------------

from turtle import *

setup(450, 200, 0, 0)
screensize(300, 150)
title("www.mclibre.org")
hideturtle()

pensize(5)
fillcolor("red")
begin_fill()
goto(50, 50)
goto(100, -50)
goto(150, 0)
goto(0, 0)
end_fill()



from turtle import *

setup(450, 200, 0, 0)
screensize(300, 150)
title("www.mclibre.org")
hideturtle()

pensize(5)
fillcolor("red")
begin_fill()
goto(0, 75)
goto(100, 0)
goto(100, 75)
end_fill()

--------------------------------------------------------------------------

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)
penup()
goto(-100, 75)
pendown()
goto(-100,0)
goto(-25, 0)
end_fill()

--------------------------------------------------------------------------

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)
end_fill()
penup()
goto(-100, 75)
pendown()
begin_fill()
goto(-100,0)
goto(-25, 0)
end_fill()

--------------------------------------------------------------------------

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