Exemplo n.º 1
0
def mainloop() :
  ''' Display function '''
  
  line_width=5
  bool_display_ls=True
  display_mode=0
  
  m=Matrix()
  #m.rotate_y(45)
  #m.rotate_z(45)
  m.rotate_x(90/2.0)
  m.load_hardware()
  
  toros=Toros(base_polygon=16,base_radius=7.5,toros_radius=15.5,display_mode="lined",lines_color=Color(ub_v=(127,127,127,0)),faces_color=Color(ub_v=(255,0,0)),lines_width=line_width,display_ls=True)
  while True :
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)  
    
    i=5.625/4.0
    m=Matrix()
    m.rotate_y(i)
    toros.update_pos(m)
    toros.display()
    
    
	
    for event in pygame.event.get() :
      ''' So we can catch user-interaction events in the mainloop. ''' 
      
      
      if event.type == QUIT      :         # The user close the window. 
        quit()
    
      elif event.type == KEYDOWN :         # The user press a keyboard key. 
        
        if event.key == K_m  or event.key == K_SEMICOLON :
	  display_mode += 1
	  if display_mode == 1 :
	    toros.set_display_mode("faced")
	  elif display_mode == 2 :
	    toros.set_display_mode("twice")  
	  elif display_mode == 3 :
	    display_mode=0
	    toros.set_display_mode("lined")
	    
	  
	elif event.key == K_l :
	  toros.set_lines_color(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
	  
	elif event.key == K_f :
	  toros.set_faces_color(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
	   
	    
	elif event.key == K_UP :
	  line_width += 1
	  
	  toros.set_lines_width(line_width)
	
	elif event.key == K_DOWN :
	  line_width -= 1
	  if line_width < 1 :
	    line_width=1
	  
	  toros.set_lines_width(line_width)  
	
	elif event.key == K_d :
	  if bool_display_ls :
	    bool_display_ls=False
	  else :
	    bool_display_ls=True
	    
	  toros.set_display_ls(bool_display_ls)
	
	elif event.key == K_s :
	  toros.set_toros_radius(uniform(1.0,20.0))
	  
	elif event.key == K_b :
	  toros.set_base_polygon(randint(3,32)) 
	  
	elif event.key == K_r :
	  toros.set_base_radius(uniform(1.0,20.0))    
	  
    
   
    
    pygame.display.flip()    
    sleep(0.000125)  
Exemplo n.º 2
0
def mainloop():
    ''' Display function '''

    line_width = 5
    bool_display_ls = True
    display_mode = 0

    faces_color_mode = 1

    color_faces = []
    for v in range(0, 20):
        color_faces.append(
            Color(ub_v=(randint(63, 255), randint(63, 255), randint(63, 255))))

    test_icosahedron = Icosahedron(12.5,
                                   display_mode="lined",
                                   lines_color=Color(ub_v=(127, 127, 127, 0)),
                                   faces_color=color_faces,
                                   lines_width=line_width,
                                   display_ls=True)
    i = 5.625 / 4.0
    m = Matrix()
    m.translate((15.5, 0.0, 0.0))
    test_icosahedron.update_pos(m)
    while True:

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        m = Matrix()
        m.translate((-test_icosahedron.center.wx, -test_icosahedron.center.wy,
                     -test_icosahedron.center.wz))
        m.rotate_x(i)
        m.rotate_y(i)
        m.rotate_z(i)
        m.translate((test_icosahedron.center.wx, test_icosahedron.center.wy,
                     test_icosahedron.center.wz))
        m.rotate_y(i)
        test_icosahedron.update_pos(m)
        test_icosahedron.display()

        for event in pygame.event.get():
            ''' So we can catch user-interaction events in the mainloop. '''

            if event.type == QUIT:  # The user close the window.
                quit()

            elif event.type == KEYDOWN:  # The user press a keyboard key.

                if event.key == K_m or event.key == K_SEMICOLON:
                    display_mode += 1
                    if display_mode == 1:
                        test_icosahedron.set_display_mode("faced")
                    elif display_mode == 2:
                        test_icosahedron.set_display_mode("twice")
                    elif display_mode == 3:
                        display_mode = 0
                        test_icosahedron.set_display_mode("lined")

                elif event.key == K_l:
                    test_icosahedron.set_lines_color(
                        Color(ub_v=(randint(63, 255), randint(63, 255),
                                    randint(63, 255))))

                elif event.key == K_f:
                    if faces_color_mode == 1:
                        test_icosahedron.set_faces_color(
                            Color(ub_v=(randint(63, 255), randint(63, 255),
                                        randint(63, 255))))
                        faces_color_mode = 0
                    elif faces_color_mode == 0:
                        color_faces = []
                        for v in range(0, 20):
                            color_faces.append(
                                Color(ub_v=(randint(63, 255), randint(63, 255),
                                            randint(63, 255))))
                        test_icosahedron.set_faces_color(color_faces)
                        faces_color_mode = 1

                elif event.key == K_UP:
                    line_width += 1

                    test_icosahedron.set_lines_width(line_width)

                elif event.key == K_DOWN:
                    line_width -= 1
                    if line_width < 1:
                        line_width = 1

                    test_icosahedron.set_lines_width(line_width)

                elif event.key == K_d:
                    if bool_display_ls:
                        bool_display_ls = False
                    else:
                        bool_display_ls = True

                    test_icosahedron.set_display_ls(bool_display_ls)

                elif event.key == K_s:
                    test_icosahedron.set_side_length(uniform(1.0, 15.5))
                    m = Matrix()
                    m.translate((15.5, 0.0, 0.0))
                    test_icosahedron.update_pos(m)

        pygame.display.flip()
        sleep(0.0001)
Exemplo n.º 3
0
def mainloop() :
  ''' Display function '''
  
  line_width=5
  bool_display_ls=True
  display_mode=0
  
  test_quad_sphere=Quad_Sphere(10.5,12,display_mode="lined",lines_color=Color(ub_v=(127,127,127,0)),faces_color=Color(ub_v=(255,0,0)),lines_width=line_width,display_ls=True)
  i=5.625/4.
  m=Matrix()
  m.translate((15.5,0.0,0.0))
  test_quad_sphere.update_pos(m)
  while True :
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)  
    
    m=Matrix()
    m.translate((-test_quad_sphere.center.wx,-test_quad_sphere.center.wy,-test_quad_sphere.center.wz))
    m.rotate_x(i)
    m.rotate_y(i)
    m.rotate_z(i)
    m.translate((test_quad_sphere.center.wx,test_quad_sphere.center.wy,test_quad_sphere.center.wz))
    m.rotate_y(i)
    test_quad_sphere.update_pos(m)
    test_quad_sphere.display()
    
    for event in pygame.event.get() :
      ''' So we can catch user-interaction events in the mainloop. ''' 
      
      
      if event.type == QUIT      :         # The user close the window. 
        quit()
    
      elif event.type == KEYDOWN :         # The user press a keyboard key. 
        
        if event.key == K_m  or event.key == K_SEMICOLON :
	  display_mode += 1
	  if display_mode == 1 :
	    test_quad_sphere.set_display_mode("faced")
	  elif display_mode == 2 :
	    test_quad_sphere.set_display_mode("twice")  
	  elif display_mode == 3 :
	    display_mode=0
	    test_quad_sphere.set_display_mode("lined")
	    
	  
	elif event.key == K_l :
	  test_quad_sphere.set_lines_color(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
	  
	elif event.key == K_f :
	  test_quad_sphere.set_faces_color(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
	    
	    
	elif event.key == K_UP :
	  line_width += 1
	  
	  test_quad_sphere.set_lines_width(line_width)
	
	elif event.key == K_DOWN :
	  line_width -= 1
	  if line_width < 1 :
	    line_width=1
	  
	  test_quad_sphere.set_lines_width(line_width)  
	
	elif event.key == K_d :
	  if bool_display_ls :
	    bool_display_ls=False
	  else :
	    bool_display_ls=True
	    
	  test_quad_sphere.set_display_ls(bool_display_ls)
	
	elif event.key == K_b :
	  test_quad_sphere.set_basis(randrange(6,24,2))
	  m=Matrix()
          m.translate((15.5,0.0,0.0))
          test_quad_sphere.update_pos(m)
	  
        elif event.key == K_s :
	  test_quad_sphere.set_radius(uniform(1.0,15.0))
	  m=Matrix()
          m.translate((15.5,0.0,0.0))
          test_quad_sphere.update_pos(m)
    
   
    
    pygame.display.flip()    
    sleep(0.000125)  
Exemplo n.º 4
0
def mainloop() :
  ''' Display function '''
  
  line_width=5
  bool_display_ls=True
  display_mode=0
  
  faces_color_mode=1
  
  quads_faces=[]
  for v in range(0,18) :
    quads_faces.append(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
  
  triangles_faces=[]
  for v in range(0,8) :
    triangles_faces.append(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
  
  poly32hedron=Poly26Hedron(7.5,display_mode="lined",lines_color=Color(ub_v=(127,127,127,0)),quads_color=quads_faces,triangles_color=triangles_faces,lines_width=line_width,display_ls=True)
  i=5.625/4.0
  m=Matrix()
  m.translate((15.5,0.0,0.0))
  poly32hedron.update_pos(m)
  while True :
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)  
    
    m=Matrix()
    m.translate((-poly32hedron.center.wx,-poly32hedron.center.wy,-poly32hedron.center.wz))
    m.rotate_x(i)
    m.rotate_y(i)
    m.rotate_z(i)
    m.translate((poly32hedron.center.wx,poly32hedron.center.wy,poly32hedron.center.wz))
    m.rotate_y(i)
    poly32hedron.update_pos(m)
    poly32hedron.display()
    
    for event in pygame.event.get() :
      ''' So we can catch user-interaction events in the mainloop. ''' 
      
      
      if event.type == QUIT      :         # The user close the window. 
        quit()
    
      elif event.type == KEYDOWN :         # The user press a keyboard key. 
        
        if event.key == K_m or event.key == K_SEMICOLON :
	  display_mode += 1
	  if display_mode == 1 :
	    poly32hedron.set_display_mode("faced")
	  elif display_mode == 2 :
	    poly32hedron.set_display_mode("twice")  
	  elif display_mode == 3 :
	    display_mode=0
	    poly32hedron.set_display_mode("lined")
	    
	  
	elif event.key == K_l :
	  poly32hedron.set_lines_color(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
	  
	elif event.key == K_f :
	  if faces_color_mode == 1 :
	    poly32hedron.set_quads_color(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
            poly32hedron.set_triangles_color(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
	    
            faces_color_mode=0

	  elif faces_color_mode == 0 :
	    quads_faces=[]
	    for v in range(0,18) :
	      quads_faces.append(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
	    
	    triangles_faces=[]
	    for v in range(0,8) :
	      triangles_faces.append(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))

	    poly32hedron.set_quads_color(quads_faces)
            poly32hedron.set_triangles_color(triangles_faces)
	    
            faces_color_mode=1
	    
	elif event.key == K_UP :
	  line_width += 1
	  
	  poly32hedron.set_lines_width(line_width)
	
	elif event.key == K_DOWN :
	  line_width -= 1
	  if line_width < 1 :
	    line_width=1
	  
	  poly32hedron.set_lines_width(line_width)  
	
	elif event.key == K_d :
	  if bool_display_ls :
	    bool_display_ls=False
	  else :
	    bool_display_ls=True
	    
	  poly32hedron.set_display_ls(bool_display_ls)
	
	elif event.key == K_s :
	  poly32hedron.set_side_length(uniform(1.0,10.0))
	  m=Matrix()
          m.translate((15.5,0.0,0.0))
          poly32hedron.update_pos(m)
	  
        
    
   
    
    pygame.display.flip()    
    sleep(0.0001)  
Exemplo n.º 5
0
def mainloop() :
  ''' Display function '''
  
  line_width=5
  bool_display_ls=True
  display_mode=0
  
  faces_color_mode=1
  
  test_tetrahedron=Tetrahedron(15.5,display_mode="lined",lines_color=Color(ub_v=(127,127,127,0)),faces_color=[Color(ub_v=(255,0,0)),Color(ub_v=(0,0,255)),Color(ub_v=(255,255,255)),Color(ub_v=(0,255,0))],lines_width=line_width,display_ls=True)
  i=5.625/4.0
  m=Matrix()
  m.translate((15.5,0.0,0.0))
  test_tetrahedron.update_pos(m)
  while True :
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)  
    
    m=Matrix()
    m.translate((-test_tetrahedron.center.wx,-test_tetrahedron.center.wy,-test_tetrahedron.center.wz))
    m.rotate_x(i)
    m.rotate_y(i)
    m.rotate_z(i)
    m.translate((test_tetrahedron.center.wx,test_tetrahedron.center.wy,test_tetrahedron.center.wz))
    m.rotate_y(i)
    test_tetrahedron.update_pos(m)
    test_tetrahedron.display()
    
    for event in pygame.event.get() :
      ''' So we can catch user-interaction events in the mainloop. ''' 
      
      
      if event.type == QUIT      :         # The user close the window. 
        quit()
    
      elif event.type == KEYDOWN :         # The user press a keyboard key. 
        
        if event.key == K_m  or event.key == K_SEMICOLON :
	  display_mode += 1
	  if display_mode == 1 :
	    test_tetrahedron.set_display_mode("faced")
	  elif display_mode == 2 :
	    test_tetrahedron.set_display_mode("twice")  
	  elif display_mode == 3 :
	    display_mode=0
	    test_tetrahedron.set_display_mode("lined")
	    
	  
	elif event.key == K_l :
	  test_tetrahedron.set_lines_color(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
	  
	elif event.key == K_f :
	  if faces_color_mode == 1 :
	    test_tetrahedron.set_faces_color(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
	    faces_color_mode=0
	  elif faces_color_mode == 0 :
	    test_tetrahedron.set_faces_color([Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))),Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))),
				              Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))),Color(ub_v=(randint(63,255),randint(63,255),randint(63,255)))
				              ]) 
	    faces_color_mode=1
	    
	elif event.key == K_UP :
	  line_width += 1
	  
	  test_tetrahedron.set_lines_width(line_width)
	
	elif event.key == K_DOWN :
	  line_width -= 1
	  if line_width < 1 :
	    line_width=1
	  
	  test_tetrahedron.set_lines_width(line_width)  
	
	elif event.key == K_d :
	  if bool_display_ls :
	    bool_display_ls=False
	  else :
	    bool_display_ls=True
	    
	  test_tetrahedron.set_display_ls(bool_display_ls)
	
	elif event.key == K_s :
	  test_tetrahedron.set_side_length(uniform(1.0,20.0))
	  m=Matrix()
          m.translate((15.5,0.0,0.0))
          test_tetrahedron.update_pos(m)
	  
        
    
   
    
    pygame.display.flip()    
    sleep(0.0001)  
