lunes, 23 de octubre de 2017

Mini-paint usando turtle

# -*- coding: utf-8 -*-

import turtle
import Tkinter
import tkColorChooser
import tkSimpleDialog


pantalla = Tkinter.Tk()
pantalla.title("Mini paint")
pantalla.resizable(False ,False)
#Se crea la pantalla que contendra la tortuga y el menu



canvas1 = Tkinter.Canvas(pantalla, width=750, height=750)
canvas1.pack(side="left", fill="both", expand=True)
canvas2 = Tkinter.Canvas(pantalla, width=750, height=750)
canvas2.pack(side="right", fill="both", expand=True)
#Se cean los 2 canvas que estaran en la pantalla

lapiz=turtle.RawTurtle(canvas1)
 
#Secrea una rawturtle y se le dice que ponga su area de dibujo en el canvas 1

lapiz.ondrag(lapiz.goto,btn=1)
 
#Se le ordena a la tortuga que se dirija al lugar al que el usuario 
#la arrastre (ondrag) con el boton 1 (click izquierdo)#La funcion ondrag al ejecutarse regresa 2 valores , la posicion de x y y en el momento
# en el que el usuario hace click sobre la tortuga , estas coordenadas son resividas por el goto


boton101= Tkinter.Button(canvas2,text="Color del lapiz",command=lambda:lapiz.pencolor(color2()))
boton101.pack(fill="x")
boton11= Tkinter.Button(canvas2,text="Grosor del lapiz",command=lambda:tamano())
boton11.pack(fill="x")
boton12= Tkinter.Button(canvas2,text="Color del relleno",command=lambda:lapiz.fillcolor(color2()))
boton12.pack(fill="x")
boton12= Tkinter.Button(canvas2,text="Cuadrado",command=lambda:cuadradi())
boton12.pack(fill="x")
boton12= Tkinter.Button(canvas2,text="Triangulo",command=lambda:triangulo())
boton12.pack(fill="x")
boton12= Tkinter.Button(canvas2,text="Circulo",command=lambda:circulo())
boton12.pack(fill="x")
boton12= Tkinter.Button(canvas2,text="Linea recta",command=lambda:linearecta())
boton12.pack(fill="x")
boton13= Tkinter.Button(canvas2,text="Limpiar",command=lambda:limpiar())
boton13.pack(fill="x")
boton14= Tkinter.Button(canvas2,text="subir y bajar lapiz",command=lambda:sube(lapiz.isdown()))
boton14.pack(fill="x")
boton14= Tkinter.Button(canvas2,text="Borrador",command=lambda:(lapiz.pencolor("White"),lapiz.pensize(10)))
boton14.pack(fill="x")
boton14= Tkinter.Button(canvas2,text="Lapiz",command=lambda:(lapiz.pencolor("black"),lapiz.pensize(1)))
boton14.pack(fill="x")
#Menu


def color2():
    a=tkColorChooser.askcolor()
    return (a[1])
    #Funcion que asigna un color al lapiz o el relleno con ayuda de la libreria tkColorChooser , 
    #la funcion tkColorChooser.askcolor() regresa el color seleccionado en forma de RGB y de hexadecimal 
    #de la forma  (RGB, hexadecimal)    #Al escribir a[1] estamos pidiendo la notacion hexadecimal del color

def tamano():
    a=tkSimpleDialog.askinteger("Hola","Dame el grosor del lapiz")
    lapiz.pensize(a)
    #Funcion que pide el tamaño del lapiz por meedio de un tkSimpleDialog.askinteger y lo asigna al lapiz


def limpiar():
    lapiz.clear()
    #Funcion que limpia el area de dibujo

def sube(a):
    if (a==False):
        lapiz.pendown()
    elif (a==True):
        lapiz.penup()
        #Funcion que se usa para subir y bajar el lapiz , para poder dibujar de forma mas realista


def cuadradi():
    lapiz.begin_fill()
    a=tkSimpleDialog.askinteger("Hola", "Dime el tamano del cuadrado")
    for x in range(4):
        lapiz.forward(a)
        lapiz.right(90)
    lapiz.end_fill()

def triangulo():
    lapiz.begin_fill()
    a=tkSimpleDialog.askinteger("Hola", "Dime el tamano del Triangulo")
    for x in range(3):
        lapiz.forward(a)
        lapiz.left(120)
    lapiz.end_fill()

