Figuras en 3D de compañeros

*****Octaedro de Cynthia***** Información de la figura en el blog de Cynthia

Código
import pygame
from pygame.locals import *

from OpenGL.GL import *
from OpenGL.GLU import *

verticies = (
    (1, -1, 0),
    (1, 1, 0),
    (-1, 1, 0),
    (-1, -1, 0),
    (0, 0, 1.5),
    (0, 0, -1.5),

    )

edges = (
    (5, 0),
    (5, 1),
    (5, 2),
    (5, 3),
    (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)
        glColor(128,0,128)

        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        Cube()
        pygame.display.flip()
        pygame.time.wait(10)


main()


Resultado:



**************figura 3D Cassandra*********** La siguiente figura la diseño mi compañera Casandra, la cual podemos encontrar en su blog

Código
import pygame
from pygame.locals import *

from OpenGL.GL import *
from OpenGL.GLU import *

verticies = (
    (0.2,0.4,0),
    (0.4,0.2,0),
    (0.4,-0.2,0),
    (0.2,-0.4,0),
    (-0.2,-0.4,0),
    (-0.4,-0.2,0),
    (-0.4,0.2,0),
    (-0.2,0.4,0),

    (0.2,0.4,1.5),
    (0.4,0.2,1.5),
    (0.4,-0.2,1.5),
    (0.2,-0.4,1.5),
    (-0.2,-0.4,1.5),
    (-0.4,-0.2,1.5),
    (-0.4,0.2,1.5),
    (-0.2,0.4,1.5)
    )

edges = (
    (0,1),
    (1,2),
    (2,3),
    (3,4),
    (4,5),
    (5,6),
    (6,7),
    (7,0),

    (8,9),
    (9,10),
    (10,11),
    (11,12),
    (12,13),
    (13,14),
    (14,15),
    (15,8),

    (0,8),
    (1,9),
    (2,10),
    (3,11),
    (4,12),
    (5,13),
    (6,14),
    (7,15)

    )


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


Resultado:

********Diamante 3D por Alexis*********
La siguiente figura fue creada por mi compañero Alexis, la explicación esta en su blog
Código
import pygame
from pygame.locals import *

from OpenGL.GL import *
from OpenGL.GLU import *

verticies = (
    (-0.5,-0.87,1.5),#0
    (0.5,-0.87,1.5),#1
    (1,0,1.5),#2
    (0.5,0.87,1.5),#3
    (-0.5,0.87,1.5),#4
    (-1,0,1.5),#5

    (-1,-1.73,1),#6
    (1,-1.73,1),#7
    (2,0,1),#8
    (1,1.73,1),#9
    (-1,1.73,1),#10
    (-2,0,1),#11

    (0,0,-1.5),#12



    )

edges = (
    (0,1),
    (1,2),
    (2,3),
    (3,4),
    (4,5),
    (5,0),


    (6,7),
    (7,8),
    (8,9),
    (9,10),
    (10,11),
    (11,6),

    (12,6),
    (12,7),
    (12,8),
    (12,9),
    (12,10),
    (12,11),

    (0,6),
    (1,7),
    (2,8),
    (3,9),
    (4,10),
    (5,11),

    )


def Cube():
    glBegin(GL_LINES)
    for edge in edges:
        for vertex in edge:
            glVertex3fv(verticies[vertex])
    glEnd()


def main():
    pygame.init()
    display = (1000,800)
    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(25)


main()


Resultado:

*****Cubo en movimiento Hugo******
El siguiente cubo fue presentado por el compañero Hugo, el cual se mueve con las teclas de flechas, podemos verlo en su blog.

import pygame
from pygame.locals import *
import random
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)
)

surfaces = (
    (0, 1, 2, 3),
    (3, 2, 7, 6),
    (6, 7, 5, 4),
    (4, 5, 1, 0),
    (1, 5, 7, 2),
    (4, 0, 3, 6)
)

colors = (
    (1, 0, 0),
    (0, 1, 0),
    (0, 0, 1),
    (0, 1, 0),
    (1, 1, 1),
    (0, 1, 1),
    (1, 0, 0),
    (0, 1, 0),
    (0, 0, 1),
    (1, 0, 0),
    (1, 1, 1),
    (0, 1, 1),
)


def Cube():
    glBegin(GL_QUADS)
    for surface in surfaces:
        x = 0
        for vertex in surface:
            x += 1
            glColor3fv(colors[x])
            glVertex3fv(verticies[vertex])
    glEnd()

    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)

    # start further back
    glTranslatef(random.randrange(-5, 5), 0, -30)

    object_passed = False
    while not object_passed:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    glTranslatef(-0.5, 0, 0)
                if event.key == pygame.K_RIGHT:
                    glTranslatef(0.5, 0, 0)

                if event.key == pygame.K_UP:
                    glTranslatef(0, 1, 0)
                if event.key == pygame.K_DOWN:
                    glTranslatef(0, -1, 0)
            '''
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 4:
                    glTranslatef(0,0,1.0)

                if event.button == 5:
                    glTranslatef(0,0,-1.0)
            '''
            x = glGetDoublev(GL_MODELVIEW_MATRIX)
            camera_x = x[3][0]
            camera_y = x[3][1]
            camera_z = x[3][2]
            glTranslatef(0, 0, 0.5)

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            Cube()
            pygame.display.flip()

            if camera_z <= 0:
                object_passed = True


for x in range(10):
    main()


Resultado:

Comentarios

Entradas más populares de este blog

Ejercicios en PyCharm

1.1 Aplicaciones gráficas por computadora.

Ensayo de lenguaje ensamblador