Entradas

Mostrando entradas de noviembre, 2017

Estrellita

Imagen
import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * verticies = (     (0,2.5,0),     (1,1,0),     (3,1,0),     (1.5,-.5,0),     (2.5,-3,0),     (0,-2,0),     (-2.5,-3,0),     (-1.5,-.5,0),     (-3,1,0),     (-1,1,0),     (0,0,.5),     (0,0,-.5) ) edges = ( (0,1),(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,8),(8,9),(9,0), (0,10),(1,10),(2,10),(3,10),(4,10),(5,10),(6,10),(7,10),(8,10),(9,10), (0,11),(1,11),(2,11),(3,11),(4,11),(5,11),(6,11),(7,11),(8,11),(9,11)     ) 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(50, (display[0]/display[1]), 0.1, 50.0)     glTranslatef(0.0,0.0, -10)     while True:         for event in pygame.event.get():             if event.type == pygame.QUIT:          

Cubito de colores

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

Cubito y Triangulito

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() ---------------------------------------------------------------------------------------------- import pygame from pyga