Esempio 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)  
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)
Esempio n. 3
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)