Exemplo n.º 6
0
def mainloop() :
  ''' Display function '''
  
  line_width=5
  bool_display_ls=True
  display_mode=0
  
  faces_color_mode=1
  
  pentagons_faces=[]
  for v in range(0,12) :
    pentagons_faces.append(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
  
  hexagons_faces=[]
  for v in range(0,20) :
    hexagons_faces.append(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))

  fulleren=Fulleren(3.5,display_mode="lined",lines_color=Color(ub_v=(127,127,127,0)),pentagons_color=pentagons_faces,hexagons_color=hexagons_faces,lines_width=line_width,display_ls=True)
  i=5.625/4.0
  m=Matrix()
  m.translate((15.5,0.0,0.0))
  fulleren.update_pos(m)
  while True :
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)  
    
    m=Matrix()
    m.translate((-fulleren.center.wx,-fulleren.center.wy,-fulleren.center.wz))
    m.rotate_x(i)
    m.rotate_y(i)
    m.rotate_z(i)
    m.translate((fulleren.center.wx,fulleren.center.wy,fulleren.center.wz))
    m.rotate_y(i)
    fulleren.update_pos(m)
    fulleren.display()
    
    for event in pygame.event.get() :
      ''' So we can catch user-interaction events in the mainloop. ''' 
      
      
      if event.type == QUIT      :         # The user close the window. 
        quit()
    
      elif event.type == KEYDOWN :         # The user press a keyboard key. 
        
        if event.key == K_m  or event.key == K_SEMICOLON :
	  display_mode += 1
	  if display_mode == 1 :
	    fulleren.set_display_mode("faced")
	  elif display_mode == 2 :
	    fulleren.set_display_mode("twice")  
	  elif display_mode == 3 :
	    display_mode=0
	    fulleren.set_display_mode("lined")
	    
	  
	elif event.key == K_l :
	  fulleren.set_lines_color(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
	  
	elif event.key == K_f :
	  if faces_color_mode == 1 :
	    fulleren.set_pentagons_color(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
            fulleren.set_hexagons_color(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
	    
            faces_color_mode=0

	  elif faces_color_mode == 0 :
	    pentagons_faces=[]
	    for v in range(0,12) :
	      pentagons_faces.append(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))
	    
	    hexagons_faces=[]
	    for v in range(0,20) :
	      hexagons_faces.append(Color(ub_v=(randint(63,255),randint(63,255),randint(63,255))))

	    fulleren.set_pentagons_color(pentagons_faces)
            fulleren.set_hexagons_color(hexagons_faces)
	    
            faces_color_mode=1
	    
	elif event.key == K_UP :
	  line_width += 1
	  
	  fulleren.set_lines_width(line_width)
	
	elif event.key == K_DOWN :
	  line_width -= 1
	  if line_width < 1 :
	    line_width=1
	  
	  fulleren.set_lines_width(line_width)  
	
	elif event.key == K_d :
	  if bool_display_ls :
	    bool_display_ls=False
	  else :
	    bool_display_ls=True
	    
	  fulleren.set_display_ls(bool_display_ls)
	
	elif event.key == K_s :
	  fulleren.set_side_length(uniform(1.0,5.0))
	  m=Matrix()
          m.translate((15.5,0.0,0.0))
          fulleren.update_pos(m)
	  
        
    
   
    
    pygame.display.flip()    
    sleep(0.0001)  
Exemplo n.º 7
0
def mainloop():
    ''' Display function '''

    line_width = 5
    bool_display_ls = True
    display_mode = 0

    test_trigon_sphere = Trigon_Sphere(12.5,
                                       12,
                                       display_mode="lined",
                                       lines_color=Color(ub_v=(127, 127, 127,
                                                               0)),
                                       faces_color=Color(ub_v=(255, 0, 0)),
                                       lines_width=line_width,
                                       display_ls=True)
    i = 5.625 / 4.
    m = Matrix()
    m.translate((15.5, 0.0, 0.0))
    test_trigon_sphere.update_pos(m)
    while True:

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        m = Matrix()
        m.translate(
            (-test_trigon_sphere.center.wx, -test_trigon_sphere.center.wy,
             -test_trigon_sphere.center.wz))
        m.rotate_x(i)
        m.rotate_y(i)
        m.rotate_z(i)
        m.translate(
            (test_trigon_sphere.center.wx, test_trigon_sphere.center.wy,
             test_trigon_sphere.center.wz))
        m.rotate_y(i)
        test_trigon_sphere.update_pos(m)
        test_trigon_sphere.display()

        for event in pygame.event.get():
            ''' So we can catch user-interaction events in the mainloop. '''

            if event.type == QUIT:  # The user close the window.
                quit()

            elif event.type == KEYDOWN:  # The user press a keyboard key.

                if event.key == K_m or event.key == K_SEMICOLON:
                    display_mode += 1
                    if display_mode == 1:
                        test_trigon_sphere.set_display_mode("faced")
                    elif display_mode == 2:
                        test_trigon_sphere.set_display_mode("twice")
                    elif display_mode == 3:
                        display_mode = 0
                        test_trigon_sphere.set_display_mode("lined")

                elif event.key == K_l:
                    test_trigon_sphere.set_lines_color(
                        Color(ub_v=(randint(63, 255), randint(63, 255),
                                    randint(63, 255))))

                elif event.key == K_f:
                    test_trigon_sphere.set_faces_color(
                        Color(ub_v=(randint(63, 255), randint(63, 255),
                                    randint(63, 255))))

                elif event.key == K_UP:
                    line_width += 1

                    test_trigon_sphere.set_lines_width(line_width)

                elif event.key == K_DOWN:
                    line_width -= 1
                    if line_width < 1:
                        line_width = 1

                    test_trigon_sphere.set_lines_width(line_width)

                elif event.key == K_d:
                    if bool_display_ls:
                        bool_display_ls = False
                    else:
                        bool_display_ls = True

                    test_trigon_sphere.set_display_ls(bool_display_ls)

                elif event.key == K_b:
                    test_trigon_sphere.set_basis(randrange(8, 28, 4))
                    m = Matrix()
                    m.translate((15.5, 0.0, 0.0))
                    test_trigon_sphere.update_pos(m)

                elif event.key == K_s:
                    test_trigon_sphere.set_radius(uniform(1.0, 15.0))
                    m = Matrix()
                    m.translate((15.5, 0.0, 0.0))
                    test_trigon_sphere.update_pos(m)

        pygame.display.flip()
        sleep(0.000125)