def circulo():
    lapiz.begin_fill()
    a=tkSimpleDialog.askinteger("Hola", "Dime el tamano del circulo")
    lapiz.circle(a)
    lapiz.end_fill()
#Funciones que crean figuras predeterminadas

def linearecta():
    lapiz.begin_fill()
    a=tkSimpleDialog.askinteger("Hola", "Dime el tamano de la linea")
    b=tkSimpleDialog.askinteger("Hola", "Dime el angulo de la linea")
    c=tkSimpleDialog.askinteger("Hola", "Dime el numero de lineas")
    for i in range(c):
     lapiz.left(b)
     lapiz.forward(a)
    lapiz.end_fill()
#Funcion que le permite al usuario crear lineas rectas y
# seleccionar el angulo de las mismas , asi como el numero de veces que dicha 
#linea sera dibujada ,para que asi se pueda#crear cualquier poligino regular

pantalla.mainloop()
 
 
 

 
 
 

domingo, 22 de octubre de 2017

Figuras con turtle pidiendo datos

import turtle
import tkSimpleDialog

lapiz= turtle.Turtle()
lapiz.speed(10)
lapiz.shape("turtle")
pantalla= turtle.Screen()
vueltas=30

a=tkSimpleDialog.askstring("hola", "Dame el fondo")
b=tkSimpleDialog.askstring("hola", "dame el relleno")
c=tkSimpleDialog.askinteger("hola", "Dame el grosor del lapiz")

pantalla.bgcolor(a)
lapiz.pensize(c)
lapiz.fillcolor(b)


cont=0
for i in range (vueltas):
    if cont > 14:
        lapiz.clear();cont=0;i=1;vueltas=1
    lapiz.begin_fill()
    lapiz.rt(90)
    lapiz.fd(200)
    lapiz.lt(120)
    lapiz.fd(200)
    lapiz.lt(120)
    lapiz.fd(200)
    cont=cont+1
    print(vueltas)
    lapiz.end_fill()

pantalla.exitonclick()


--------
import turtle
import tkSimpleDialog

lapiz= turtle.Turtle()
lapiz.speed(10)
lapiz.shape("turtle")
pantalla= turtle.Screen()

vueltas=tkSimpleDialog.askinteger("hola","Dame el numero de figuras")
a=tkSimpleDialog.askstring("hola", "Dame el fondo")
b=tkSimpleDialog.askstring("hola", "dame el relleno")
c=tkSimpleDialog.askinteger("hola", "Dame el grosor del lapiz")

pantalla.bgcolor(a)
lapiz.pensize(c)
lapiz.fillcolor(b)


cont=0
for i in range (vueltas):
    if cont > 14:
        lapiz.clear();cont=0;i=1;vueltas=1
    lapiz.begin_fill()
    lapiz.rt(90)
    lapiz.fd(200)
    lapiz.lt(120)
    lapiz.fd(200)
    lapiz.lt(120)
    lapiz.fd(200)
    cont=cont+1
    print(vueltas)
    lapiz.end_fill()

pantalla.exitonclick()

--------------------------------
import turtle
import tkSimpleDialog

lapiz= turtle.Turtle()
lapiz.speed(10)
lapiz.shape("turtle")
pantalla= turtle.Screen()

vueltas=tkSimpleDialog.askinteger("hola","Dame el numero de figuras")
a=tkSimpleDialog.askstring("hola", "Dame el fondo")
b=tkSimpleDialog.askstring("hola", "dame el relleno")
c=tkSimpleDialog.askinteger("hola", "Dame el grosor del lapiz")

pantalla.bgcolor(a)
lapiz.pensize(c)
lapiz.fillcolor(b)


cont=0
ax=90
bx=200
cx=120

for i in range (vueltas):
    if cont > 11:
        lapiz.clear();cont=0;i=1;vueltas=1
    lapiz.begin_fill()
    lapiz.rt(ax)
    lapiz.fd(bx)
    lapiz.lt(cx)
    lapiz.fd(bx)
    lapiz.lt(cx)
    lapiz.fd(bx)
    cont=cont+1
    print(vueltas)
    lapiz.end_fill()

pantalla.exitonclick()

miércoles, 18 de octubre de 2017

Figuras con turtle , pidiendo colores

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


martes, 17 de octubre de 2017

Figuras con turtle del dia 16/10/2017

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

domingo, 15 de octubre de 2017

Manejando turtle , funciones y circulos

from turtle import *
color('black', 'cyan')

speed(10000)

penup()

pendown()

