Edificio en llamas, PyOpenGL

#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * ancho = 720 alto = 576 """ Inicializa OpenGL """ def initGL(): glClearColor(0.047, 0.717, 0.944, 0.0)#Azul cielo glClearDepth(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glEnable(GL_POLYGON_SMOOTH) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glShadeModel(GL_SMOOTH) resizeGL(ancho, alto) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) """ Acomoda la pantalla y la camara """ def resizeGL(ancho, alto): if alto == 0: alto = 1 glViewport(0, 0, ancho, alto) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45, float(ancho)/float(alto), 0.1, 100.0) glMatrixMode(GL_MODELVIEW) """ Posiciona la flama mediante los vertices de la ventana """ def burn(vertice1, vertice2, vertice3, vertice4, vertice5, vertice6,fuego): glBegin(GL_TRIANGLES) glColor3f(0.827, 0.133, 0.074) glVertex3f(vertice1, vertice2, 1.0) glColor3f(0.717, 0.305, 0.137) glVertex3f(vertice3, vertice4, 1.0) glColor3f(1.0, 1.0, 0.0) glVertex3f(vertice5, vertice6, 1.0) glEnd() glBegin(GL_TRIANGLES) glColor3f(0.827, 0.133, 0.074) glVertex3f(vertice1, vertice2, 1.0) glColor3f(0.717, 0.305, 0.137) glVertex3f(vertice3, vertice4, 1.0) glColor3f(0.800, 0.40, 0.0) glVertex3f((vertice5/1.3)+fuego, vertice6, 1.0) glEnd() glBegin(GL_TRIANGLES) glColor3f(0.827, 0.133, 0.074) glVertex3f(vertice1, vertice2, 1.0) glColor3f(0.717, 0.305, 0.137) glVertex3f(vertice3, vertice4, 1.0) glColor3f(0.800, 0.40, 0.0) glVertex3f(((vertice5/1.3)+(vertice5/1.8))-fuego, vertice6, 1.0) glEnd() glBegin(GL_TRIANGLES) glColor3f(0.827, 0.133, 0.074) glVertex3f(vertice1, vertice2, 1.0) glColor3f(0.717, 0.305, 0.137) glVertex3f(vertice3, vertice4, 1.0) glColor3f(0.800, 0.40, 0.0) glVertex3f((vertice5/2)+fuego, vertice6, 1.0) glEnd() glBegin(GL_TRIANGLES) glColor3f(0.827, 0.133, 0.074) glVertex3f(vertice1, vertice2, 1.0) glColor3f(0.717, 0.305, 0.137) glVertex3f(vertice3, vertice4, 1.0) glColor3f(0.800, 0.40, 0.0) glVertex3f(((vertice5/2)+(vertice5/1.8))-fuego, vertice6, 1.0) glEnd() """ Dibuja el edificio elemento por elemento """ def drawBuilding(fuego): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity() glTranslatef(0.0, 0.0, -6.) glPushMatrix() glShadeModel(GL_SMOOTH) burn(-0.718,0.558,-0.358,0.558,(-0.358-0.718)/2 ,(0.918 + 0.558)/2,fuego) glBegin(GL_QUADS)#Ventana glColor3f(1.0, 1.0, 1.0) glVertex3f(-0.358, 0.918, 1.0) glVertex3f(-0.718, 0.918, 1.0) glVertex3f(-0.718, 0.558, 1.0) glVertex3f(-0.358, 0.558, 1.0) glEnd() #burn(0.160,0.558,-0.200,0.558,(-0.200+0.160)/2 ,(0.918 + 0.558)/2,fuego) glBegin(GL_QUADS)#Ventana glColor3f(1.0, 1.0, 1.0) glVertex3f(-0.20, 0.918, 1.0) glVertex3f(0.160, 0.918, 1.0) glVertex3f(0.160, 0.558, 1.0) glVertex3f(-0.20, 0.558, 1.0) glEnd() burn(0.660,0.558,0.300,0.558,(0.300+0.660)/2 ,(0.918 + 0.558)/2,fuego) glBegin(GL_QUADS)#Ventana glColor3f(1.0, 1.0, 1.0) glVertex3f(0.300, 0.918, 1.0) glVertex3f(0.660, 0.918, 1.0) glVertex3f(0.660, 0.558, 1.0) glVertex3f(0.300, 0.558, 1.0) glEnd() burn(-0.718,-0.042,-0.358,-0.042,(-0.358-0.718)/2 ,(0.318 + 0.042)/2,fuego) glBegin(GL_QUADS)#Ventana glColor3f(1.0, 1.0, 1.0) glVertex3f(-0.358, 0.318, 1.0) glVertex3f(-0.718, 0.318, 1.0) glVertex3f(-0.718, -0.042, 1.0) glVertex3f(-0.358, -0.042, 1.0) glEnd() #burn(0.160,-0.042,-0.200,-0.042,(-0.200+0.160)/2 ,(0.318 + 0.042)/2,fuego) glBegin(GL_QUADS)#Ventana glColor3f(1.0, 1.0, 1.0) glVertex3f(-0.20, 0.318, 1.0) glVertex3f(0.160, 0.318, 1.0) glVertex3f(0.160, -0.042, 1.0) glVertex3f(-0.20, -0.042, 1.0) glEnd() burn(0.660,-0.042,0.300,-0.042,(0.300+0.660)/2 ,(0.318 + 0.042)/2,fuego) glBegin(GL_QUADS)#Ventana glColor3f(1.0, 1.0, 1.0) glVertex3f(0.300, 0.318, 1.0) glVertex3f(0.660, 0.318, 1.0) glVertex3f(0.660, -0.042, 1.0) glVertex3f(0.300, -0.042, 1.0) glEnd() burn(-0.718,-0.642,-0.358,-0.642,(-0.358-0.718)/2 ,(-0.282 - 0.642)/2,fuego) glBegin(GL_QUADS)#Ventana glColor3f(1.0, 1.0, 1.0) glVertex3f(-0.358, -0.282, 1.0) glVertex3f(-0.718, -0.282, 1.0) glVertex3f(-0.718, -0.642, 1.0) glVertex3f(-0.358, -0.642, 1.0) glEnd() #burn(0.160,-0.642,-0.200,-0.642,(-0.200+0.160)/2 ,(-0.282 - 0.642)/2,fuego) glBegin(GL_QUADS)#Ventana glColor3f(1.0, 1.0, 1.0) glVertex3f(-0.20, -0.282, 1.0) glVertex3f(0.160, -0.282, 1.0) glVertex3f(0.160, -0.642, 1.0) glVertex3f(-0.20, -0.642, 1.0) glEnd() burn(0.660,-0.642,0.300,-0.642,(0.300+0.660)/2 ,(-0.282 - 0.642)/2,fuego) glBegin(GL_QUADS)#Ventana glColor3f(1.0, 1.0, 1.0) glVertex3f(0.300, -0.282, 1.0) glVertex3f(0.660, -0.282, 1.0) glVertex3f(0.660, -0.642, 1.0) glVertex3f(0.300, -0.642, 1.0) glEnd() glBegin(GL_QUADS)#Puerta glColor3f(0.458, 0.294, 0.05) glVertex3f( 0.4, -0.9, 1.0) glVertex3f(-0.4, -0.9, 1.0) glVertex3f(-0.4, -1.5, 1.0) glVertex3f( 0.4, -1.5, 1.0) glEnd() glBegin(GL_QUADS)#Edificio glColor3f(0.10, 0.10, 0.10) glVertex3f( 1.0, 1.3, 1.0) glVertex3f(-1.0, 1.3, 1.0) glVertex3f(-1.0,-1.5, 1.0) glVertex3f( 1.0,-1.5, 1.0) glEnd() glBegin(GL_QUADS)#Piso glColor3f(0.0, 0.0, 0.0) glVertex3f( 3.0, -1.5, 1.0) glVertex3f(-3.0, -1.5, 1.0) glVertex3f(-3.0, -2.1, 1.0) glVertex3f( 3.0, -2.1, 1.0) glEnd() glPopMatrix() """ Principal """ if __name__ == '__main__': fuego = 0.02 contador = 0 glutInit(sys.argv) pygame.init() pygame.display.set_mode((ancho, alto),(OPENGL|DOUBLEBUF|GLUT_RGB)) pygame.display.set_caption("Edificio") resizeGL(ancho, alto) initGL() while True: contador = contador + 1 if ((contador%3) == 0): fuego = fuego * -1 keys = pygame.key.get_pressed() for eventos in pygame.event.get(): if eventos.type == QUIT: sys.exit(0) drawBuilding(fuego) pygame.display.flip()
Programa hecho con:

Pygame
PyOpenGL

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.