You are on page 1of 3

Computer Graphics 3d Project

To create a simple 3D model of a human using basic shapes like cones and cylinders,
you can use a Python library like PyOpenGL or Pygame. PyOpenGL provides a set of
Python bindings for OpenGL, which is a powerful 3D graphics API used to create
complex 3D scenes. Pygame, on the other hand, is a Python module used for
creating games and multimedia applications.

Here's an example of how you can create a simple 3D model of a human using
PyOpenGL:

import pygame

from pygame.locals import *

from OpenGL.GL import *

from OpenGL.GLU import *

def draw_cube():

glBegin(GL_QUADS)

glVertex3f(1.0, 1.0, -1.0)

glVertex3f(-1.0, 1.0, -1.0)

glVertex3f(-1.0, 1.0, 1.0)

glVertex3f(1.0, 1.0, 1.0)

glEnd()

def draw_human():

glPushMatrix()

glColor3f(1.0, 0.0, 0.0)

glTranslatef(0.0, 0.0, -5.0)

glRotatef(45, 0.0, 1.0, 0.0)

draw_cube()

glPopMatrix()

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.0)

while True:

for event in pygame.event.get():

if event.type == pygame.QUIT:

pygame.quit()

quit()

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)

draw_human()

pygame.display.flip()

pygame.time.wait(10)

main()

This code creates a red cube and rotates it at a 45-degree angle to create the body
of a human. To create the other parts of the human, you can use similar functions to
draw cones and cylinders, and use the glTranslatef() and glRotatef() functions to
position and rotate them in 3D space.

Note that this code only provides a basic starting point for creating a 3D model of a
human using Python. To create a more detailed and complex model, you will need to
use more advanced techniques and libraries, such as mesh modeling and texturing.

To install PyOpenGL and Pygame in PyCharm, you can follow these steps:

1. Open your PyCharm project and navigate to the terminal.


2. Type pip install PyOpenGL and press Enter to install PyOpenGL.
3. Type pip install pygame and press Enter to install Pygame.

Once the installation process is complete, you can import these libraries into your
Python code using the following lines of code:

import pygame

from pygame.locals import *

from OpenGL.GL import *

from OpenGL.GLU import *

You might also like