Programación

“Primero resuelve el problema. Entonces, escribe el código.” — John Johnson

martes, 26 de noviembre de 2019

spinball colores


from tkinter import *

window = Tk()

window.title("Capta letrero")

window.geometry('500x250')
li=[];
def clicked():

   print(var.get())
   l=var.get()
   li.append(l)
   print(li)
 
 
def clicked2():

   print(var.get())
   l=var.get()
   li.append(l)
   print(li)

 
def clicked3():

   print(var.get())
   l=var.get()
   li.append(l)
   print(li)
 
var =IntVar()
var.set(2)

spin = Spinbox(window, values=(1, 2),fg="white",bg="red", width=5, textvariable=var)
spin.grid(column=0,row=0)
spin = Spinbox(window, values=(1, 2),fg="white",bg="green", width=5, textvariable=var)
spin.grid(column=2,row=0)
spin = Spinbox(window, values=(1, 2),fg="white",bg="blue", width=5, textvariable=var)
spin.grid(column=4,row=0)

btn = Button(window,fg="red", text="Valor aceptado", command=clicked)
btn.grid(column=1, row=0)
btn = Button(window, fg="green",text="Valor aceptado", command=clicked2)
btn.grid(column=3, row=0)
btn = Button(window, fg="blue",text="Valor aceptado", command=clicked3)
btn.grid(column=5, row=0)
window.mainloop()

jueves, 21 de noviembre de 2019

https://stackoverflow.com/questions/25088087/how-to-move-a-turtle-stamp-in-python

import random
import turtle

STAMP_SIZE = 20
SQUARE_SIZE = 15
FINISH_LINE = 200
COLOR_LIST = ['red', 'blue', 'green', 'brown', 'yellow', 'purple']

def draw_start():
    turtle.speed('fastest')
    turtle.penup()
    turtle.setpos(-350, 300)
    turtle.pendown()
    turtle.right(90)
    turtle.forward(520)

def draw_finish():
    turtle.shape('square')
    turtle.shapesize(SQUARE_SIZE / STAMP_SIZE)
    turtle.penup()

    for i in range(18):
        turtle.setpos(FINISH_LINE, (300 - (i * SQUARE_SIZE * 2)))
        turtle.stamp()

    for j in range(18):
        turtle.setpos(FINISH_LINE + SQUARE_SIZE, ((300 - SQUARE_SIZE) - (j * SQUARE_SIZE  * 2)))
        turtle.stamp()

    turtle.hideturtle()

def move_turtle(who):
    who.forward(random.randint(1, 10))
    if who.xcor() < FINISH_LINE:
        turtle.ontimer(lambda who=who: move_turtle(who), 50)

print('Welcome to Turtle Racing!')
number_of_turtles = int(input('How many turtles (between 3 and 6): '))

draw_start()
draw_finish()

turtle_list = []

for idx in range(number_of_turtles):
    racer = turtle.Turtle('turtle', visible=False)
    racer.speed('fastest')  # affects drawing speed, not forward motion
    racer.penup()
    racer.setpos(-350 - STAMP_SIZE, 280 - idx * 90)
    racer.color(COLOR_LIST[idx])
    racer.showturtle()

    turtle_list.append(racer)

for racer in turtle_list:
    turtle.ontimer(lambda who=racer: move_turtle(who), 100)

turtle.exitonclick()

miércoles, 20 de noviembre de 2019

Apoyos

https://stackoverflow.com/questions/25088087/how-to-move-a-turtle-stamp-in-python


https://runestone.academy/runestone/books/published/StudentCSP/CSPRe

peatTurtles/stamp.html


from turtle import *
t=Turtle()
screen=t.getscreen()


setup(250, 250, 0, 0)
screensize(120, 120)
hideturtle()

penup()
color("Red")
goto(-100, 0)
pendown()
goto(-50, 50)
goto(50, -50)
goto(100, 0)
goto(50, 50)
goto(-50, -50)
goto(-100, 0)

penup()

goto(0, 50)
dot(50, 0, 0, 0)
goto(0, -50)
dot(50, 0, 0, 0)
screen.exitonclick()

*******Camina y estampa**************
from turtle import *
#tortugota caminando
t=Turtle()
screen=t.getscreen()
setup(1500,600)
#screensize(400,200)
#speed(10)
t.shapesize(4,4,5)
t.shape("turtle")
t.fd(200)
t.fd(100)
t.stamp()
#tilt() Rota la forma del shape determinado
#en angulos, desde el actual angulo de inclinacion
#pero no cambia la direcciona de desplazamiento
t.tilt(30)
t.fd(50)
t.tilt(30)
t.fd(150)


****Vegetacion ****
from turtle import *
t=Turtle()
screen=t.getscreen()

setup(420, 420, 0, 0)

