1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax1 = fig.add_subplot(111, projection='3d') xpos = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] ypos = [2,3,4,5,1,6,2,1,7,2,3,5,1,3,2] num_elements = len(xpos) zpos = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] dx = np.ones(15) dy = np.ones(15) dz = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] ax1.bar3d(xpos, ypos, zpos, dx, dy, dz, color='#000000') plt.show() |
domingo, 25 de noviembre de 2018
Grafica de barras
Cubo3d
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * verticies = ( (1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, -1), (1, -1, 1), (1, 1, 1), (-1, -1, 1), (-1, 1, 1) ) edges = ( (0, 1), (0, 3), (0, 4), (2, 1), (2, 3), (2, 7), (6, 3), (6, 4), (6, 7), (5, 1), (5, 4), (5, 7) ) def Cube(): glBegin(GL_LINES) for edge in edges: for vertex in edge: glVertex3fv(verticies[vertex]) glEnd() def main(): pygame.init() display = (800, 600) pygame.display.set_mode(display, DOUBLEBUF | OPENGL) gluPerspective(45, (display[0] / display[1]), 0.1, 50.0) glTranslatef(0.0, 0.0, -5) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() glRotatef(1, 3, 1, 1) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) Cube() pygame.display.flip() pygame.time.wait(10) main() |
Cuadrado de colores
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | import sys, math, pygame from operator import itemgetter class Point3D: def __init__(self, x=0, y=0, z=0): self.x, self.y, self.z = float(x), float(y), float(z) def rotateX(self, angle): """ Rotates the point around the X axis by the given angle in degrees. """ rad = angle * math.pi / 180 cosa = math.cos(rad) sina = math.sin(rad) y = self.y * cosa - self.z * sina z = self.y * sina + self.z * cosa return Point3D(self.x, y, z) def rotateY(self, angle): """ Rotates the point around the Y axis by the given angle in degrees. """ rad = angle * math.pi / 180 cosa = math.cos(rad) sina = math.sin(rad) z = self.z * cosa - self.x * sina x = self.z * sina + self.x * cosa return Point3D(x, self.y, z) def rotateZ(self, angle): """ Rotates the point around the Z axis by the given angle in degrees. """ rad = angle * math.pi / 180 cosa = math.cos(rad) sina = math.sin(rad) x = self.x * cosa - self.y * sina y = self.x * sina + self.y * cosa return Point3D(x, y, self.z) def project(self, win_width, win_height, fov, viewer_distance): """ Transforms this 3D point to 2D using a perspective projection. """ factor = fov / (viewer_distance + self.z) x = self.x * factor + win_width / 2 y = -self.y * factor + win_height / 2 return Point3D(x, y, self.z) class Simulation: def __init__(self, win_width=640, win_height=480): pygame.init() self.screen = pygame.display.set_mode((win_width, win_height)) pygame.display.set_caption("Figura de cubo 3D en python") self.clock = pygame.time.Clock() self.vertices = [ Point3D(-1, 1, -1), Point3D(1, 1, -1), Point3D(1, -1, -1), Point3D(-1, -1, -1), Point3D(-1, 1, 1), Point3D(1, 1, 1), Point3D(1, -1, 1), Point3D(-1, -1, 1) ] # Define the vertices that compose each of the 6 faces. These numbers are # indices to the vertices list defined above. self.faces = [(0, 1, 2, 3), (1, 5, 6, 2), (5, 4, 7, 6), (4, 0, 3, 7), (0, 4, 5, 1), (3, 2, 6, 7)] # Define colors for each face self.colors = [(25, 0, 55), (0, 100, 50), (10, 5, 50), (20, 30, 5), (30, 25, 25), (2, 55, 10)] self.angle = 0 def run(self): """ Main Loop """ while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() self.clock.tick(50) self.screen.fill((0, 32, 0)) # It will hold transformed vertices. t = [] for v in self.vertices: # Rotate the point around X axis, then around Y axis, and finally around Z axis. r = v.rotateX(self.angle).rotateY(self.angle).rotateZ(self.angle) # Transform the point from 3D to 2D p = r.project(self.screen.get_width(), self.screen.get_height(), 256, 4) # Put the point in the list of transformed vertices t.append(p) # Calculate the average Z values of each face. avg_z = [] i = 0 for f in self.faces: z = (t[f[0]].z + t[f[1]].z + t[f[2]].z + t[f[3]].z) / 4.0 avg_z.append([i, z]) i = i + 1 # Draw the faces using the Painter's algorithm: # Distant faces are drawn before the closer ones. for tmp in sorted(avg_z, key=itemgetter(1), reverse=True): face_index = tmp[0] f = self.faces[face_index] pointlist = [(t[f[0]].x, t[f[0]].y), (t[f[1]].x, t[f[1]].y), (t[f[1]].x, t[f[1]].y), (t[f[2]].x, t[f[2]].y), (t[f[2]].x, t[f[2]].y), (t[f[3]].x, t[f[3]].y), (t[f[3]].x, t[f[3]].y), (t[f[0]].x, t[f[0]].y)] pygame.draw.polygon(self.screen, self.colors[face_index], pointlist) self.angle += 1 pygame.display.flip() if __name__ == "__main__": Simulation().run() |
Triangulo 3D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * verticies = ( (1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, -1), (0,0,1) ) edges = ( (4,0), (4,1), (4,2), (4,3), (0,1), (0,3), (2,1), (2,3) ) def Cube(): glBegin(GL_LINES) for edge in edges: for vertex in edge: glVertex3fv(verticies[vertex]) glEnd() def main(): pygame.init() display = (800,600) pygame.display.set_mode(display, DOUBLEBUF|OPENGL) gluPerspective(45, (display[0]/display[1]), 0.1, 50.0) glTranslatef(0.0,0.0, -5) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() glRotatef(1, 3, 1, 1) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) Cube() pygame.display.flip() pygame.time.wait(10) main() |
Saludo P15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from Tkinter import * import tkMessageBox root = Tk() root.geometry("500x500") root.title("Saludador") et1 = Label(root, text = "Escribe un nombre para saludar").place(x=160,y=130) entrada =StringVar() entrada.set('') caja11 = Entry(root, textvariable = str (entrada)).place(x=170,y=180) b1 = Button(root, text = "Saludar", command = lambda: tkMessageBox.showinfo("Message", "Hola " + entrada.get() + "!")) .place(x=200,y=230) root.mainloop() |
Numero aleatorio desde el numero n hasta el numero n P14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | from Tkinter import * from random import * root = Tk() root.geometry("500x500") root.title("Generador de numeros") def funcion(): num = randint(int(aux.get()),int(aux2.get())) aux3.set(num) et1 = Label(root, text = "Numero 1").place(x=100,y=100) et2 = Label(root, text = "Numero 2").place(x=100,y=150) et3 = Label(root, text = "Numero generado").place(x=100,y=250) arr1=[1,2,3,4,5,6,7,8,9,10] arr2 = [1,2,3,4,5,6,7,8,9,10] aux = StringVar() aux2 = StringVar() aux3 = StringVar() s1 = Spinbox(root,textvariable = aux, values = arr1).place(x=300,y=100) s2 = Spinbox(root,textvariable = aux2, values = arr2).place(x=300,y=150) caja = Entry(root, textvariable =aux3).place(x=300,y=250) b1 = Button(root, text = "Generar",command = funcion).place(x=300,y=300) root.mainloop() |
Ingresar pelicula P13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | from Tkinter import * root = Tk() root.geometry("500x500") root.title("Peliculas") def fun(): x = aux2.get() pelis.append(x) lol = OptionMenu(root, aux, *pelis).place(x=350, y=140) et1 = Label(root, text = "Escribe el titulo de una pelicula").place(x=100,y=100) et2 = Label(root, text = "Peliculas").place(x=350,y=100) aux=StringVar() aux.set("") aux2=StringVar() pelis = [""] lol = OptionMenu(root,aux,*pelis).place(x=350,y=140) c1 = Entry(root, textvariable =aux2).place(x=100,y=140) b1 = Button(root, text = "Ingresar", command =fun).place(x=100, y=170) root.mainloop() |
Ruta del archivo P12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | from Tkinter import * from tkFileDialog import askopenfilename root = Tk() root.geometry("500x500") root.title("Mostrar ruta fichero") et1 = Label(root, text = "Pulsa en el boton y elige una ruta").place(x=150,y=70) def llamada(): nombre = StringVar() nombre.set(askopenfilename()) Entry(root, width = 40, textvariable=nombre).place(x=100, y=100) Entry(root,width = 40).place(x=100, y=100) Button(root, text ="...", command = llamada).place(x=370,y=100) root.mainloop() |
Mult P11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | # -*- coding: utf-8 -*- from Tkinter import * def hacer_click(): try: valor = int(entrada_texto.get()) valor = valor * 5 etiqueta.config(text=valor) except ValueError: etiqueta.config(text="Introduzca un valor") def hacer_click2(): try: valor2 = int(entrada_texto2.get()) valor2 = valor2 * 10 etiqueta2.config(text=valor2) except ValueError: etiqueta2.config(text="Introduzca un valor") def hacer_click3(): try: valor3 = int(entrada_texto3.get()) valor3 = valor3 * 15 etiqueta3.config(text=valor3) except ValueError: etiqueta3.config(text="Introduzca un valor") app = Tk() # marco de la aplicacion con el obj Tk vp = Frame(app) # usamos el objeto frame '''ahora le damos formato a nuestra ventana, y para eso vamos a utilizar el metodo grid(), el cual nos va a permitir posicionar los elementos graficos en nuestra ventana. otro parametro que utilizaremos sera el margen: padx = (50,50) lo cual indica 50 pixeles del lado izquierdo y 50 pixeles del lado derecho luego utilizamos pady = (10,10), que son 10 pixeles en la parte superior y 10 pixeles en la parte inferior''' vp.grid(column=0, row=0, padx=(50, 50), pady=(10, 10)) '''luego vamos a utilizar los metodos columnconfigure() y rowconfigure() los cuales nos van a servir para dar un peso relativo del ancho y el alto de todos los elementos que se pongan en la ventana''' vp.columnconfigure(0, weight=1) vp.rowconfigure(0, weight=1) '''creamos una etiqueta llamada valor y la posicionamos con el metodo grid()''' etiqueta = Label(vp, text="valor") # creo un objeto etiqueta etiqueta.grid(column=100, row=1) etiqueta2 = Label(vp, text="valor 2") etiqueta2.grid(column=100, row=4) etiqueta3 = Label(vp, text="valor 3") etiqueta3.grid(column=100, row=6) '''creamos un boton de OK y posicionamos con grid ''' boton = Button(vp, text="Multiplicar por 5", command=hacer_click) boton.grid(column=1, row=1) boton1 = Button(vp, text="Multiplicar por 10", command=hacer_click2) boton1.grid(column=1, row=4) boton2 = Button(vp, text="Multiplicar por 15", command=hacer_click3) boton2.grid(column=1, row=6) valor = "" entrada_texto = Entry(vp, width=10, textvariable=valor) entrada_texto.grid(column=2, row=1) valor2 = "" entrada_texto2 = Entry(vp, width=10, textvariable=valor2) entrada_texto2.grid(column=2, row=4) valor3 = "" entrada_texto3 = Entry(vp, width=10, textvariable=valor3) entrada_texto3.grid(column=2, row=6) app.mainloop() |
Calendario P10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #!/usr/bin/env phyton #- * - coding: utf - 8 -*- #Simple calendario con tkinter import calendar import Tkinter as tk import datetime ano = datetime.date.today ().year mes = datetime.date.today ().month def writeCalendar(ano, mes): str1 = calendar.month (ano, mes) label1.configure (text=str1) def mesAnterior(): global mes, ano mes -= 1 if ano == 0: mes = 12 ano -= 1 writeCalendar (ano, mes) def mesSiguiente(): global mes, ano mes += 1 if mes == 13: mes = 1 ano += 1 writeCalendar (ano, mes) root = tk.Tk () root.title ("Calendario") label1 = tk.Label (root, text="", font=('courier', 40, 'bold'), bg='white', justify=tk.LEFT) label1.grid (row=1, column=1) frame = tk.Frame (root, bd=5) anterior = tk.Button (frame, text="Anterior", command=mesAnterior) anterior.grid (row=1, column=1, sticky=tk.W) siguiente = tk.Button (frame, text="Siguiente", command=mesSiguiente) siguiente.grid (row=1, column=2) frame.grid (row=2, column=1) writeCalendar (ano, mes) root.mainloop () |
Ocultar/mostrar imagen P9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #Aportacion.- Alan Hernandez Mijangos #Programa.- que toma un archivo GIF y lo muestra al hacer clic en un boton # -*- coding: utf-8 -*-import Tkinter as tk from Tkinter import * ventana = Tk() ventana.geometry('400x400') ventana.config(bg="black") ventana.title("Mostrando y ocultando un boton con una imagen") def btn_hide(): if b1.winfo_ismapped(): b1.place_forget() b2.configure(text="Mostrar", width=30) else: b1.place(x=100, y=100) b2.configure(text="Ocultar", width=30) imgBoton = PhotoImage(file="icon.gif") b1 = Button(ventana, text="Boton 1", image=imgBoton, fg="black", width=200) b1.place(x=90, y=50) b2 = Button(ventana, text="Ocultar ", command=btn_hide, fg="black", width=15) b2.place(x=130, y=280) ventana.mainloop() |
Encriptador P8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | # -*- coding: utf-8 -*- from Tkinter import * # Jesus Eduardo Martinez Hinojosa # Ventana ventana = Tk() ventana.geometry("300x300+350+80") ventana.title("Encriptador") ventana.resizable(width=False, height=False) try: ventana.iconbitmap("icono.ico") except: print("no hay icono disponible") # Clave numclave = 1 # Funciones. def boton1(): # Cifrado Cesar TAM_MAX_CLAVE = 26 def obtenerModo(): modo = "e" return modo def obtenerMensaje(): mensaje = text.get("0.0", END) return mensaje def obtenerClave(): global numclave clave = numclave return clave def obtenerMensajeTraducido(modo, mensaje, clave): if modo[0] == 'd': clave = -clave traduccion = '' for simbolo in mensaje: if simbolo.isalpha(): num = ord(simbolo) num += clave if simbolo.isupper(): if num > ord('Z'): num -= 26 elif num < ord('A'): num += 26 elif simbolo.islower(): if num > ord('z'): num -= 26 elif num < ord('a'): num += 26 traduccion += chr(num) else: traduccion += simbolo return traduccion modo = obtenerModo() mensaje = obtenerMensaje() if modo[0] != 'b': clave = obtenerClave() if modo[0] != 'b': texto = (obtenerMensajeTraducido(modo, mensaje, clave)) text.delete("0.0", END) text.insert("0.0", texto) informe1.config(text="Texto Encriptado") else: for clave in range(1, TAM_MAX_CLAVE + 1): print(clave, obtenerMensajeTraducido('desencriptar', mensaje, clave)) def boton2(): # Cifrado Cesar TAM_MAX_CLAVE = 26 def obtenerModo(): modo = "d" return modo def obtenerMensaje(): mensaje = text.get("0.0", END) return mensaje def obtenerClave(): global numclave clave = numclave return clave def obtenerMensajeTraducido(modo, mensaje, clave): if modo[0] == 'd': clave = -clave traduccion = '' for simbolo in mensaje: if simbolo.isalpha(): num = ord(simbolo) num += clave if simbolo.isupper(): if num > ord('Z'): num -= 26 elif num < ord('A'): num += 26 elif simbolo.islower(): if num > ord('z'): num -= 26 elif num < ord('a'): num += 26 traduccion += chr(num) else: traduccion += simbolo return traduccion modo = obtenerModo() mensaje = obtenerMensaje() if modo[0] != 'b': clave = obtenerClave() if modo[0] != 'b': texto = (obtenerMensajeTraducido(modo, mensaje, clave)) text.delete("0.0", END) text.insert("0.0", texto) informe1.config(text="Texto Desencriptado") else: for clave in range(1, TAM_MAX_CLAVE + 1): print(clave, obtenerMensajeTraducido('desencriptar', mensaje, clave)) def salir(): ventana.destroy() def menu_activacion(event): menu_despegable.post(event.x_root, event.y_root) def cortar(): text.clipboard_clear() text.clipboard_append(text.selection_get()) sel = text.get(SEL_FIRST, SEL_LAST) text.delete(SEL_FIRST, SEL_LAST) def copiar(): text.clipboard_clear() text.clipboard_append(text.selection_get()) def pegar(): tem = text.selection_get(selection="CLIPBOARD") text.insert(INSERT, tem) # Widget b1 = Button(ventana, text="Encriptar", bg='black', fg='white', activebackground='cyan', activeforeground='dark slate gray', command=boton1, font=("Courier New", 9)) b2 = Button(ventana, text="Desencriptar", bg='black', fg='white', activebackground='cyan', activeforeground='dark slate gray', command=boton2, font=("Courier New", 9)) text = Text(ventana, fg='lavender', bg='dark slate gray', font=("Courier New", 10)) informe1 = Label(ventana, text="Ingrese un texto", bg="turquoise", font=("Courier New", 10)) b1.place(x=10, y=260, width=120, height=30) b2.place(x=167, y=260, width=120, height=30) informe1.place(x=0, y=0, width=300, height=30) text.place(x=0, y=30, height=218, width=300) menu_despegable = Menu(ventana, tearoff=0) menu_despegable.add_command(label="Cortar", command=cortar, font=("Courier New", 9)) menu_despegable.add_command(label="Copiar", command=copiar, font=("Courier New", 9)) menu_despegable.add_command(label="Pegar", command=pegar, font=("Courier New", 9)) menu_despegable.add_separator() menu_despegable.add_command(label="Salir", command=salir, font=("Courier New", 9)) text.bind(".", menu_activacion) ventana.mainloop() |
Suscribirse a:
Comentarios (Atom)