def dibujar():
    a = 0    begin_fill()
    while True:
      penup()
      forward(100)
      left(170)
      pendown()
      circle(30)
      a=a+10      if a==360:
         break    end_fill()

a=-500b=400pendown()
for f in range (0,6):
    b=b-100    a=-500    for x in range (0,14):
      penup()

      goto(a,b)
      pendown()
      dibujar()
      a=a+100


done()
 
 
 

martes, 10 de octubre de 2017

Primeras figuras en turtle

Figura propia:
from turtle import *
setup(600,600,0,0)
#hideturtle()
speed(1)
pensize(10)
pencolor("blue")
penup()
goto(100,-100)
pendown()
pencolor("RED")
goto(100,100)
goto(-100,100)
goto(-100,-100)
goto(100,-100)
penup()
home()
pendown()
pencolor("purple")
circle(50)
goto(-100,-100)
home()
goto(100,-100)
home()
goto(100,100)
home()
goto(-100,100)
goto(0,100)
goto(0,200)
goto(-100,100)
goto(0,200)
goto(100,100)
goto(-100,-100)
goto(0,-200)
goto(100,-100)
goto(200,0)
goto(100,100)
goto(-100,100)
goto(-200,0)
goto(-100,-100)
goto(0,-200)
pencolor("blue")
circle(200,20)
pencolor("RED")
circle(200,20)
pencolor("purple")
circle(200,20)
pencolor("black")
circle(200,20)
pencolor("yellow")
circle(200,20)
pencolor("brown")
circle(200,20)
pencolor("orange")
circle(200,20)
pencolor("cyan")
circle(200,20)
pencolor("green")
circle(200,20)
pencolor("red")
circle(200,20)
pencolor("brown")
circle(200,20)
pencolor("yellow")
circle(200,20)
pencolor("blue")
circle(200,20)
pencolor("purple")
circle(200,20)
pencolor("cyan")
circle(200,20)
pencolor("black")
circle(200,20)
pencolor("orange")
circle(200,20)
pencolor("purple")
circle(200,20)
goto(-200,-200)
goto(-200,0)
goto(-200,200)
goto(0,200)
goto(200,200)
goto(200,0)
goto(200,-200)
goto(0,-200)
done()

Barco:

from turtle import *

setup(600,600,0,0)

#hideturtle()
speed(100)

pensize(10)

pencolor("blue")

goto(100,0)
goto(75,-30)
goto(0,-30)
goto(-25,0)
home()
goto(0,100)
goto(40,75)
goto(0,75)
done()

domingo, 8 de octubre de 2017

Libreria turtle conocimiento basico


from turtle import *

setup(640, 480, 0, 0)
 done()
 
--------------------------------------------------------------
 
from turtle import *

setup(450, 150, 0, 0)
title("Ejemplo de ventana")
done() 
----------------------------------------------------------------
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() 
-----------------------------------------------------------------
from turtle import *

setup(450, 150, 0, 0)
screensize(10, 10)
done() 
------------------------------------------------------------------
from turtle import *

setup(150, 150, 0, 0)
screensize(300, 300)
done() 
-----------------------------------------------------------------
from turtle import *

setup(450, 150, 0, 0)
screensize(400, 300)
done() 
--------------------------------------------------------------
 
from turtle import *

setup(250, 100, 0, 0)
screensize(100, 100)
hideturtle()
dot(10, 0, 0, 0)
screensize(200, 100)
done() 
--------------------------------------------------------------
from turtle import *

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

showturtle()
done() 
---------------------------------------------------------------
from turtle import *

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

goto(100, 0)
done() 
----------------------------------------------------------------
from turtle import *

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

goto(100, 0)
hideturtle()
done() 
---------------------------------------------------------------
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() 
-------------------------------------------------------------------
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() 
---------------------------------------------------------------------
from turtle import *

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

goto(100, 50)
penup()
goto(100, -50)
pendown()
goto(50, -50)
done() 
---------------------------------------------------------------------
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() 
------------------------------------------------------------------   
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() 
--------------------------------------------------------------
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() 
-----------------------------------------------------------------
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() 
---------------------------------------------------------------
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()
done() 
------------------------------------------------------------
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()
done() 
---------------------------------------------------------------
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()
done() 
------------------------------------------------------------------
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()
 
done()
-----------------------------------------------------------------------------------------------
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()
done() 
----------------------------------------------------------------
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()
done() 
----------------------------------------------------------------
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()
done() 
------------------------------------------------------------------
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() 
------------------------------------------------------------------