setup(450, 200, 0, 0)
screensize(300, 150)
title("www.mclibre.org")
hideturtle()
color("Green")
lado = int(numinput("Módulo turtle", "Tamaño del cuadros (10-100): ", 50, 10, 100))
nx = int(numinput("Módulo turtle", "Número de cuadros en horizontal (1-20)", 5, 1, 20))
ny = int(numinput("Módulo turtle", "Número de cuadros en vertical (1-20)", 5, 1, 20))

screensize(lado * nx * 2, lado * ny * 2)

for i in range(ny):
    for j in range(nx):
        origenX = lado * j
        origenY = lado * i
        goto(origenX, origenY)
        pendown()
        begin_fill()
        goto(origenX, origenY + lado//2)
        goto(origenX + lado, origenY + lado//2)
        goto(origenX + lado, origenY + lado)
        goto(origenX, origenY)
        end_fill()
        penup()
        goto(origenX, origenY + lado)
        pendown()
        begin_fill()
        goto(origenX + lado//2, origenY + lado)
        goto(origenX + lado // 2, origenY)
        goto(origenX + lado, origenY)
        goto(origenX, origenY + lado)
        end_fill()
        penup()
screen.exitonclick()

****puntos****

from turtle import *
t=Turtle()
screen=t.getscreen()




#3
setup(250, 250, 0, 0)
screensize(120, 120)
colormode(255)
hideturtle()

penup()
goto(-100, 100)
dot(10, 255, 0, 0)
goto(-33, 33)
dot(10, 0, 0, 0)
goto(33, -33)
dot(10, 0, 0, 255)
goto(100, -100)
dot(10, 0, 255, 0)
#4
setup(250, 250, 0, 0)
screensize(120, 120)
colormode(255)
hideturtle()

penup()
goto(-100, 0)
dot(10, 0, 0, 0)
goto(-50, 0)
dot(10, 51, 51, 51)
goto(0, 0)
dot(10, 102, 102, 102)
goto(50, 0)
dot(10, 153, 153, 153)
goto(100, 0)
dot(10, 204, 204, 204)

#5
setup(250, 250, 0, 0)
screensize(120, 120)
colormode(255)
hideturtle()

penup()
goto(0, 80)
dot(40, 0, 0, 255)
goto(0, 40)
dot(40, 255, 0, 0)
goto(0, 0)
dot(40, 0, 0, 0)
goto(0, -40)
dot(40, 0, 255, 0)
goto(0, -80)
dot(40, 255, 0, 255)
screen.exitonclick()


****Coordenadas***
from turtle import *
t=Turtle()
a=Turtle()
screen=t.getscreen()
setup(800, 600, 0, 0)
shape('turtle')
penup()
goto(100,100)
write("Estas en 100, 100")
t.penup()
t.color("red")
t.goto(120,120)
t.write("Estas en 120, 120")
a.penup()
a.shape("turtle")
a.color("magenta")
a.goto(140,140)
a.write("Estas en 140, 140")


screen.exitonclick()


martes, 26 de febrero de 2019

Graficar funciones con matplotlib

Cálculo simbólico con Sympy

Sympy permite hacer operaciones analíticas o con símbolos en lugar de con valores numéricos Al igual que en Python existen varios tipos de datos numéricos como enteros (int), decimales (float) o booleanos (bool:True, False, etc.), Sympy posee tres tipos de datos propios: Real, Rational e Integer, es decir, números reales, racionales y enteros. Estoquiere decir que Rational(1,2) representa 1/2, Rational(5,2) a 5/2, etc. en lugar de 0.5 o 2.5.
http://www.iac.es/sieinvens/python-course/source/sympy.html

https://recursospython.com/codigos-de-fuente/graficar-funciones-matplotlib/

from matplotlib import pyplot
# Función cuadrática.
def f1(x):
    return 2*(x**2) + 5*x - 2
# Función lineal.
def f2(x):
    return 4*x + 1
# Valores del eje X que toma el gráfico.
x = range(-10, 15)
# Graficar ambas funciones.
pyplot.plot(x, [f1(i) for i in x])
pyplot.plot(x, [f2(i) for i in x])
# Establecer el color de los ejes.
pyplot.axhline(0, color="black")
pyplot.axvline(0, color="black")
# Limitar los valores de los ejes.
pyplot.xlim(-10, 10)
pyplot.ylim(-10, 10)
# Guardar gráfico como imágen PNG.
pyplot.savefig("output.png")
# Mostrarlo.
pyplot.show()


http://webs.ucm.es/info/aocg/python/modulos_cientificos/matplotlib/index.html



https://www.youtube.com/watch?v=i8ruymr85Gg



lunes, 21 de enero de 2019

Mejores promedios Agosto Diciembre 2018

SARABIA LANDEROS MARCO POLO
VAZQUEZ BARBA PAOLA DEL PILAR
MARTINEZ RUIZ JORGE ALEJANDRO
LEZAMA LEZAMA JESUS ERNESTO