Entradas

Mostrando las entradas de 2017

Gráfico de barras 3D

Imagen
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='#00ceaa') plt.show()

Figuras 3D en Python

Cubo 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

Video: 3D en python

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

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

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