コード例 #1
0
ファイル: pyglutCube.py プロジェクト: mrcyberfighter/pyglut
 def set_side_length(self,side_length) :
   if not isinstance(side_length,int) and not isinstance(side_length,float) :
     raise TypeError("Argument side_length",int,float)
   elif side_length < 0.0 :
     raise ValueError("Value of argument side_length must be greater than 0.0") 
   
   self.side_length=side_length
   self.polyhedron=generate_cube(side_length)
   self.ls=Localview()
コード例 #2
0
 def set_radius(self,radius) :
   ''' Change the trigon sphere radius. '''
   
   if not isinstance(radius,int) and not isinstance(radius,float) :
     raise TypeError(int,float)
   elif radius < 0.0 :
     raise ValueError("Value of radius must be greater than 0.0") 
   
   self.radius=radius
   self.trigons=generate_trigon_sphere(self.basis,radius)[0]
   self.ls=Localview()
コード例 #3
0
ファイル: pyglutToros.py プロジェクト: mrcyberfighter/pyglut
 def set_toros_radius(self,toros_radius) :
   ''' Change the toros radius (without the base polygon radius). '''
   
   if not isinstance(toros_radius,int) and not isinstance(toros_radius,float) :
     raise TypeError("toros_radius argument",int,float)
   elif toros_radius <= 0.0 :
     raise ValueError("Value of toros_radius must be greater than 0.0") 
   
   self.toros_radius=toros_radius
   self.toros=generate_toros(self.base_polygon,self.base_radius,toros_radius)
   self.ls=Localview()
コード例 #4
0
    def set_side_length(self, side_length):
        if not isinstance(side_length, int) and not isinstance(
                side_length, float):
            raise TypeError("Argument side_length", int, float)
        elif side_length < 0.0:
            raise ValueError(
                "Value of argument side_length must be greater than 0.0")

        self.side_length = side_length
        self.hexagons, self.pentagons = generate_fulleren(side_length)
        self.ls = Localview()
コード例 #5
0
  def set_basis(self,basis) :
    ''' Change the trigon sphere basis. '''
    
    if not isinstance(basis,int) :
      raise TypeError(int)

    if basis < 6 or basis % 2 :
      print "the basis for the sphere must be greater as 5 and basis % 2 == 0 "
      quit()
    
    self.basis=basis
    self.trigons=generate_trigon_sphere(basis,self.radius)[0]
    self.ls=Localview()
コード例 #6
0
ファイル: pyglutToros.py プロジェクト: mrcyberfighter/pyglut
  def set_base_polygon(self,base_polygon) :
    ''' Change the toros basis polygon. '''
    
    if not isinstance(base_polygon,int) :
      raise TypeError("base_polygon argument",int)

    if base_polygon <= 2 :
      print "the base polygon must be greater than 2 "
      quit()
    
    
    self.base_polygon=base_polygon
    self.toros=generate_toros(base_polygon,self.base_radius,self.toros_radius)
    self.ls=Localview()
コード例 #7
0
ファイル: pyglutIcosahedron.py プロジェクト: PyMine/PyMine
 def set_side_length(self,side_length) :
   if not isinstance(side_length,int) and not isinstance(side_length,float) :
     raise TypeError("Argument side_length",int,float)
   elif side_length < 0.0 :
     raise ValueError("Value of argument side_length must be greater than 0.0") 
   
   self.side_length=side_length
   self.polyhedron=generate_icosahedron(side_length)[1]
   self.ls=Localview()
コード例 #8
0
ファイル: pyglut26hedron.py プロジェクト: PyMine/PyMine
 def set_side_length(self,side_length) :
   if not isinstance(side_length,int) and not isinstance(side_length,float) :
     raise TypeError("Argument side_length",int,float)
   elif side_length < 0.0 :
     raise ValueError("Value of argument side_length must be greater than 0.0") 
   
   self.side_length=side_length
   self.triangles,self.quads=generate_polyhedron_26_faces(side_length)
   self.ls=Localview()
コード例 #9
0
ファイル: pyglutFulleren.py プロジェクト: PyMine/PyMine
 def set_side_length(self,side_length) :
   if not isinstance(side_length,int) and not isinstance(side_length,float) :
     raise TypeError("Argument side_length",int,float)
   elif side_length < 0.0 :
     raise ValueError("Value of argument side_length must be greater than 0.0") 
   
   self.side_length=side_length
   self.hexagons,self.pentagons=generate_fulleren(side_length) 
   self.ls=Localview()
コード例 #10
0
ファイル: pyglutFulleren.py プロジェクト: PyMine/PyMine
class Fulleren(object) :
  def __init__(self,side_length,display_mode="lined",lines_color=False,pentagons_color=False,hexagons_color=False,lines_width=1,display_ls=False) :
    ''' generate an cube object with the given side length settings.
    
        display_mode    = "lined" -> only the lines will be displayed.
        display_mode    = "faced" -> only the faces will be displayed.
        display_mode    = "twice" -> The lines and the faces will be displayed.
        lines_color     = an objet <type 'Color'> representing the lines color.
        pentagons_color = an objet <type 'Color'> representing the pentagons color.
                          an 12-items-list contains <type 'Color'> objects.  
        hexagons_color  = an objet <type 'Color'> representing the hexagons color.
                          an 20-items-list contains <type 'Color'> objects. 
        line_width      = an integer representing the lines width.
    '''
    
    if not isinstance(side_length,int) and not isinstance(side_length,float) :
      raise TypeError(int,float)
    elif side_length <= 0.0 :
      raise ValueError("Value of side_length must be greater than 0.0") 
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("lined","faced","twice")
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError(lines_color,Color)
      
    
    if pentagons_color :
      if not isinstance(pentagons_color,Color) and not isinstance(pentagons_color,list) :
        raise TypeError(pentagons_color,Color,list)
      elif isinstance(pentagons_color,list) and len(pentagons_color) != 12 :
	print "Error pentagons_color argument:\nYou must give an list from 12 Color objects.\nOne Color object per face."
	quit()
      elif isinstance(pentagons_color,list) and len(pentagons_color) == 12 :
        tmp=[]
        pentagons_color_index=0
        while pentagons_color_index < 12 :
	  if type(pentagons_color[pentagons_color_index].a) == bool :
	    pentagons_color[pentagons_color_index].a=0
	  pentagons_color_index += 1
      
    if hexagons_color :
      if not isinstance(hexagons_color,Color) and not isinstance(hexagons_color,list) :
        raise TypeError(hexagons_color,Color,list)
      elif isinstance(hexagons_color,list) and len(hexagons_color) != 20 :
	print "Error hexagons_color argument:\nYou must give an list from 20 Color objects.\nOne Color object per face."
	quit()
      elif isinstance(hexagons_color,list) and len(hexagons_color) == 20 :
        tmp=[]
        hexagons_color_index=0
        while hexagons_color_index < 20 :
	  if type(hexagons_color[hexagons_color_index].a) == bool :
	    hexagons_color[hexagons_color_index].a=0
	  hexagons_color_index += 1    
        
    
    if not isinstance(lines_width,int) :
      raise TypeError(lines_width,int)
    elif lines_width < 1 :
      raise ValueError(lines_width,"Lines width value too little.") 
    
    if isinstance(lines_color,Color) :
      if type(lines_color.a) == bool :
        lines_color.a=0
    
    if isinstance(pentagons_color,Color) :
      if type(pentagons_color.a) == bool :
	pentagons_color.a=0
	
    if isinstance(hexagons_color,Color) :
      if type(hexagons_color.a) == bool :
	hexagons_color.a=0 	
    
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    
    self.side_length=side_length
    self.lines_color=lines_color
    self.pentagons_color=pentagons_color
    self.hexagons_color=hexagons_color
    self.lines_width=lines_width
    self.hexagons,self.pentagons=generate_fulleren(side_length)
    self.ls=Localview()
    
    self.center=Vertex(0.0,0.0,0.0)    
    
  def update_pos(self,matrix) :
    ''' Apply changing contains in the matrix argument. '''
    
    if not isinstance(matrix, Matrix) :
      raise TypeError(matrix,Matrix)
    
    center=[]
    tmp_pentagons=[]
    for polygon in self.pentagons :
      # Loop over every pentagon from the polyhedron. 
      tmp_polygon=[]
      for lines in polygon :
	tmp_lines=[]
	for vertex in lines :
	  # Loop over every vertice from the polygon.
	  res_vertex= matrix * vertex # Multiply the current vertice with the matrix
	  
	  # Storing the new position from the vertice.
	  tmp_lines.append(res_vertex)  # For the polyhedron polygon container.
	  center.append(res_vertex)       # For polyhedron center computing.
	  
	tmp_polygon.append(tmp_lines)  
      tmp_pentagons.append(tmp_polygon)
    
    self.pentagons=tmp_pentagons          # Update the pentagon container with the new postion from every vertice.
    
    tmp_hexagons=[]
    for polygon in self.hexagons :
      # Loop over every hexagon from the polyhedron. 
      tmp_polygon=[]
      for lines in polygon :
	tmp_lines=[]
	for vertex in lines :
	  # Loop over every vertice from the polygon.
	
	  res_vertex= matrix * vertex # Multiply the current vertice with the matrix
	  
	  # Storing the new position from the vertice.
	  tmp_lines.append(res_vertex)  # For the polyhedron polygon container.
	  center.append(res_vertex)       # For polyhedron center computing.
	
	tmp_polygon.append(tmp_lines)  
      tmp_hexagons.append(tmp_polygon)
    
    self.hexagons=tmp_hexagons            # Update the hexagon container with the new postion from every vertice.
    
    self.center=get_center_from_polyhedron(center)  # Update the polyhedron center.  
    
    self.ls= matrix * self.ls                       # Update the localview.
    
    
    
  def display(self) :
    
    if self.display_mode == "lined" :
      # Configuration of polygons lines displaying.
      glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)
      
      if self.lines_color :
	# Lines color configuration. 
	glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)
    
    
      for polygon in self.hexagons :
	# Loop over every hexagon from the polyhedron. 
	# For only lines displaying.
        glBegin(GL_POLYGON)
        for lines in polygon :
	  for v in lines :
	    # We loop over the every vertice from the polygon.
	    glVertex3fv(v.get_vertex())
        glEnd()	
      
    
    elif self.display_mode == "faced" :
      # Configuration of polygons faces displaying.
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
      if self.pentagons_color and isinstance(self.pentagons_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.pentagons_color.get_ubyte_v())
      
      
	
      pentagons_color_index=0  # Iterator, case there are more than one color for the faces displaying.	
	
      if self.pentagons_color and isinstance(self.pentagons_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.pentagons_color.get_ubyte_v())
      
      for polygon in self.pentagons :
	# Loop over every pentagon from the polyhedron. 
	if self.pentagons_color and isinstance(self.pentagons_color,list) : 
	  # Case there are more than one color for the faces displaying.
	  glColor4ubv(self.pentagons_color[pentagons_color_index].get_ubyte_v())
	  
	glBegin(GL_POLYGON)
	for lines in polygon :
	  for v in lines :
	    # We loop over the every vertice from the polygon.
	    glVertex3fv(v.get_vertex())
	glEnd()	
    
	pentagons_color_index += 1
      
      if self.hexagons_color and isinstance(self.hexagons_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.hexagons_color.get_ubyte_v())
	
      hexagons_color_index=0  # Iterator, case there are more than one color for the faces displaying. 	
	
      for polygon in self.hexagons :
	# Loop over every hexagon from the polyhedron. 
	if self.hexagons_color and isinstance(self.hexagons_color,list) : 
	  # Case there are more than one color for the faces displaying.
	  glColor4ubv(self.hexagons_color[hexagons_color_index].get_ubyte_v())
	  
	glBegin(GL_POLYGON)
	for lines in polygon :
	  for v in lines :
	    # We loop over the every vertice from the polygon.
	    glVertex3fv(v.get_vertex())
	glEnd()
	hexagons_color_index += 1
      
    elif self.display_mode == "twice" :
      # Configuration of polygons faces displaying.
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
      if self.pentagons_color and isinstance(self.pentagons_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.pentagons_color.get_ubyte_v())
      
      
	
      pentagons_color_index=0	
      for polygon in self.pentagons :
	# Loop over every pentagon from the polyhedron. 
	if self.pentagons_color and isinstance(self.pentagons_color,list) : 
	  # Case there are more than one color for the faces displaying.
	  glColor4ubv(self.pentagons_color[pentagons_color_index].get_ubyte_v())
	  
	glBegin(GL_POLYGON)
	for lines in polygon :
	  for v in lines :
	    # We loop over the every vertice from the polygon.
	    glVertex3fv(v.get_vertex())
	glEnd()	
    
	pentagons_color_index += 1
      
      if self.hexagons_color and isinstance(self.hexagons_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.hexagons_color.get_ubyte_v())
	
      hexagons_color_index=0  # Iterator, case there are more than one color for the faces displaying.	
	
      for polygon in self.hexagons :
	# Loop over every hexagon from the polyhedron. 
	if self.hexagons_color and isinstance(self.hexagons_color,list) :
	  # Case there are more than one color for the faces displaying.
	  glColor4ubv(self.hexagons_color[hexagons_color_index].get_ubyte_v())
	  
	glBegin(GL_POLYGON)
	for lines in polygon :
	  for v in lines :
	    # We loop over the every vertice from the polygon.
	    glVertex3fv(v.get_vertex())
	glEnd()
	
	hexagons_color_index += 1
      
      # Configuration of polygons lines displaying.
      glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)
      
      if self.lines_color :
	# Lines color configuration. 
	glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)
    
    
      for polygon in self.hexagons :
	# Loop over every hexagon from the polyhedron.
	# For only lines displaying.
        glBegin(GL_POLYGON)
        for lines in polygon :
	  for v in lines :
	    # We loop over the every vertice from the polygon.
	    glVertex3fv(v.get_vertex())
        glEnd()	
      
    if self.display_ls :
      # Displaying the Localview.
      self.ls.display(self.side_length*4.0/10.0)
      
  def set_display_mode(self,display_mode) :
    ''' Change the polyhedron display mode. 
        Value of argument display_mode should be:
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces willbe displayed.
    '''
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("lined","faced","twice")
    
    self.display_mode=display_mode
    
  def set_lines_color(self,lines_color) :
    ''' Change the lines color from the polyhedron.
        Value of argument lines_color should be:
        lines_color  = An objet <type 'Color'> representing the lines color.
    '''
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
      
      if isinstance(lines_color.a,bool) :
	lines_color.a=0
	
    self.lines_color=lines_color
    
  def set_pentagons_color(self,pentagons_color) :
    ''' Change the faces color(s) from the polyhedron.
        Value of argument faces_color should be:
        faces_color  = An objet <type 'Color'> representing the pentagons faces color.
                       An 12-items-list from object <type 'Color'>.
                       One item per pentagon face. 
    '''
    
    if pentagons_color :
      
      if not isinstance(pentagons_color,Color) and not isinstance(pentagons_color,list) :
        raise TypeError(pentagons_color,Color,list)
      
      elif isinstance(pentagons_color,list) and len(pentagons_color) != 12 :
	print "Error pentagons_color argument:\nYou must give an list from 12 Color objects.\nOne Color object per face."
	quit()
	
      elif isinstance(pentagons_color,list) and len(pentagons_color) == 12 :
        tmp=[]
        pentagons_color_index=0
        while pentagons_color_index < 12 :
	  if type(pentagons_color[pentagons_color_index].a) == bool :
	    pentagons_color[pentagons_color_index].a=0
	  pentagons_color_index += 1
    
      elif isinstance(pentagons_color,Color) :
	if type(pentagons_color.a) == bool :
	    pentagons_color.a=0	  
      
      else :
	raise TypeError(Color)
      
      self.pentagons_color=pentagons_color
    
  def set_hexagons_color(self,hexagons_color) :
    ''' Change the faces color(s) from the polyhedron.
        Value of argument faces_color should be:
        faces_color  = An objet <type 'Color'> representing the hexagons faces color.
                       An 20-items-list from object <type 'Color'>.
                       One item per hexagons face. 
    '''
    
    if hexagons_color :
      
      if not isinstance(hexagons_color,Color) and not isinstance(hexagons_color,list) :
        raise TypeError(hexagons_color,Color,list)
      
      elif isinstance(hexagons_color,list) and len(hexagons_color) != 20 :
	print "Error hexagons_color argument:\nYou must give an list from 20 Color objects.\nOne Color object per face."
	quit()
      
      elif isinstance(hexagons_color,list) and len(hexagons_color) == 20 :
        tmp=[]
        hexagons_color_index=0
        while hexagons_color_index < 20 :
	  if type(hexagons_color[hexagons_color_index].a) == bool :
	    hexagons_color[hexagons_color_index].a=0
	  hexagons_color_index += 1    
      
      elif isinstance(hexagons_color,Color) :
	if type(hexagons_color.a) == bool :
	    hexagons_color.a=0	  
      
      else :
	raise TypeError(Color)
      
      self.hexagons_color=hexagons_color  
    
  def set_lines_width(self,lines_width) :
    ''' Change the lines width from the polyhedron.
        Value of argument lines_width should be:
        lines_width  = An integer representing the lines width.
    '''
    if not isinstance(lines_width,int) :
      raise TypeError("Argument lines_width",int)
    elif lines_width < 1 :
      raise ValueError(lines_width,"Lines width value too little.") 
    
    self.lines_width=lines_width
    
  def set_display_ls(self,display_ls) :
    ''' Change the Localview displaying setting.
        Value of argument display_ls should be an boolean value:
        display_ls   = Define if the localview should be display.
    '''    
        
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    else :
      raise TypeError("Argument display_ls",bool)
    
  def set_side_length(self,side_length) :
    if not isinstance(side_length,int) and not isinstance(side_length,float) :
      raise TypeError("Argument side_length",int,float)
    elif side_length < 0.0 :
      raise ValueError("Value of argument side_length must be greater than 0.0") 
    
    self.side_length=side_length
    self.hexagons,self.pentagons=generate_fulleren(side_length) 
    self.ls=Localview()
  
  def __doc__(self) :
    ''' Print documentation '''
    
    print '''
    Generate an fulleren object with position updating, 
    display and settings setters methods.
    
    The display mode set how the fulleren will be display 
    and can take as values:
    "lined" -> Only the edges will be display.
    "faces" -> Only the faces willbbe display.
    "twice" -> The edges and the faces will be display.
    
    The lines color must be an object from <type 'Color'> available throught
    this module as datatype dealing with colors as unsigned bytes 
    or floating-points values.
    
    The pentagons_color color can be:
    -> An object from <type 'Color'> in which case the fulleren pentagons 
       will be filled with this color.
    -> Or an 12-items-list from <type 'Color'> objects.
       1 item per pentagon.
       
    The hexagons_color color can be:
    -> An object from <type 'Color'> in which case the fulleren hexagons 
       will be filled with this color.
    -> Or an 20-items-list from <type 'Color'> objects.
       1 item per hexagon.
    
    The lines width must be an integer representing the number of pixels from 
    the edges width.
    
    The display_ls argument must be an boolean value point to if the polyhedron 
    own Localview will be displayed. 
    The datatype Localview is available throught this module. 
    sea his documentation to know more about.
    
    '''      
コード例 #11
0
ファイル: pyglut26hedron.py プロジェクト: PyMine/PyMine
  def __init__(self,side_length,display_mode="lined",lines_color=False,quads_color=False,triangles_color=False,lines_width=1,display_ls=False) :
    ''' generate an 26 faces polyhedron object with the given side length settings.
           
        display_mode    = "lined" -> only the lines will be displayed.
        display_mode    = "faced" -> only the faces will be displayed.
        display_mode    = "twice" -> The lines and the faces will be displayed.
        lines_color     = an objet <type 'Color'> representing the lines color.
        quads_color     = an objet <type 'Color'> representing the quads color.
                          an 18-items-list contains <type 'Color'> objects.  
        triangles_color = an objet <type 'Color'> representing the triangles color.
                          an 8-items-list contains <type 'Color'> objects. 
        line_width      = an integer representing the lines width.
    '''
    
    if not isinstance(side_length,int) and not isinstance(side_length,float) :
      raise TypeError(int,float)
    elif side_length < 0.0 :
      raise ValueError("Value of side_length must be greater than 0.0") 
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("lined","faced","twice")
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError(lines_color,Color)
    
    if quads_color :
      if not isinstance(quads_color,Color) and not isinstance(quads_color,list) :
        raise TypeError(quads_color,Color,list)
      elif isinstance(quads_color,list) and len(quads_color) != 18 :
	print "Error quads_color argument:\nYou must give an list from 18 Color objects.\nOne Color object per face."
	quit()
      elif isinstance(quads_color,list) and len(quads_color) == 18 :
        tmp=[]
        quads_color_index=0
        while quads_color_index < 18 :
	  if type(quads_color[quads_color_index].a) == bool :
	    quads_color[quads_color_index].a=0
	  quads_color_index += 1
      
    if triangles_color :
      if not isinstance(triangles_color,Color) and not isinstance(triangles_color,list) :
        raise TypeError(triangles_color,Color,list)
      elif isinstance(triangles_color,list) and len(triangles_color) != 8 :
	print "Error triangles_color argument:\nYou must give an list from 8 Color objects.\nOne Color object per face."
	quit()
      elif isinstance(triangles_color,list) and len(triangles_color) == 8 :
        tmp=[]
        triangles_color_index=0
        while triangles_color_index < 8 :
	  if type(triangles_color[triangles_color_index].a) == bool :
	    triangles_color[triangles_color_index].a=0
	  triangles_color_index += 1    
        
    
    if not isinstance(lines_width,int) :
      raise TypeError(lines_width,int)
    elif lines_width < 1 :
      raise ValueError(lines_width,"Lines width value too little.") 
    
    if isinstance(lines_color,Color) :
      if type(lines_color.a) == bool :
        lines_color.a=0
    
    if isinstance(quads_color,Color) :
      if type(quads_color.a) == bool :
	quads_color.a=0
	
    if isinstance(triangles_color,Color) :
      if type(triangles_color.a) == bool :
	triangles_color.a=0 	
    
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    
    self.side_length=side_length
    self.lines_color=lines_color
    self.quads_color=quads_color
    self.triangles_color=triangles_color
    self.lines_width=lines_width
    self.triangles,self.quads=generate_polyhedron_26_faces(side_length)
    self.ls=Localview()
    
    self.center=Vertex(0.0,0.0,0.0)    
コード例 #12
0
ファイル: pyglut26hedron.py プロジェクト: PyMine/PyMine
class Poly26Hedron(object) :
  def __init__(self,side_length,display_mode="lined",lines_color=False,quads_color=False,triangles_color=False,lines_width=1,display_ls=False) :
    ''' generate an 26 faces polyhedron object with the given side length settings.
           
        display_mode    = "lined" -> only the lines will be displayed.
        display_mode    = "faced" -> only the faces will be displayed.
        display_mode    = "twice" -> The lines and the faces will be displayed.
        lines_color     = an objet <type 'Color'> representing the lines color.
        quads_color     = an objet <type 'Color'> representing the quads color.
                          an 18-items-list contains <type 'Color'> objects.  
        triangles_color = an objet <type 'Color'> representing the triangles color.
                          an 8-items-list contains <type 'Color'> objects. 
        line_width      = an integer representing the lines width.
    '''
    
    if not isinstance(side_length,int) and not isinstance(side_length,float) :
      raise TypeError(int,float)
    elif side_length < 0.0 :
      raise ValueError("Value of side_length must be greater than 0.0") 
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("lined","faced","twice")
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError(lines_color,Color)
    
    if quads_color :
      if not isinstance(quads_color,Color) and not isinstance(quads_color,list) :
        raise TypeError(quads_color,Color,list)
      elif isinstance(quads_color,list) and len(quads_color) != 18 :
	print "Error quads_color argument:\nYou must give an list from 18 Color objects.\nOne Color object per face."
	quit()
      elif isinstance(quads_color,list) and len(quads_color) == 18 :
        tmp=[]
        quads_color_index=0
        while quads_color_index < 18 :
	  if type(quads_color[quads_color_index].a) == bool :
	    quads_color[quads_color_index].a=0
	  quads_color_index += 1
      
    if triangles_color :
      if not isinstance(triangles_color,Color) and not isinstance(triangles_color,list) :
        raise TypeError(triangles_color,Color,list)
      elif isinstance(triangles_color,list) and len(triangles_color) != 8 :
	print "Error triangles_color argument:\nYou must give an list from 8 Color objects.\nOne Color object per face."
	quit()
      elif isinstance(triangles_color,list) and len(triangles_color) == 8 :
        tmp=[]
        triangles_color_index=0
        while triangles_color_index < 8 :
	  if type(triangles_color[triangles_color_index].a) == bool :
	    triangles_color[triangles_color_index].a=0
	  triangles_color_index += 1    
        
    
    if not isinstance(lines_width,int) :
      raise TypeError(lines_width,int)
    elif lines_width < 1 :
      raise ValueError(lines_width,"Lines width value too little.") 
    
    if isinstance(lines_color,Color) :
      if type(lines_color.a) == bool :
        lines_color.a=0
    
    if isinstance(quads_color,Color) :
      if type(quads_color.a) == bool :
	quads_color.a=0
	
    if isinstance(triangles_color,Color) :
      if type(triangles_color.a) == bool :
	triangles_color.a=0 	
    
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    
    self.side_length=side_length
    self.lines_color=lines_color
    self.quads_color=quads_color
    self.triangles_color=triangles_color
    self.lines_width=lines_width
    self.triangles,self.quads=generate_polyhedron_26_faces(side_length)
    self.ls=Localview()
    
    self.center=Vertex(0.0,0.0,0.0)    
    
  def update_pos(self,matrix) :
    ''' Apply changing contains in the matrix argument. '''
    
    if not isinstance(matrix, Matrix) :
      raise TypeError(matrix,Matrix)
    
    center=[]
    tmp_quads=[]
    for polygon in self.quads :
      tmp_polygon=[]
      for vertex in polygon :
	# Loop over every vertice from the polygon.
	
	res_vertex= matrix * vertex # Multiply the current vertice with the matrix
	
	# Storing the new position from the vertice.
	tmp_polygon.append(res_vertex)  # For the polyhedron polygon container.
	center.append(res_vertex)       # For polyhedron center computing.
	
      tmp_quads.append(tmp_polygon)
    
    
    self.quads=tmp_quads        # Update the quad container with the new postion from every vertice.
    
    tmp_triangles=[]
    for polygon in self.triangles :
      tmp_polygon=[]
      for vertex in polygon :
	# Loop over every vertice from the polygon.
	
	res_vertex= matrix * vertex # Multiply the current vertice with the matrix
	
	# Storing the new position from the vertice.
	tmp_polygon.append(res_vertex)  # For the polyhedron polygon container.
	center.append(res_vertex)       # For polyhedron center computing.
	  
      tmp_triangles.append(tmp_polygon)
    
    self.triangles=tmp_triangles        # Update the triangle container with the new postion from every vertice.
    
    self.center=get_center_from_polyhedron(center)  # Update the polyhedron center. 
    
    self.ls= matrix * self.ls                       # Update the localview.
    
    
    
  def display(self) :
    
    if self.display_mode == "lined" :
      # Configuration of polygons lines displaying.
      glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)
      
      if self.lines_color :
	# Lines color configuration. 
	glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)
    
    
      for polygon in self.quads :
	# Loop over every quad from the polyhedron. 
	# For only lines displaying.
        glBegin(GL_POLYGON)
        for v in polygon :
	   # We loop over the every vertice from the polygon.
	  glVertex3fv(v.get_vertex())
        glEnd()	
      
    
    elif self.display_mode == "faced" :
      # Configuration of polygons faces displaying.
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
      
      if self.quads_color and isinstance(self.quads_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.quads_color.get_ubyte_v())
      
      
	
      quads_color_index=0  # Iterator, case there are more than one color for the faces displaying.		
	
      if self.quads_color and isinstance(self.quads_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.quads_color.get_ubyte_v())
      
      for polygon in self.quads :
	# Loop over every quad from the polyhedron. 
	if self.quads_color and isinstance(self.quads_color,list) : 
	  # Case there are more than one color for the faces displaying.
	  glColor4ubv(self.quads_color[quads_color_index].get_ubyte_v())
	
	glBegin(GL_POLYGON)
	for v in polygon :
	   # We loop over the every vertice from the polygon.
	  glVertex3fv(v.get_vertex())
	glEnd()	
    
	quads_color_index += 1
      
      if self.triangles_color and isinstance(self.triangles_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.triangles_color.get_ubyte_v())
	
      triangles_color_index=0  # Iterator, case there are more than one color for the faces displaying.	
	
      for polygon in self.triangles :
	# Loop over every triangle from the polyhedron. 
	if self.triangles_color and isinstance(self.triangles_color,list) :
	  # Case there are more than one color for the faces displaying.
	  glColor4ubv(self.triangles_color[triangles_color_index].get_ubyte_v())
	  
	glBegin(GL_POLYGON)
	for v in polygon :
	   # We loop over the every vertice from the polygon.
	  glVertex3fv(v.get_vertex())
	glEnd()
	triangles_color_index += 1
      
    elif self.display_mode == "twice" :
      # Configuration of polygons faces displaying.  
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
      
      if self.quads_color and isinstance(self.quads_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.quads_color.get_ubyte_v())
      
      
	
      quads_color_index=0  # Iterator, case there are more than one color for the faces displaying.		
	
      if self.quads_color and isinstance(self.quads_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.quads_color.get_ubyte_v())
      
      for polygon in self.quads :
	# Loop over every quad from the polyhedron. 
	if self.quads_color and isinstance(self.quads_color,list) : 
	  glColor4ubv(self.quads_color[quads_color_index].get_ubyte_v())
	
	glBegin(GL_POLYGON)
	for v in polygon :
	   # We loop over the every vertice from the polygon.
	  glVertex3fv(v.get_vertex())
	glEnd()	
    
	quads_color_index += 1
      
      if self.triangles_color and isinstance(self.triangles_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.triangles_color.get_ubyte_v())
	
      triangles_color_index=0  # Iterator, case there are more than one color for the faces displaying.	
	
      for polygon in self.triangles :
	# Loop over every triangle from the polyhedron. 
	if self.triangles_color and isinstance(self.triangles_color,list) : 
	  # Case there are more than one color for the faces displaying.
	  glColor4ubv(self.triangles_color[triangles_color_index].get_ubyte_v())
	  
	glBegin(GL_POLYGON)
	for v in polygon :
	  # We loop over the every vertice from the polygon.
	  glVertex3fv(v.get_vertex())
	glEnd()
	triangles_color_index += 1
       
      # Configuration of polygons lines displaying. 
      glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)
      
      if self.lines_color :
	# Lines color configuration. 
	glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)
    
    
      for polygon in self.quads :
	# Loop over every quad from the polyhedron. 
	# For only lines displaying.
        glBegin(GL_POLYGON)
        for v in polygon :
	  # We loop over the every vertice from the polygon.
	  glVertex3fv(v.get_vertex())
        glEnd()	
      
    if self.display_ls :
      # Displaying the Localview.
      self.ls.display(self.side_length*2.0/10.0)

  def set_display_mode(self,display_mode) :
    ''' Change the polyhedron display mode. 
        Value of argument display_mode should be:
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces willbe displayed.
    '''
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("lined","faced","twice")
    
    self.display_mode=display_mode
    
  def set_lines_color(self,lines_color) :
    ''' Change the lines color from the polyhedron.
        Value of argument lines_color should be:
        lines_color  = An objet <type 'Color'> representing the lines color.
    '''
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
      
      if isinstance(lines_color.a,bool) :
	lines_color.a=0
       
      self.lines_color=lines_color
    
  def set_quads_color(self,quads_color) :
    ''' Change the faces color(s) from the polyhedron.
        Value of argument quads_color should be:
        quads_color  = An objet <type 'Color'> representing the quads faces color.
                       An 18-items-list from object <type 'Color'>.
                       One item per quad face. 
    '''
    
    if quads_color :
      
      if not isinstance(quads_color,Color) and not isinstance(quads_color,list) :
        raise TypeError(quads_color,Color,list)
      
      elif isinstance(quads_color,list) and len(quads_color) != 18 :
	print "Error quads_color argument:\nYou must give an list from 18 Color objects.\nOne Color object per face."
	quit()
	
      elif isinstance(quads_color,list) and len(quads_color) == 18 :
        tmp=[]
        quads_color_index=0
        while quads_color_index < 18 :
	  if type(quads_color[quads_color_index].a) == bool :
	    quads_color[quads_color_index].a=0
	  quads_color_index += 1
      
      elif isinstance(quads_color,Color) :
	if type(quads_color.a) == bool :
	    quads_color.a=0
      
      else :
        raise TypeError(Color)
      
      self.quads_color=quads_color
    
  def set_triangles_color(self,triangles_color) :
    ''' Change the faces color(s) from the polyhedron.
        Value of argument triangles_color should be:
        triangles_color  = An objet <type 'Color'> representing the triangles faces color.
                           An 8-items-list from object <type 'Color'>.
                           One item per triangles face. 
    '''
    
    if triangles_color :
      
      if not isinstance(triangles_color,Color) and not isinstance(triangles_color,list) :
        raise TypeError(triangles_color,Color,list)
      
      elif isinstance(triangles_color,list) and len(triangles_color) != 8 :
	print "Error triangles_color argument:\nYou must give an list from 8 Color objects.\nOne Color object per face."
	quit()
      
      elif isinstance(triangles_color,list) and len(triangles_color) == 8 :
        tmp=[]
        triangles_color_index=0
        while triangles_color_index < 8 :
	  if type(triangles_color[triangles_color_index].a) == bool :
	    triangles_color[triangles_color_index].a=0
	  triangles_color_index += 1    
      
      elif isinstance(triangles_color,Color) :
	if type(triangles_color.a) == bool :
	    triangles_color.a=0
      
      else :
        raise TypeError(Color)
      
      self.triangles_color=triangles_color  
    
  def set_lines_width(self,lines_width) :
    ''' Change the lines width from the polyhedron.
        Value of argument lines_width should be:
        lines_width  = An integer representing the lines width.
    '''
    if not isinstance(lines_width,int) :
      raise TypeError("Argument lines_width",int)
    elif lines_width < 1 :
      raise ValueError(lines_width,"Lines width value too little.") 
    
    self.lines_width=lines_width
    
  def set_display_ls(self,display_ls) :
    ''' Change the Localview displaying setting.
        Value of argument display_ls should be an boolean value:
        display_ls   = Define if the localview should be display.
    '''    
        
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    else :
      raise TypeError("Argument display_ls",bool)
    
  def set_side_length(self,side_length) :
    if not isinstance(side_length,int) and not isinstance(side_length,float) :
      raise TypeError("Argument side_length",int,float)
    elif side_length < 0.0 :
      raise ValueError("Value of argument side_length must be greater than 0.0") 
    
    self.side_length=side_length
    self.triangles,self.quads=generate_polyhedron_26_faces(side_length)
    self.ls=Localview()
  
  def __doc__(self) :
    ''' Print documentation '''
    
    print '''
コード例 #13
0
    def __init__(self,
                 side_length,
                 display_mode="lined",
                 lines_color=False,
                 faces_color=False,
                 lines_width=1,
                 display_ls=False):
        ''' Generate an Icosahedron object with the given side length settings.
        
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces will be displayed.
        lines_color  = An objet <type 'Color'> representing the lines color.
        faces_color  = An objet <type 'Color'> representing the faces color.
                       An 8-items-list from object <type 'Color'>.
                       One item per icosahedron face. 
        lines_width  = An integer representing the lines width.
        display_ls   = Define if the localview should be display.
    '''

        if not isinstance(side_length, int) and not isinstance(
                side_length, float):
            raise TypeError("Argument side_length", int, float)
        elif side_length <= 0.0:
            raise ValueError(
                "Value of argument side_length must be greater than 0.0")

        if display_mode == "lined" or display_mode == "faced" or display_mode == "twice":
            self.display_mode = display_mode
        else:
            raise ValueError("Argument display_mode", "lined", "faced",
                             "twice")

        if lines_color:
            if not isinstance(lines_color, Color):
                raise TypeError("Argument lines_color", Color)

        if faces_color:
            if not isinstance(faces_color, Color) and not isinstance(
                    faces_color, list):
                raise TypeError(faces_color, Color, list)
            elif isinstance(faces_color, list) and len(faces_color) != 20:
                print "Error faces_color argument:\nYou must give an list from 20 Color objects.\nOne Color object per face."
                quit()
            elif isinstance(faces_color, list) and len(faces_color) == 20:
                tmp = []
                faces_color_index = 0
                while faces_color_index < 20:
                    if type(faces_color[faces_color_index].a) == bool:
                        faces_color[faces_color_index].a = 0
                    faces_color_index += 1

        if not isinstance(lines_width, int):
            raise TypeError("Argument lines_width", int)
        elif lines_width < 1:
            raise ValueError(lines_width, "Lines width value too little.")

        if isinstance(lines_color, Color):
            if type(lines_color.a) == bool:
                lines_color.a = 0

        if isinstance(faces_color, Color):
            if type(faces_color.a) == bool:
                faces_color.a = 0

        if isinstance(display_ls, bool):
            self.display_ls = display_ls

        self.side_length = side_length
        self.lines_color = lines_color
        self.faces_color = faces_color
        self.lines_width = lines_width
        self.polyhedron = generate_icosahedron(side_length)[1]
        self.ls = Localview()

        self.center = Vertex(0.0, 0.0, 0.0)
コード例 #14
0
class Trigon_Sphere(object) :
  def __init__(self,radius,basis,display_mode="lined",lines_color=False,faces_color=False,lines_width=1,display_ls=False) :
    ''' generate an trigon sphere object with the given radius and polygone basis.
    
        basis        = Integer taken as basis for the sphere generating.  
        radius       = Radius of the sphere. 
        display_mode = "lined" -> only the lines will be displayed.
        display_mode = "faced" -> only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces will be displayed.
        lines_color  = an objet <type 'Color'> representing the lines color.
        faces_color  = an objet <type 'Color'> representing the faces color.
        line_width   = an integer representing the lines width.
    '''
    
    if not isinstance(radius,int) and not isinstance(radius,float) :
      raise TypeError(int,float)
    elif radius <= 0.0 :
      raise ValueError("Value of radius must be greater than 0.0") 
    
    if not isinstance(basis,int) :
      raise TypeError(int)

    if basis < 6 or basis % 4 :
      print "the basis for the sphere must be greater as 5 and basis % 4 == 0 "
      quit()
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("Argument display_mode","lined","faced","twice")
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
    
    if faces_color :
      if not isinstance(faces_color,Color) : 
        raise TypeError("Argument faces_color",Color)
      
      
         	
    
    if not isinstance(lines_width,int) :
      raise TypeError(lines_width,int)
    elif lines_width < 1 :
      raise ValueError("Lines width value too little.") 
    
    if isinstance(lines_color,Color) :
      if type(lines_color.a) == bool :
        lines_color.a=0
    
    if not type(faces_color) == bool :
      if type(faces_color.a) == bool :
	faces_color.a=0
    
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    
    self.lines_color=lines_color
    self.faces_color=faces_color
    self.lines_width=lines_width
    self.basis=basis
    self.radius=radius
    self.trigons=generate_trigon_sphere(basis,radius)[0]
    self.ls=Localview()
    
    self.center=Vertex(0.0,0.0,0.0)    
    
  def update_pos(self,matrix) :
    ''' Apply changing contains in the matrix argument. '''
    
    if not isinstance(matrix, Matrix) :
      raise TypeError(matrix,Matrix)
    
    center=[]
    tmp_polyhedron=[]
    for polygon in self.trigons :
      # Loop over every polygon from the sphere. 
      tmp_polygon=[]
      
      for vertex in polygon :
	# Loop over every vertice from the polygon.
	
	res_vertex= matrix * vertex # Multiply the current vertice with the matrix
 	
 	# Storing the new position from the vertice.
 	tmp_polygon.append(res_vertex)  # For the sphere polygon container.
	center.append(res_vertex)       # For sphere center computing.
      
      tmp_polyhedron.append(tmp_polygon)
    
    self.trigons=tmp_polyhedron                       # Update the polygon container with the new postion from every vertice.
    
    self.center=get_center_from_polyhedron(center)    # Update the sphere center.  
    
    self.ls= matrix * self.ls                         # Update the localview.
    
    
    
  def display(self) :
    if self.display_mode == "lined" :
      
      if self.lines_color :	
        # Lines color configuration. 
        glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)    # Setting the line width given as argument.
     
      i=-1
      boolean=False

      while i < len(self.trigons)-1 :
	# Loop to display the triangles from our sphere.
	# Throught iterating over the polygons on the XZ surface.
	ii=-1
	while ii < len(self.trigons[i])-1 :
          glBegin(GL_LINE_LOOP)
	  if boolean :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii].get_vertex())
	  else :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii+1].get_vertex())
          glEnd()
	  ii += 1

	if boolean :
	  boolean=False
	else :
	  boolean=True

	i += 1
	  
    elif self.display_mode == "faced" :
      
      if self.faces_color :	
        # Faces color configuration. 
        glColor4ubv(self.faces_color.get_ubyte_v())
      
      i=-1
      boolean=False

      while i < len(self.trigons)-1 :
	# Loop to display the triangles from our sphere.
	# Throught iterating over the polygons on the XZ surface.
	ii=-1
	while ii < len(self.trigons[i])-1 :
          glBegin(GL_TRIANGLES)
	  if boolean :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii].get_vertex())
	  else :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii+1].get_vertex())
          glEnd()
	  ii += 1

	if boolean :
	  boolean=False
	else :
	  boolean=True

	i += 1
		  
      
    if self.display_mode == "twice" :  
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL) 
      
      if self.faces_color :
         # Faces color configuration. 	
        glColor4ubv(self.faces_color.get_ubyte_v())
      
      
      i=-1
      boolean=False

      while i < len(self.trigons)-1 :
	# Loop to display the triangles from our sphere.
	# Throught iterating over the polygons on the XZ surface.
	ii=-1
	while ii < len(self.trigons[i])-1 :
          glBegin(GL_TRIANGLES)
	  if boolean :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii].get_vertex())
	  else :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii+1].get_vertex())
          glEnd()
	  ii += 1

	if boolean :
	  boolean=False
	else :
	  boolean=True

	i += 1
	
      if self.lines_color :
         # Lines color configuration. 	
        glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)    # Setting the line width given as argument.
     
      i=-1
      boolean=False

      while i < len(self.trigons)-1 :
	# Loop to display the triangles from our sphere.
	# Throught iterating over the polygons on the XZ surface.
	ii=-1
	while ii < len(self.trigons[i])-1 :
          glBegin(GL_LINE_LOOP)
	  if boolean :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii].get_vertex())
	  else :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii+1].get_vertex())
          glEnd()
	  ii += 1

	if boolean :
	  boolean=False
	else :
	  boolean=True

	i += 1

    if self.display_ls :
      # Displaying the Localview.
      self.ls.display(self.radius*2.0/10.0)

  def set_display_mode(self,display_mode) :
    ''' Change the sphere display mode. 
        Value of argument display_mode should be:
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces willbe displayed.
    '''
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("lined","faced","twice")
    
    self.display_mode=display_mode
    
  def set_lines_color(self,lines_color) :
    ''' Change the lines color from the sphere.
        Value of argument lines_color should be:
        lines_color  = An objet <type 'Color'> representing the lines color.
    '''
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
      
      if isinstance(lines_color.a,bool) :
	lines_color.a=0
	
    self.lines_color=lines_color
    
  def set_faces_color(self,faces_color) :
    ''' Change the faces color(s) from the sphere.
        Value of argument faces_color should be:
        faces_color  = An objet <type 'Color'> representing the faces color.
    '''
    
    if isinstance(faces_color,Color) :
      if type(faces_color.a) == bool :
	faces_color.a=0	  
    
    else :
      raise TypeError(Color)
    
    self.faces_color=faces_color
    
  def set_lines_width(self,lines_width) :
    ''' Change the lines width from the sphere.
        Value of argument lines_width should be:
        lines_width  = An integer representing the lines width.
    '''
    if not isinstance(lines_width,int) :
      raise TypeError("Argument lines_width",int)
    elif lines_width < 1 :
      raise ValueError(lines_width,"Lines width value too little.") 
    
    self.lines_width=lines_width
    
  def set_display_ls(self,display_ls) :
    ''' Change the Localview displaying setting.
        Value of argument display_ls should be an boolean value:
        display_ls   = Define if the localview should be display.
    '''    
        
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    else :
      raise TypeError("Argument display_ls",bool)
    
  def set_basis(self,basis) :
    ''' Change the trigon sphere basis. '''
    
    if not isinstance(basis,int) :
      raise TypeError(int)

    if basis < 6 or basis % 2 :
      print "the basis for the sphere must be greater as 5 and basis % 2 == 0 "
      quit()
    
    self.basis=basis
    self.trigons=generate_trigon_sphere(basis,self.radius)[0]
    self.ls=Localview()
    
  def set_radius(self,radius) :
    ''' Change the trigon sphere radius. '''
    
    if not isinstance(radius,int) and not isinstance(radius,float) :
      raise TypeError(int,float)
    elif radius < 0.0 :
      raise ValueError("Value of radius must be greater than 0.0") 
    
    self.radius=radius
    self.trigons=generate_trigon_sphere(self.basis,radius)[0]
    self.ls=Localview()
  
  def __doc__(self) :
    ''' Print documentation '''
    
    print '''
    Generate an trigon sphere object with position updating, 
    display and settings setters methods.
    
    An "trigon sphere" is an sphere which every faces is an trigon.
    
    The display mode set how the trigon sphere will be display 
    and can take as values:
    "lined" -> Only the edges will be display.
    "faces" -> Only the faces willbbe display.
    "twice" -> The edges and the faces will be display.
    
    The lines color must be an object from <type 'Color'> available throught
    this module as datatype dealing with colors as unsigned bytes 
    or floating-points values.
    
    The faces color can be:
    -> An object from <type 'Color'> in which case the trigon sphere 
       will be filled with this color.
    
    The lines width must be an integer representing the number of pixels from 
    the edges width.
    
    The display_ls argument must be an boolean value point to if the sphere 
    own Localview will be displayed. 
    The datatype Localview is available throught this module. 
    sea his documentation to know more about.
    
    '''    
コード例 #15
0
class Poly26Hedron(object):
    def __init__(self,
                 side_length,
                 display_mode="lined",
                 lines_color=False,
                 quads_color=False,
                 triangles_color=False,
                 lines_width=1,
                 display_ls=False):
        ''' generate an 26 faces polyhedron object with the given side length settings.
           
        display_mode    = "lined" -> only the lines will be displayed.
        display_mode    = "faced" -> only the faces will be displayed.
        display_mode    = "twice" -> The lines and the faces will be displayed.
        lines_color     = an objet <type 'Color'> representing the lines color.
        quads_color     = an objet <type 'Color'> representing the quads color.
                          an 18-items-list contains <type 'Color'> objects.  
        triangles_color = an objet <type 'Color'> representing the triangles color.
                          an 8-items-list contains <type 'Color'> objects. 
        line_width      = an integer representing the lines width.
    '''

        if not isinstance(side_length, int) and not isinstance(
                side_length, float):
            raise TypeError(int, float)
        elif side_length < 0.0:
            raise ValueError("Value of side_length must be greater than 0.0")

        if display_mode == "lined" or display_mode == "faced" or display_mode == "twice":
            self.display_mode = display_mode
        else:
            raise ValueError("lined", "faced", "twice")

        if lines_color:
            if not isinstance(lines_color, Color):
                raise TypeError(lines_color, Color)

        if quads_color:
            if not isinstance(quads_color, Color) and not isinstance(
                    quads_color, list):
                raise TypeError(quads_color, Color, list)
            elif isinstance(quads_color, list) and len(quads_color) != 18:
                print "Error quads_color argument:\nYou must give an list from 18 Color objects.\nOne Color object per face."
                quit()
            elif isinstance(quads_color, list) and len(quads_color) == 18:
                tmp = []
                quads_color_index = 0
                while quads_color_index < 18:
                    if type(quads_color[quads_color_index].a) == bool:
                        quads_color[quads_color_index].a = 0
                    quads_color_index += 1

        if triangles_color:
            if not isinstance(triangles_color, Color) and not isinstance(
                    triangles_color, list):
                raise TypeError(triangles_color, Color, list)
            elif isinstance(triangles_color,
                            list) and len(triangles_color) != 8:
                print "Error triangles_color argument:\nYou must give an list from 8 Color objects.\nOne Color object per face."
                quit()
            elif isinstance(triangles_color,
                            list) and len(triangles_color) == 8:
                tmp = []
                triangles_color_index = 0
                while triangles_color_index < 8:
                    if type(triangles_color[triangles_color_index].a) == bool:
                        triangles_color[triangles_color_index].a = 0
                    triangles_color_index += 1

        if not isinstance(lines_width, int):
            raise TypeError(lines_width, int)
        elif lines_width < 1:
            raise ValueError(lines_width, "Lines width value too little.")

        if isinstance(lines_color, Color):
            if type(lines_color.a) == bool:
                lines_color.a = 0

        if isinstance(quads_color, Color):
            if type(quads_color.a) == bool:
                quads_color.a = 0

        if isinstance(triangles_color, Color):
            if type(triangles_color.a) == bool:
                triangles_color.a = 0

        if isinstance(display_ls, bool):
            self.display_ls = display_ls

        self.side_length = side_length
        self.lines_color = lines_color
        self.quads_color = quads_color
        self.triangles_color = triangles_color
        self.lines_width = lines_width
        self.triangles, self.quads = generate_polyhedron_26_faces(side_length)
        self.ls = Localview()

        self.center = Vertex(0.0, 0.0, 0.0)

    def update_pos(self, matrix):
        ''' Apply changing contains in the matrix argument. '''

        if not isinstance(matrix, Matrix):
            raise TypeError(matrix, Matrix)

        center = []
        tmp_quads = []
        for polygon in self.quads:
            tmp_polygon = []
            for vertex in polygon:
                # Loop over every vertice from the polygon.

                res_vertex = matrix * vertex  # Multiply the current vertice with the matrix

                # Storing the new position from the vertice.
                tmp_polygon.append(
                    res_vertex)  # For the polyhedron polygon container.
                center.append(res_vertex)  # For polyhedron center computing.

            tmp_quads.append(tmp_polygon)

        self.quads = tmp_quads  # Update the quad container with the new postion from every vertice.

        tmp_triangles = []
        for polygon in self.triangles:
            tmp_polygon = []
            for vertex in polygon:
                # Loop over every vertice from the polygon.

                res_vertex = matrix * vertex  # Multiply the current vertice with the matrix

                # Storing the new position from the vertice.
                tmp_polygon.append(
                    res_vertex)  # For the polyhedron polygon container.
                center.append(res_vertex)  # For polyhedron center computing.

            tmp_triangles.append(tmp_polygon)

        self.triangles = tmp_triangles  # Update the triangle container with the new postion from every vertice.

        self.center = get_center_from_polyhedron(
            center)  # Update the polyhedron center.

        self.ls = matrix * self.ls  # Update the localview.

    def display(self):

        if self.display_mode == "lined":
            # Configuration of polygons lines displaying.
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

            if self.lines_color:
                # Lines color configuration.
                glColor4ubv(self.lines_color.get_ubyte_v())

            glLineWidth(self.lines_width)

            for polygon in self.quads:
                # Loop over every quad from the polyhedron.
                # For only lines displaying.
                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()

        elif self.display_mode == "faced":
            # Configuration of polygons faces displaying.
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

            if self.quads_color and isinstance(self.quads_color, Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.quads_color.get_ubyte_v())

            quads_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

            if self.quads_color and isinstance(self.quads_color, Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.quads_color.get_ubyte_v())

            for polygon in self.quads:
                # Loop over every quad from the polyhedron.
                if self.quads_color and isinstance(self.quads_color, list):
                    # Case there are more than one color for the faces displaying.
                    glColor4ubv(
                        self.quads_color[quads_color_index].get_ubyte_v())

                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()

                quads_color_index += 1

            if self.triangles_color and isinstance(self.triangles_color,
                                                   Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.triangles_color.get_ubyte_v())

            triangles_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

            for polygon in self.triangles:
                # Loop over every triangle from the polyhedron.
                if self.triangles_color and isinstance(self.triangles_color,
                                                       list):
                    # Case there are more than one color for the faces displaying.
                    glColor4ubv(self.triangles_color[triangles_color_index].
                                get_ubyte_v())

                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()
                triangles_color_index += 1

        elif self.display_mode == "twice":
            # Configuration of polygons faces displaying.
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

            if self.quads_color and isinstance(self.quads_color, Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.quads_color.get_ubyte_v())

            quads_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

            if self.quads_color and isinstance(self.quads_color, Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.quads_color.get_ubyte_v())

            for polygon in self.quads:
                # Loop over every quad from the polyhedron.
                if self.quads_color and isinstance(self.quads_color, list):
                    glColor4ubv(
                        self.quads_color[quads_color_index].get_ubyte_v())

                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()

                quads_color_index += 1

            if self.triangles_color and isinstance(self.triangles_color,
                                                   Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.triangles_color.get_ubyte_v())

            triangles_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

            for polygon in self.triangles:
                # Loop over every triangle from the polyhedron.
                if self.triangles_color and isinstance(self.triangles_color,
                                                       list):
                    # Case there are more than one color for the faces displaying.
                    glColor4ubv(self.triangles_color[triangles_color_index].
                                get_ubyte_v())

                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()
                triangles_color_index += 1

            # Configuration of polygons lines displaying.
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

            if self.lines_color:
                # Lines color configuration.
                glColor4ubv(self.lines_color.get_ubyte_v())

            glLineWidth(self.lines_width)

            for polygon in self.quads:
                # Loop over every quad from the polyhedron.
                # For only lines displaying.
                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()

        if self.display_ls:
            # Displaying the Localview.
            self.ls.display(self.side_length * 2.0 / 10.0)

    def set_display_mode(self, display_mode):
        ''' Change the polyhedron display mode. 
        Value of argument display_mode should be:
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces willbe displayed.
    '''

        if display_mode == "lined" or display_mode == "faced" or display_mode == "twice":
            self.display_mode = display_mode
        else:
            raise ValueError("lined", "faced", "twice")

        self.display_mode = display_mode

    def set_lines_color(self, lines_color):
        ''' Change the lines color from the polyhedron.
        Value of argument lines_color should be:
        lines_color  = An objet <type 'Color'> representing the lines color.
    '''

        if lines_color:
            if not isinstance(lines_color, Color):
                raise TypeError("Argument lines_color", Color)

            if isinstance(lines_color.a, bool):
                lines_color.a = 0

            self.lines_color = lines_color

    def set_quads_color(self, quads_color):
        ''' Change the faces color(s) from the polyhedron.
        Value of argument quads_color should be:
        quads_color  = An objet <type 'Color'> representing the quads faces color.
                       An 18-items-list from object <type 'Color'>.
                       One item per quad face. 
    '''

        if quads_color:

            if not isinstance(quads_color, Color) and not isinstance(
                    quads_color, list):
                raise TypeError(quads_color, Color, list)

            elif isinstance(quads_color, list) and len(quads_color) != 18:
                print "Error quads_color argument:\nYou must give an list from 18 Color objects.\nOne Color object per face."
                quit()

            elif isinstance(quads_color, list) and len(quads_color) == 18:
                tmp = []
                quads_color_index = 0
                while quads_color_index < 18:
                    if type(quads_color[quads_color_index].a) == bool:
                        quads_color[quads_color_index].a = 0
                    quads_color_index += 1

            elif isinstance(quads_color, Color):
                if type(quads_color.a) == bool:
                    quads_color.a = 0

            else:
                raise TypeError(Color)

            self.quads_color = quads_color

    def set_triangles_color(self, triangles_color):
        ''' Change the faces color(s) from the polyhedron.
        Value of argument triangles_color should be:
        triangles_color  = An objet <type 'Color'> representing the triangles faces color.
                           An 8-items-list from object <type 'Color'>.
                           One item per triangles face. 
    '''

        if triangles_color:

            if not isinstance(triangles_color, Color) and not isinstance(
                    triangles_color, list):
                raise TypeError(triangles_color, Color, list)

            elif isinstance(triangles_color,
                            list) and len(triangles_color) != 8:
                print "Error triangles_color argument:\nYou must give an list from 8 Color objects.\nOne Color object per face."
                quit()

            elif isinstance(triangles_color,
                            list) and len(triangles_color) == 8:
                tmp = []
                triangles_color_index = 0
                while triangles_color_index < 8:
                    if type(triangles_color[triangles_color_index].a) == bool:
                        triangles_color[triangles_color_index].a = 0
                    triangles_color_index += 1

            elif isinstance(triangles_color, Color):
                if type(triangles_color.a) == bool:
                    triangles_color.a = 0

            else:
                raise TypeError(Color)

            self.triangles_color = triangles_color

    def set_lines_width(self, lines_width):
        ''' Change the lines width from the polyhedron.
        Value of argument lines_width should be:
        lines_width  = An integer representing the lines width.
    '''
        if not isinstance(lines_width, int):
            raise TypeError("Argument lines_width", int)
        elif lines_width < 1:
            raise ValueError(lines_width, "Lines width value too little.")

        self.lines_width = lines_width

    def set_display_ls(self, display_ls):
        ''' Change the Localview displaying setting.
        Value of argument display_ls should be an boolean value:
        display_ls   = Define if the localview should be display.
    '''

        if isinstance(display_ls, bool):
            self.display_ls = display_ls
        else:
            raise TypeError("Argument display_ls", bool)

    def set_side_length(self, side_length):
        if not isinstance(side_length, int) and not isinstance(
                side_length, float):
            raise TypeError("Argument side_length", int, float)
        elif side_length < 0.0:
            raise ValueError(
                "Value of argument side_length must be greater than 0.0")

        self.side_length = side_length
        self.triangles, self.quads = generate_polyhedron_26_faces(side_length)
        self.ls = Localview()

    def __doc__(self):
        ''' Print documentation '''

        print '''
コード例 #16
0
ファイル: pyglutIcosahedron.py プロジェクト: PyMine/PyMine
class Icosahedron(object) :
  def __init__(self,side_length,display_mode="lined",lines_color=False,faces_color=False,lines_width=1,display_ls=False) :
    ''' Generate an Icosahedron object with the given side length settings.
        
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces will be displayed.
        lines_color  = An objet <type 'Color'> representing the lines color.
        faces_color  = An objet <type 'Color'> representing the faces color.
                       An 8-items-list from object <type 'Color'>.
                       One item per icosahedron face. 
        lines_width  = An integer representing the lines width.
        display_ls   = Define if the localview should be display.
    '''
    
    if not isinstance(side_length,int) and not isinstance(side_length,float) :
      raise TypeError("Argument side_length",int,float)
    elif side_length <= 0.0 :
      raise ValueError("Value of argument side_length must be greater than 0.0") 
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("Argument display_mode","lined","faced","twice")
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
    
    if faces_color :
      if not isinstance(faces_color,Color) and not isinstance(faces_color,list) :
        raise TypeError(faces_color,Color,list)
      elif isinstance(faces_color,list) and len(faces_color) != 20 :
	print "Error faces_color argument:\nYou must give an list from 20 Color objects.\nOne Color object per face."
	quit()
      elif isinstance(faces_color,list) and len(faces_color) == 20 :
        tmp=[]
        faces_color_index=0
        while faces_color_index < 20 :
	  if type(faces_color[faces_color_index].a) == bool :
	    faces_color[faces_color_index].a=0
	  faces_color_index += 1
      
         	
    
    if not isinstance(lines_width,int) :
      raise TypeError("Argument lines_width",int)
    elif lines_width < 1 :
      raise ValueError(lines_width,"Lines width value too little.") 
    
    if isinstance(lines_color,Color) :
      if type(lines_color.a) == bool :
        lines_color.a=0
    
    if isinstance(faces_color,Color) :
      if type(faces_color.a) == bool :
	faces_color.a=0
    
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    
    self.side_length=side_length
    self.lines_color=lines_color
    self.faces_color=faces_color
    self.lines_width=lines_width
    self.polyhedron=generate_icosahedron(side_length)[1]
    self.ls=Localview()
    
    self.center=Vertex(0.0,0.0,0.0)    
    
  def update_pos(self,matrix) :
    ''' Apply changing contains in the matrix argument. '''
    
    if not isinstance(matrix, Matrix) :
      raise TypeError(matrix,Matrix)
    
    center=[]
    tmp_polyhedron=[]
    
    for polygon in self.polyhedron :
      # Loop over every polygon from the polyhedron. 
      tmp_polygon=[]
      
      for vertex in polygon :
	# Loop over every vertice from the polygon.
	
	res_vertex= matrix * vertex # Multiply the current vertice with the matrix
 	
 	# Storing the new position from the vertice.
 	tmp_polygon.append(res_vertex)  # For the polyhedron polygon container.
	center.append(res_vertex)       # For polyhedron center computing.
      
      tmp_polyhedron.append(tmp_polygon)
    
    self.polyhedron=tmp_polyhedron                  # Update the polygon container with the new postion from every vertice.
    
    self.center=get_center_from_polyhedron(center)  # Update the polyhedron center.  
    
    self.ls= matrix * self.ls                       # Update the localview.
    
    
    
  def display(self) :
    ''' Icosahedron displaying method towards the settings. '''
    
    
    faces_color_index=0  # Iterator, case there are more than one color for the faces displaying.
    
    if self.display_mode == "lined" or self.display_mode == "faced" :
      
      if self.display_mode == "lined" and self.lines_color :
	  # Configuration of polygons lines displaying.
	  glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)
	  
	  if self.lines_color :
	    # Lines color configuration. 
	    glColor4ubv(self.lines_color.get_ubyte_v())

	  glLineWidth(self.lines_width)
	
      elif self.display_mode == "faced" :
	# Configuration of polygons faces displaying.
	glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
	
	if self.faces_color and isinstance(self.faces_color,Color) :
	  # Faces colorizing configuration.
	  glColor4ubv(self.faces_color.get_ubyte_v())
      
      for polygon in self.polyhedron :
	# We loop over the polyhedron polygons container.
	
	if self.faces_color and isinstance(self.faces_color,list) and self.display_mode == "faced" : 
	  # Faces multi-colorizing configuration.
	  glColor4ubv(self.faces_color[faces_color_index].get_ubyte_v())
	
	# Displaying one polygon:
	glBegin(GL_POLYGON)
	for v in polygon :
	  # We loop over the every vertice from the polygon.
	  glVertex3fv(v.get_vertex())
	glEnd()	
	
	faces_color_index += 1 
      
    elif self.display_mode == "twice" :
      
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
      
      if self.faces_color and isinstance(self.faces_color,Color) :
	glColor4ubv(self.faces_color.get_ubyte_v())
	
      for faces in self.polyhedron :
	# We loop over the polyhedron polygons container.
	
	if self.faces_color and isinstance(self.faces_color,list) :
	  # Faces multi-colorizing configuration.
	  glColor4ubv(self.faces_color[faces_color_index].get_ubyte_v())
	  
	# Displaying one polygon face:  
	glBegin(GL_POLYGON)
        for v in faces :
	   # We loop over the every vertice from the face.
	  glVertex3fv(v.get_vertex())
        glEnd()
        
        faces_color_index += 1  
        
      glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)
      
      if self.lines_color :
	# Lines color configuration. 
	glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)
      
      # Displaying one polygon face edges: 
      for faces in self.polyhedron :
	
	glBegin(GL_POLYGON)
        for v in faces :
	  # We loop over the every vertice from the face.
	  glVertex3fv(v.get_vertex())
        glEnd() 
      
    if self.display_ls :
      # Displaying the Localview.
      self.ls.display(self.side_length*2.0/10.0)
   
  def set_display_mode(self,display_mode) :
    ''' Change the polyhedron display mode. 
        Value of argument display_mode should be:
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces willbe displayed.
    '''
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("lined","faced","twice")
    
    self.display_mode=display_mode
    
  def set_lines_color(self,lines_color) :
    ''' Change the lines color from the polyhedron.
        Value of argument lines_color should be:
        lines_color  = An objet <type 'Color'> representing the lines color.
    '''
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
      
      if isinstance(lines_color.a,bool) :
	lines_color.a=0
	
    self.lines_color=lines_color
    
  def set_faces_color(self,faces_color) :
    ''' Change the faces color(s) from the polyhedron.
        Value of argument faces_color should be:
        faces_color  = An objet <type 'Color'> representing the faces color.
                       An 20-items-list from object <type 'Color'>.
                       One item per icosahedron face. 
    '''
    
    if not isinstance(faces_color,Color) and not isinstance(faces_color,list) :
      raise TypeError(faces_color,Color,list)
    
    elif isinstance(faces_color,list) and len(faces_color) != 20 :
      print "Error faces_color argument:\nYou must give an list from 20 Color objects.\nOne Color object per face."
      quit()
    
    elif isinstance(faces_color,list) and len(faces_color) == 20 :
      tmp=[]
      faces_color_index=0
      while faces_color_index < 20 :
	if isinstance(faces_color[faces_color_index].a,bool) :
	  faces_color[faces_color_index].a=0
	faces_color_index += 1
    
    elif isinstance(faces_color,Color) :
      if type(faces_color.a) == bool :
	faces_color.a=0	  
    
    else :
      raise TypeError(Color)
    
    self.faces_color=faces_color
    
  def set_lines_width(self,lines_width) :
    ''' Change the lines width from the polyhedron.
        Value of argument lines_width should be:
        lines_width  = An integer representing the lines width.
    '''
    if not isinstance(lines_width,int) :
      raise TypeError("Argument lines_width",int)
    elif lines_width < 1 :
      raise ValueError(lines_width,"Lines width value too little.") 
    
    self.lines_width=lines_width
    
  def set_display_ls(self,display_ls) :
    ''' Change the Localview displaying setting.
        Value of argument display_ls should be an boolean value:
        display_ls   = Define if the localview should be display.
    '''    
        
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    else :
      raise TypeError("Argument display_ls",bool)
    
  def set_side_length(self,side_length) :
    if not isinstance(side_length,int) and not isinstance(side_length,float) :
      raise TypeError("Argument side_length",int,float)
    elif side_length < 0.0 :
      raise ValueError("Value of argument side_length must be greater than 0.0") 
    
    self.side_length=side_length
    self.polyhedron=generate_icosahedron(side_length)[1]
    self.ls=Localview()
  
  def __doc__(self) :
    ''' Print documentation '''
    
    print '''
コード例 #17
0
ファイル: pyglutToros.py プロジェクト: mrcyberfighter/pyglut
class Toros(object) :
  def __init__(self,base_polygon,base_radius,toros_radius,display_mode="lined",lines_color=False,faces_color=False,lines_width=1,display_ls=False) :
    ''' Generate an toros object with the given radius and basis polygone settings.
    
        base_polygon = the toros basis polygon.
        base_radius  = the toros basis polygon radius.
        toros_radius = the toros radius (without the base polygon radius). 
        display_mode = "lined" -> only the lines will be displayed.
        display_mode = "faced" -> only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces will be displayed.
        lines_color  = an objet <type 'Color'> representing the lines color.
        faces_color  = an objet <type 'Color'> representing the faces color.
        line_width   = an integer representing the lines width.
    '''
    
    if not isinstance(base_polygon,int) :
      raise TypeError("base_polygon argument",int)

    if base_polygon <= 2 :
      print "the base polygon must be greater than 2 "
      quit()
    
    
    if not isinstance(base_radius,int) and not isinstance(base_radius,float) :
      raise TypeError("base_radius argument",int,float)
    elif base_radius <= 0.0 :
      raise ValueError("Value of base_radius must be greater than 0.0") 
    
    
    if not isinstance(toros_radius,int) and not isinstance(toros_radius,float) :
      raise TypeError("toros_radius argument",int,float)
    elif toros_radius <= 0.0 :
      raise ValueError("Value of toros_radius must be greater than 0.0") 
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("Argument display_mode","lined","faced","twice")
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
    
    if faces_color :
      if not isinstance(faces_color,Color) : 
        raise TypeError("Argument faces_color",Color)
      
      
         	
    
    if not isinstance(lines_width,int) :
      raise TypeError(lines_width,int)
    elif lines_width < 1 :
      raise ValueError("Lines width value too little.") 
    
    if isinstance(lines_color,Color) :
      if type(lines_color.a) == bool :
        lines_color.a=0
    
    if isinstance(faces_color,Color) :
      if type(faces_color.a) == bool :
	faces_color.a=0
    
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
      
    self.base_polygon=base_polygon
    self.base_radius=base_radius
    self.toros_radius=toros_radius
    self.lines_color=lines_color
    self.faces_color=faces_color
    self.lines_width=lines_width
    self.toros=generate_toros(base_polygon,base_radius,toros_radius)
    self.ls=Localview()
    self.center=Vertex(0.0,0.0,0.0)
    
  def update_pos(self,matrix) :
    ''' Apply changing contains in the matrix argument. '''
    
    if not isinstance(matrix, Matrix) :
      raise TypeError(matrix,Matrix)
    
    center=[]
    tmp_toros=[]
    
    for polygon in self.toros :
      # Loop over every polygon from the toros. 
      tmp_polygon=[]
      
      for vertex in polygon :
	# Loop over every vertice from the polygon.
	
	res_vertex= matrix * vertex # Multiply the current vertice with the matrix
 	
 	# Storing the new position from the vertice.
 	tmp_polygon.append(res_vertex)  # For the toros polygon container.
	center.append(res_vertex)       # For toros center computing.
      
      tmp_toros.append(tmp_polygon)
    
    self.toros=tmp_toros                  # Update the polygon container with the new postion from every vertice.
    
    self.center=get_center_from_polyhedron(center)  # Update the toros center.  
    
    self.ls= matrix * self.ls                       # Update the localview.  
    
  def display(self) :
    if self.display_mode == "lined" :
      if self.lines_color :
        # Lines color configuration. 	
        glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)    # Setting the line width given as argument.
      
      i=0
      while i < len(self.toros) :
	glBegin(GL_LINE_LOOP)
	for v in self.toros[i] :
	  glVertex3fv(v.get_vertex())
	glEnd()
	i += 1
      
      i=-1
      while i < len(self.toros)-1 :
	ii=0
	while ii < len(self.toros[i]) :
	  glBegin(GL_LINES)
	  glVertex3fv(self.toros[i][ii].get_vertex())
	  glVertex3fv(self.toros[i+1][ii].get_vertex())
	  glEnd()
	  ii += 1
	i += 1	
	
    elif self.display_mode == "faced" :
      
      if self.faces_color :
	# Faces color configuration. 
        glColor4ubv(self.faces_color.get_ubyte_v())
	
      i=-1
      while i < len(self.toros)-1 :
	ii=-1
	while ii < len(self.toros[i])-1 :
	  glBegin(GL_QUADS)
	  glVertex3fv(self.toros[i][ii].get_vertex())
	  glVertex3fv(self.toros[i+1][ii].get_vertex())
	  glVertex3fv(self.toros[i+1][ii+1].get_vertex())
	  glVertex3fv(self.toros[i][ii+1].get_vertex())
	  glEnd()
	  ii += 1
	i += 1	
		    
      
    elif self.display_mode == "twice" :  
      
      if self.faces_color :
        glColor4ubv(self.faces_color.get_ubyte_v())
	
      i=-1
      while i < len(self.toros)-1 :
	ii=-1
	while ii < len(self.toros[i])-1 :
	  glBegin(GL_QUADS)
	  glVertex3fv(self.toros[i][ii].get_vertex())
	  glVertex3fv(self.toros[i+1][ii].get_vertex())
	  glVertex3fv(self.toros[i+1][ii+1].get_vertex())
	  glVertex3fv(self.toros[i][ii+1].get_vertex())
	  glEnd()
	  ii += 1
	i += 1	
	
      if self.lines_color :
        # Lines color configuration. 	
        glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)    # Setting the line width given as argument.
      
      i=0
      while i < len(self.toros) :
	glBegin(GL_LINE_LOOP)
	for v in self.toros[i] :
	  glVertex3fv(v.get_vertex())
	glEnd()
	i += 1
      
      i=-1
      while i < len(self.toros)-1 :
	ii=0
	while ii < len(self.toros[i]) :
	  glBegin(GL_LINES)
	  glVertex3fv(self.toros[i][ii].get_vertex())
	  glVertex3fv(self.toros[i+1][ii].get_vertex())
	  glEnd()
	  ii += 1
	i += 1	
	
    if self.display_ls :
      # Displaying the Localview.
      self.ls.display(self.base_radius*2.0/10.0)
      
  def set_display_mode(self,display_mode) :
    ''' Change the polyhedron display mode. 
        Value of argument display_mode should be:
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces willbe displayed.
    '''
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("lined","faced","twice")
    
    self.display_mode=display_mode
    
  def set_lines_color(self,lines_color) :
    ''' Change the lines color from the polyhedron.
        Value of argument lines_color should be:
        lines_color  = An objet <type 'Color'> representing the lines color.
    '''
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
      
      if isinstance(lines_color.a,bool) :
	lines_color.a=0
	
    self.lines_color=lines_color
    
  def set_faces_color(self,faces_color) :
    ''' Change the faces color(s) from the polyhedron.
        Value of argument faces_color should be:
        faces_color  = An objet <type 'Color'> representing the faces color.
    '''
    
    if isinstance(faces_color,Color) :
      if type(faces_color.a) == bool :
	faces_color.a=0	  
    
    else :
      raise TypeError(Color)
      
    self.faces_color=faces_color
    
  def set_lines_width(self,lines_width) :
    ''' Change the lines width from the polyhedron.
        Value of argument lines_width should be:
        lines_width  = An integer representing the lines width.
    '''
    if not isinstance(lines_width,int) :
      raise TypeError("Argument lines_width",int)
    elif lines_width < 1 :
      raise ValueError(lines_width,"Lines width value too little.") 
    
    self.lines_width=lines_width
    
  def set_display_ls(self,display_ls) :
    ''' Change the Localview displaying setting.
        Value of argument display_ls should be an boolean value:
        display_ls   = Define if the localview should be display.
    '''    
        
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    else :
      raise TypeError("Argument display_ls",bool)
    
  def set_base_polygon(self,base_polygon) :
    ''' Change the toros basis polygon. '''
    
    if not isinstance(base_polygon,int) :
      raise TypeError("base_polygon argument",int)

    if base_polygon <= 2 :
      print "the base polygon must be greater than 2 "
      quit()
    
    
    self.base_polygon=base_polygon
    self.toros=generate_toros(base_polygon,self.base_radius,self.toros_radius)
    self.ls=Localview()
    
  def set_base_radius(self,base_radius) :
    ''' Change the toros base polygon radius. '''
    
    if not isinstance(base_radius,int) and not isinstance(base_radius,float) :
      raise TypeError("base_radius argument",int,float)
    elif base_radius <= 0.0 :
      raise ValueError("Value of base_radius must be greater than 0.0") 
    
    self.base_radius=base_radius
    self.toros=generate_toros(self.base_polygon,base_radius,self.toros_radius)
    self.ls=Localview()
  
  def set_toros_radius(self,toros_radius) :
    ''' Change the toros radius (without the base polygon radius). '''
    
    if not isinstance(toros_radius,int) and not isinstance(toros_radius,float) :
      raise TypeError("toros_radius argument",int,float)
    elif toros_radius <= 0.0 :
      raise ValueError("Value of toros_radius must be greater than 0.0") 
    
    self.toros_radius=toros_radius
    self.toros=generate_toros(self.base_polygon,self.base_radius,toros_radius)
    self.ls=Localview()
  
  def __doc__(self) :
    ''' Print documentation '''
    
    print '''
    Generate an toros object with position updating, 
    display and settings setters methods.
    
    The display mode set how the toros will be display 
    and can take as values:
    "lined" -> Only the edges will be display.
    "faces" -> Only the faces willbbe display.
    "twice" -> The edges and the faces will be display.
    
    The lines color must be an object from <type 'Color'> available throught
    this module as datatype dealing with colors as unsigned bytes 
    or floating-points values.
    
    The faces color can be:
    -> An object from <type 'Color'> in which case the toros will be filled 
       with this color.
    
    The lines width must be an integer representing the number of pixels from 
    the edges width.
    
    The display_ls argument must be an boolean value point to if the polyhedron 
    own Localview will be displayed. 
    The datatype Localview is available throught this module. 
    sea his documentation to know more about.
    
    '''        
コード例 #18
0
ファイル: pyglutToros.py プロジェクト: mrcyberfighter/pyglut
  def __init__(self,base_polygon,base_radius,toros_radius,display_mode="lined",lines_color=False,faces_color=False,lines_width=1,display_ls=False) :
    ''' Generate an toros object with the given radius and basis polygone settings.
    
        base_polygon = the toros basis polygon.
        base_radius  = the toros basis polygon radius.
        toros_radius = the toros radius (without the base polygon radius). 
        display_mode = "lined" -> only the lines will be displayed.
        display_mode = "faced" -> only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces will be displayed.
        lines_color  = an objet <type 'Color'> representing the lines color.
        faces_color  = an objet <type 'Color'> representing the faces color.
        line_width   = an integer representing the lines width.
    '''
    
    if not isinstance(base_polygon,int) :
      raise TypeError("base_polygon argument",int)

    if base_polygon <= 2 :
      print "the base polygon must be greater than 2 "
      quit()
    
    
    if not isinstance(base_radius,int) and not isinstance(base_radius,float) :
      raise TypeError("base_radius argument",int,float)
    elif base_radius <= 0.0 :
      raise ValueError("Value of base_radius must be greater than 0.0") 
    
    
    if not isinstance(toros_radius,int) and not isinstance(toros_radius,float) :
      raise TypeError("toros_radius argument",int,float)
    elif toros_radius <= 0.0 :
      raise ValueError("Value of toros_radius must be greater than 0.0") 
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("Argument display_mode","lined","faced","twice")
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
    
    if faces_color :
      if not isinstance(faces_color,Color) : 
        raise TypeError("Argument faces_color",Color)
      
      
         	
    
    if not isinstance(lines_width,int) :
      raise TypeError(lines_width,int)
    elif lines_width < 1 :
      raise ValueError("Lines width value too little.") 
    
    if isinstance(lines_color,Color) :
      if type(lines_color.a) == bool :
        lines_color.a=0
    
    if isinstance(faces_color,Color) :
      if type(faces_color.a) == bool :
	faces_color.a=0
    
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
      
    self.base_polygon=base_polygon
    self.base_radius=base_radius
    self.toros_radius=toros_radius
    self.lines_color=lines_color
    self.faces_color=faces_color
    self.lines_width=lines_width
    self.toros=generate_toros(base_polygon,base_radius,toros_radius)
    self.ls=Localview()
    self.center=Vertex(0.0,0.0,0.0)
コード例 #19
0
class Fulleren(object):
    def __init__(self,
                 side_length,
                 display_mode="lined",
                 lines_color=False,
                 pentagons_color=False,
                 hexagons_color=False,
                 lines_width=1,
                 display_ls=False):
        ''' generate an cube object with the given side length settings.
    
        display_mode    = "lined" -> only the lines will be displayed.
        display_mode    = "faced" -> only the faces will be displayed.
        display_mode    = "twice" -> The lines and the faces will be displayed.
        lines_color     = an objet <type 'Color'> representing the lines color.
        pentagons_color = an objet <type 'Color'> representing the pentagons color.
                          an 12-items-list contains <type 'Color'> objects.  
        hexagons_color  = an objet <type 'Color'> representing the hexagons color.
                          an 20-items-list contains <type 'Color'> objects. 
        line_width      = an integer representing the lines width.
    '''

        if not isinstance(side_length, int) and not isinstance(
                side_length, float):
            raise TypeError(int, float)
        elif side_length <= 0.0:
            raise ValueError("Value of side_length must be greater than 0.0")

        if display_mode == "lined" or display_mode == "faced" or display_mode == "twice":
            self.display_mode = display_mode
        else:
            raise ValueError("lined", "faced", "twice")

        if lines_color:
            if not isinstance(lines_color, Color):
                raise TypeError(lines_color, Color)

        if pentagons_color:
            if not isinstance(pentagons_color, Color) and not isinstance(
                    pentagons_color, list):
                raise TypeError(pentagons_color, Color, list)
            elif isinstance(pentagons_color,
                            list) and len(pentagons_color) != 12:
                print "Error pentagons_color argument:\nYou must give an list from 12 Color objects.\nOne Color object per face."
                quit()
            elif isinstance(pentagons_color,
                            list) and len(pentagons_color) == 12:
                tmp = []
                pentagons_color_index = 0
                while pentagons_color_index < 12:
                    if type(pentagons_color[pentagons_color_index].a) == bool:
                        pentagons_color[pentagons_color_index].a = 0
                    pentagons_color_index += 1

        if hexagons_color:
            if not isinstance(hexagons_color, Color) and not isinstance(
                    hexagons_color, list):
                raise TypeError(hexagons_color, Color, list)
            elif isinstance(hexagons_color,
                            list) and len(hexagons_color) != 20:
                print "Error hexagons_color argument:\nYou must give an list from 20 Color objects.\nOne Color object per face."
                quit()
            elif isinstance(hexagons_color,
                            list) and len(hexagons_color) == 20:
                tmp = []
                hexagons_color_index = 0
                while hexagons_color_index < 20:
                    if type(hexagons_color[hexagons_color_index].a) == bool:
                        hexagons_color[hexagons_color_index].a = 0
                    hexagons_color_index += 1

        if not isinstance(lines_width, int):
            raise TypeError(lines_width, int)
        elif lines_width < 1:
            raise ValueError(lines_width, "Lines width value too little.")

        if isinstance(lines_color, Color):
            if type(lines_color.a) == bool:
                lines_color.a = 0

        if isinstance(pentagons_color, Color):
            if type(pentagons_color.a) == bool:
                pentagons_color.a = 0

        if isinstance(hexagons_color, Color):
            if type(hexagons_color.a) == bool:
                hexagons_color.a = 0

        if isinstance(display_ls, bool):
            self.display_ls = display_ls

        self.side_length = side_length
        self.lines_color = lines_color
        self.pentagons_color = pentagons_color
        self.hexagons_color = hexagons_color
        self.lines_width = lines_width
        self.hexagons, self.pentagons = generate_fulleren(side_length)
        self.ls = Localview()

        self.center = Vertex(0.0, 0.0, 0.0)

    def update_pos(self, matrix):
        ''' Apply changing contains in the matrix argument. '''

        if not isinstance(matrix, Matrix):
            raise TypeError(matrix, Matrix)

        center = []
        tmp_pentagons = []
        for polygon in self.pentagons:
            # Loop over every pentagon from the polyhedron.
            tmp_polygon = []
            for lines in polygon:
                tmp_lines = []
                for vertex in lines:
                    # Loop over every vertice from the polygon.
                    res_vertex = matrix * vertex  # Multiply the current vertice with the matrix

                    # Storing the new position from the vertice.
                    tmp_lines.append(
                        res_vertex)  # For the polyhedron polygon container.
                    center.append(
                        res_vertex)  # For polyhedron center computing.

                tmp_polygon.append(tmp_lines)
            tmp_pentagons.append(tmp_polygon)

        self.pentagons = tmp_pentagons  # Update the pentagon container with the new postion from every vertice.

        tmp_hexagons = []
        for polygon in self.hexagons:
            # Loop over every hexagon from the polyhedron.
            tmp_polygon = []
            for lines in polygon:
                tmp_lines = []
                for vertex in lines:
                    # Loop over every vertice from the polygon.

                    res_vertex = matrix * vertex  # Multiply the current vertice with the matrix

                    # Storing the new position from the vertice.
                    tmp_lines.append(
                        res_vertex)  # For the polyhedron polygon container.
                    center.append(
                        res_vertex)  # For polyhedron center computing.

                tmp_polygon.append(tmp_lines)
            tmp_hexagons.append(tmp_polygon)

        self.hexagons = tmp_hexagons  # Update the hexagon container with the new postion from every vertice.

        self.center = get_center_from_polyhedron(
            center)  # Update the polyhedron center.

        self.ls = matrix * self.ls  # Update the localview.

    def display(self):

        if self.display_mode == "lined":
            # Configuration of polygons lines displaying.
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

            if self.lines_color:
                # Lines color configuration.
                glColor4ubv(self.lines_color.get_ubyte_v())

            glLineWidth(self.lines_width)

            for polygon in self.hexagons:
                # Loop over every hexagon from the polyhedron.
                # For only lines displaying.
                glBegin(GL_POLYGON)
                for lines in polygon:
                    for v in lines:
                        # We loop over the every vertice from the polygon.
                        glVertex3fv(v.get_vertex())
                glEnd()

        elif self.display_mode == "faced":
            # Configuration of polygons faces displaying.
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
            if self.pentagons_color and isinstance(self.pentagons_color,
                                                   Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.pentagons_color.get_ubyte_v())

            pentagons_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

            if self.pentagons_color and isinstance(self.pentagons_color,
                                                   Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.pentagons_color.get_ubyte_v())

            for polygon in self.pentagons:
                # Loop over every pentagon from the polyhedron.
                if self.pentagons_color and isinstance(self.pentagons_color,
                                                       list):
                    # Case there are more than one color for the faces displaying.
                    glColor4ubv(self.pentagons_color[pentagons_color_index].
                                get_ubyte_v())

                glBegin(GL_POLYGON)
                for lines in polygon:
                    for v in lines:
                        # We loop over the every vertice from the polygon.
                        glVertex3fv(v.get_vertex())
                glEnd()

                pentagons_color_index += 1

            if self.hexagons_color and isinstance(self.hexagons_color, Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.hexagons_color.get_ubyte_v())

            hexagons_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

            for polygon in self.hexagons:
                # Loop over every hexagon from the polyhedron.
                if self.hexagons_color and isinstance(self.hexagons_color,
                                                      list):
                    # Case there are more than one color for the faces displaying.
                    glColor4ubv(self.hexagons_color[hexagons_color_index].
                                get_ubyte_v())

                glBegin(GL_POLYGON)
                for lines in polygon:
                    for v in lines:
                        # We loop over the every vertice from the polygon.
                        glVertex3fv(v.get_vertex())
                glEnd()
                hexagons_color_index += 1

        elif self.display_mode == "twice":
            # Configuration of polygons faces displaying.
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
            if self.pentagons_color and isinstance(self.pentagons_color,
                                                   Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.pentagons_color.get_ubyte_v())

            pentagons_color_index = 0
            for polygon in self.pentagons:
                # Loop over every pentagon from the polyhedron.
                if self.pentagons_color and isinstance(self.pentagons_color,
                                                       list):
                    # Case there are more than one color for the faces displaying.
                    glColor4ubv(self.pentagons_color[pentagons_color_index].
                                get_ubyte_v())

                glBegin(GL_POLYGON)
                for lines in polygon:
                    for v in lines:
                        # We loop over the every vertice from the polygon.
                        glVertex3fv(v.get_vertex())
                glEnd()

                pentagons_color_index += 1

            if self.hexagons_color and isinstance(self.hexagons_color, Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.hexagons_color.get_ubyte_v())

            hexagons_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

            for polygon in self.hexagons:
                # Loop over every hexagon from the polyhedron.
                if self.hexagons_color and isinstance(self.hexagons_color,
                                                      list):
                    # Case there are more than one color for the faces displaying.
                    glColor4ubv(self.hexagons_color[hexagons_color_index].
                                get_ubyte_v())

                glBegin(GL_POLYGON)
                for lines in polygon:
                    for v in lines:
                        # We loop over the every vertice from the polygon.
                        glVertex3fv(v.get_vertex())
                glEnd()

                hexagons_color_index += 1

            # Configuration of polygons lines displaying.
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

            if self.lines_color:
                # Lines color configuration.
                glColor4ubv(self.lines_color.get_ubyte_v())

            glLineWidth(self.lines_width)

            for polygon in self.hexagons:
                # Loop over every hexagon from the polyhedron.
                # For only lines displaying.
                glBegin(GL_POLYGON)
                for lines in polygon:
                    for v in lines:
                        # We loop over the every vertice from the polygon.
                        glVertex3fv(v.get_vertex())
                glEnd()

        if self.display_ls:
            # Displaying the Localview.
            self.ls.display(self.side_length * 4.0 / 10.0)

    def set_display_mode(self, display_mode):
        ''' Change the polyhedron display mode. 
        Value of argument display_mode should be:
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces willbe displayed.
    '''

        if display_mode == "lined" or display_mode == "faced" or display_mode == "twice":
            self.display_mode = display_mode
        else:
            raise ValueError("lined", "faced", "twice")

        self.display_mode = display_mode

    def set_lines_color(self, lines_color):
        ''' Change the lines color from the polyhedron.
        Value of argument lines_color should be:
        lines_color  = An objet <type 'Color'> representing the lines color.
    '''

        if lines_color:
            if not isinstance(lines_color, Color):
                raise TypeError("Argument lines_color", Color)

            if isinstance(lines_color.a, bool):
                lines_color.a = 0

        self.lines_color = lines_color

    def set_pentagons_color(self, pentagons_color):
        ''' Change the faces color(s) from the polyhedron.
        Value of argument faces_color should be:
        faces_color  = An objet <type 'Color'> representing the pentagons faces color.
                       An 12-items-list from object <type 'Color'>.
                       One item per pentagon face. 
    '''

        if pentagons_color:

            if not isinstance(pentagons_color, Color) and not isinstance(
                    pentagons_color, list):
                raise TypeError(pentagons_color, Color, list)

            elif isinstance(pentagons_color,
                            list) and len(pentagons_color) != 12:
                print "Error pentagons_color argument:\nYou must give an list from 12 Color objects.\nOne Color object per face."
                quit()

            elif isinstance(pentagons_color,
                            list) and len(pentagons_color) == 12:
                tmp = []
                pentagons_color_index = 0
                while pentagons_color_index < 12:
                    if type(pentagons_color[pentagons_color_index].a) == bool:
                        pentagons_color[pentagons_color_index].a = 0
                    pentagons_color_index += 1

            elif isinstance(pentagons_color, Color):
                if type(pentagons_color.a) == bool:
                    pentagons_color.a = 0

            else:
                raise TypeError(Color)

            self.pentagons_color = pentagons_color

    def set_hexagons_color(self, hexagons_color):
        ''' Change the faces color(s) from the polyhedron.
        Value of argument faces_color should be:
        faces_color  = An objet <type 'Color'> representing the hexagons faces color.
                       An 20-items-list from object <type 'Color'>.
                       One item per hexagons face. 
    '''

        if hexagons_color:

            if not isinstance(hexagons_color, Color) and not isinstance(
                    hexagons_color, list):
                raise TypeError(hexagons_color, Color, list)

            elif isinstance(hexagons_color,
                            list) and len(hexagons_color) != 20:
                print "Error hexagons_color argument:\nYou must give an list from 20 Color objects.\nOne Color object per face."
                quit()

            elif isinstance(hexagons_color,
                            list) and len(hexagons_color) == 20:
                tmp = []
                hexagons_color_index = 0
                while hexagons_color_index < 20:
                    if type(hexagons_color[hexagons_color_index].a) == bool:
                        hexagons_color[hexagons_color_index].a = 0
                    hexagons_color_index += 1

            elif isinstance(hexagons_color, Color):
                if type(hexagons_color.a) == bool:
                    hexagons_color.a = 0

            else:
                raise TypeError(Color)

            self.hexagons_color = hexagons_color

    def set_lines_width(self, lines_width):
        ''' Change the lines width from the polyhedron.
        Value of argument lines_width should be:
        lines_width  = An integer representing the lines width.
    '''
        if not isinstance(lines_width, int):
            raise TypeError("Argument lines_width", int)
        elif lines_width < 1:
            raise ValueError(lines_width, "Lines width value too little.")

        self.lines_width = lines_width

    def set_display_ls(self, display_ls):
        ''' Change the Localview displaying setting.
        Value of argument display_ls should be an boolean value:
        display_ls   = Define if the localview should be display.
    '''

        if isinstance(display_ls, bool):
            self.display_ls = display_ls
        else:
            raise TypeError("Argument display_ls", bool)

    def set_side_length(self, side_length):
        if not isinstance(side_length, int) and not isinstance(
                side_length, float):
            raise TypeError("Argument side_length", int, float)
        elif side_length < 0.0:
            raise ValueError(
                "Value of argument side_length must be greater than 0.0")

        self.side_length = side_length
        self.hexagons, self.pentagons = generate_fulleren(side_length)
        self.ls = Localview()

    def __doc__(self):
        ''' Print documentation '''

        print '''
コード例 #20
0
    def __init__(self,
                 side_length,
                 display_mode="lined",
                 lines_color=False,
                 pentagons_color=False,
                 hexagons_color=False,
                 lines_width=1,
                 display_ls=False):
        ''' generate an cube object with the given side length settings.
    
        display_mode    = "lined" -> only the lines will be displayed.
        display_mode    = "faced" -> only the faces will be displayed.
        display_mode    = "twice" -> The lines and the faces will be displayed.
        lines_color     = an objet <type 'Color'> representing the lines color.
        pentagons_color = an objet <type 'Color'> representing the pentagons color.
                          an 12-items-list contains <type 'Color'> objects.  
        hexagons_color  = an objet <type 'Color'> representing the hexagons color.
                          an 20-items-list contains <type 'Color'> objects. 
        line_width      = an integer representing the lines width.
    '''

        if not isinstance(side_length, int) and not isinstance(
                side_length, float):
            raise TypeError(int, float)
        elif side_length <= 0.0:
            raise ValueError("Value of side_length must be greater than 0.0")

        if display_mode == "lined" or display_mode == "faced" or display_mode == "twice":
            self.display_mode = display_mode
        else:
            raise ValueError("lined", "faced", "twice")

        if lines_color:
            if not isinstance(lines_color, Color):
                raise TypeError(lines_color, Color)

        if pentagons_color:
            if not isinstance(pentagons_color, Color) and not isinstance(
                    pentagons_color, list):
                raise TypeError(pentagons_color, Color, list)
            elif isinstance(pentagons_color,
                            list) and len(pentagons_color) != 12:
                print "Error pentagons_color argument:\nYou must give an list from 12 Color objects.\nOne Color object per face."
                quit()
            elif isinstance(pentagons_color,
                            list) and len(pentagons_color) == 12:
                tmp = []
                pentagons_color_index = 0
                while pentagons_color_index < 12:
                    if type(pentagons_color[pentagons_color_index].a) == bool:
                        pentagons_color[pentagons_color_index].a = 0
                    pentagons_color_index += 1

        if hexagons_color:
            if not isinstance(hexagons_color, Color) and not isinstance(
                    hexagons_color, list):
                raise TypeError(hexagons_color, Color, list)
            elif isinstance(hexagons_color,
                            list) and len(hexagons_color) != 20:
                print "Error hexagons_color argument:\nYou must give an list from 20 Color objects.\nOne Color object per face."
                quit()
            elif isinstance(hexagons_color,
                            list) and len(hexagons_color) == 20:
                tmp = []
                hexagons_color_index = 0
                while hexagons_color_index < 20:
                    if type(hexagons_color[hexagons_color_index].a) == bool:
                        hexagons_color[hexagons_color_index].a = 0
                    hexagons_color_index += 1

        if not isinstance(lines_width, int):
            raise TypeError(lines_width, int)
        elif lines_width < 1:
            raise ValueError(lines_width, "Lines width value too little.")

        if isinstance(lines_color, Color):
            if type(lines_color.a) == bool:
                lines_color.a = 0

        if isinstance(pentagons_color, Color):
            if type(pentagons_color.a) == bool:
                pentagons_color.a = 0

        if isinstance(hexagons_color, Color):
            if type(hexagons_color.a) == bool:
                hexagons_color.a = 0

        if isinstance(display_ls, bool):
            self.display_ls = display_ls

        self.side_length = side_length
        self.lines_color = lines_color
        self.pentagons_color = pentagons_color
        self.hexagons_color = hexagons_color
        self.lines_width = lines_width
        self.hexagons, self.pentagons = generate_fulleren(side_length)
        self.ls = Localview()

        self.center = Vertex(0.0, 0.0, 0.0)
コード例 #21
0
  def __init__(self,radius,basis,display_mode="lined",lines_color=False,faces_color=False,lines_width=1,display_ls=False) :
    ''' generate an trigon sphere object with the given radius and polygone basis.
    
        basis        = Integer taken as basis for the sphere generating.  
        radius       = Radius of the sphere. 
        display_mode = "lined" -> only the lines will be displayed.
        display_mode = "faced" -> only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces will be displayed.
        lines_color  = an objet <type 'Color'> representing the lines color.
        faces_color  = an objet <type 'Color'> representing the faces color.
        line_width   = an integer representing the lines width.
    '''
    
    if not isinstance(radius,int) and not isinstance(radius,float) :
      raise TypeError(int,float)
    elif radius <= 0.0 :
      raise ValueError("Value of radius must be greater than 0.0") 
    
    if not isinstance(basis,int) :
      raise TypeError(int)

    if basis < 6 or basis % 4 :
      print "the basis for the sphere must be greater as 5 and basis % 4 == 0 "
      quit()
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("Argument display_mode","lined","faced","twice")
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
    
    if faces_color :
      if not isinstance(faces_color,Color) : 
        raise TypeError("Argument faces_color",Color)
      
      
         	
    
    if not isinstance(lines_width,int) :
      raise TypeError(lines_width,int)
    elif lines_width < 1 :
      raise ValueError("Lines width value too little.") 
    
    if isinstance(lines_color,Color) :
      if type(lines_color.a) == bool :
        lines_color.a=0
    
    if not type(faces_color) == bool :
      if type(faces_color.a) == bool :
	faces_color.a=0
    
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    
    self.lines_color=lines_color
    self.faces_color=faces_color
    self.lines_width=lines_width
    self.basis=basis
    self.radius=radius
    self.trigons=generate_trigon_sphere(basis,radius)[0]
    self.ls=Localview()
    
    self.center=Vertex(0.0,0.0,0.0)    
コード例 #22
0
ファイル: pyglutFulleren.py プロジェクト: PyMine/PyMine
  def __init__(self,side_length,display_mode="lined",lines_color=False,pentagons_color=False,hexagons_color=False,lines_width=1,display_ls=False) :
    ''' generate an cube object with the given side length settings.
    
        display_mode    = "lined" -> only the lines will be displayed.
        display_mode    = "faced" -> only the faces will be displayed.
        display_mode    = "twice" -> The lines and the faces will be displayed.
        lines_color     = an objet <type 'Color'> representing the lines color.
        pentagons_color = an objet <type 'Color'> representing the pentagons color.
                          an 12-items-list contains <type 'Color'> objects.  
        hexagons_color  = an objet <type 'Color'> representing the hexagons color.
                          an 20-items-list contains <type 'Color'> objects. 
        line_width      = an integer representing the lines width.
    '''
    
    if not isinstance(side_length,int) and not isinstance(side_length,float) :
      raise TypeError(int,float)
    elif side_length <= 0.0 :
      raise ValueError("Value of side_length must be greater than 0.0") 
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("lined","faced","twice")
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError(lines_color,Color)
      
    
    if pentagons_color :
      if not isinstance(pentagons_color,Color) and not isinstance(pentagons_color,list) :
        raise TypeError(pentagons_color,Color,list)
      elif isinstance(pentagons_color,list) and len(pentagons_color) != 12 :
	print "Error pentagons_color argument:\nYou must give an list from 12 Color objects.\nOne Color object per face."
	quit()
      elif isinstance(pentagons_color,list) and len(pentagons_color) == 12 :
        tmp=[]
        pentagons_color_index=0
        while pentagons_color_index < 12 :
	  if type(pentagons_color[pentagons_color_index].a) == bool :
	    pentagons_color[pentagons_color_index].a=0
	  pentagons_color_index += 1
      
    if hexagons_color :
      if not isinstance(hexagons_color,Color) and not isinstance(hexagons_color,list) :
        raise TypeError(hexagons_color,Color,list)
      elif isinstance(hexagons_color,list) and len(hexagons_color) != 20 :
	print "Error hexagons_color argument:\nYou must give an list from 20 Color objects.\nOne Color object per face."
	quit()
      elif isinstance(hexagons_color,list) and len(hexagons_color) == 20 :
        tmp=[]
        hexagons_color_index=0
        while hexagons_color_index < 20 :
	  if type(hexagons_color[hexagons_color_index].a) == bool :
	    hexagons_color[hexagons_color_index].a=0
	  hexagons_color_index += 1    
        
    
    if not isinstance(lines_width,int) :
      raise TypeError(lines_width,int)
    elif lines_width < 1 :
      raise ValueError(lines_width,"Lines width value too little.") 
    
    if isinstance(lines_color,Color) :
      if type(lines_color.a) == bool :
        lines_color.a=0
    
    if isinstance(pentagons_color,Color) :
      if type(pentagons_color.a) == bool :
	pentagons_color.a=0
	
    if isinstance(hexagons_color,Color) :
      if type(hexagons_color.a) == bool :
	hexagons_color.a=0 	
    
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    
    self.side_length=side_length
    self.lines_color=lines_color
    self.pentagons_color=pentagons_color
    self.hexagons_color=hexagons_color
    self.lines_width=lines_width
    self.hexagons,self.pentagons=generate_fulleren(side_length)
    self.ls=Localview()
    
    self.center=Vertex(0.0,0.0,0.0)    
コード例 #23
0
ファイル: pyglutIcosahedron.py プロジェクト: PyMine/PyMine
  def __init__(self,side_length,display_mode="lined",lines_color=False,faces_color=False,lines_width=1,display_ls=False) :
    ''' Generate an Icosahedron object with the given side length settings.
        
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces will be displayed.
        lines_color  = An objet <type 'Color'> representing the lines color.
        faces_color  = An objet <type 'Color'> representing the faces color.
                       An 8-items-list from object <type 'Color'>.
                       One item per icosahedron face. 
        lines_width  = An integer representing the lines width.
        display_ls   = Define if the localview should be display.
    '''
    
    if not isinstance(side_length,int) and not isinstance(side_length,float) :
      raise TypeError("Argument side_length",int,float)
    elif side_length <= 0.0 :
      raise ValueError("Value of argument side_length must be greater than 0.0") 
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("Argument display_mode","lined","faced","twice")
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
    
    if faces_color :
      if not isinstance(faces_color,Color) and not isinstance(faces_color,list) :
        raise TypeError(faces_color,Color,list)
      elif isinstance(faces_color,list) and len(faces_color) != 20 :
	print "Error faces_color argument:\nYou must give an list from 20 Color objects.\nOne Color object per face."
	quit()
      elif isinstance(faces_color,list) and len(faces_color) == 20 :
        tmp=[]
        faces_color_index=0
        while faces_color_index < 20 :
	  if type(faces_color[faces_color_index].a) == bool :
	    faces_color[faces_color_index].a=0
	  faces_color_index += 1
      
         	
    
    if not isinstance(lines_width,int) :
      raise TypeError("Argument lines_width",int)
    elif lines_width < 1 :
      raise ValueError(lines_width,"Lines width value too little.") 
    
    if isinstance(lines_color,Color) :
      if type(lines_color.a) == bool :
        lines_color.a=0
    
    if isinstance(faces_color,Color) :
      if type(faces_color.a) == bool :
	faces_color.a=0
    
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    
    self.side_length=side_length
    self.lines_color=lines_color
    self.faces_color=faces_color
    self.lines_width=lines_width
    self.polyhedron=generate_icosahedron(side_length)[1]
    self.ls=Localview()
    
    self.center=Vertex(0.0,0.0,0.0)    
コード例 #24
0
class Icosahedron(object):
    def __init__(self,
                 side_length,
                 display_mode="lined",
                 lines_color=False,
                 faces_color=False,
                 lines_width=1,
                 display_ls=False):
        ''' Generate an Icosahedron object with the given side length settings.
        
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces will be displayed.
        lines_color  = An objet <type 'Color'> representing the lines color.
        faces_color  = An objet <type 'Color'> representing the faces color.
                       An 8-items-list from object <type 'Color'>.
                       One item per icosahedron face. 
        lines_width  = An integer representing the lines width.
        display_ls   = Define if the localview should be display.
    '''

        if not isinstance(side_length, int) and not isinstance(
                side_length, float):
            raise TypeError("Argument side_length", int, float)
        elif side_length <= 0.0:
            raise ValueError(
                "Value of argument side_length must be greater than 0.0")

        if display_mode == "lined" or display_mode == "faced" or display_mode == "twice":
            self.display_mode = display_mode
        else:
            raise ValueError("Argument display_mode", "lined", "faced",
                             "twice")

        if lines_color:
            if not isinstance(lines_color, Color):
                raise TypeError("Argument lines_color", Color)

        if faces_color:
            if not isinstance(faces_color, Color) and not isinstance(
                    faces_color, list):
                raise TypeError(faces_color, Color, list)
            elif isinstance(faces_color, list) and len(faces_color) != 20:
                print "Error faces_color argument:\nYou must give an list from 20 Color objects.\nOne Color object per face."
                quit()
            elif isinstance(faces_color, list) and len(faces_color) == 20:
                tmp = []
                faces_color_index = 0
                while faces_color_index < 20:
                    if type(faces_color[faces_color_index].a) == bool:
                        faces_color[faces_color_index].a = 0
                    faces_color_index += 1

        if not isinstance(lines_width, int):
            raise TypeError("Argument lines_width", int)
        elif lines_width < 1:
            raise ValueError(lines_width, "Lines width value too little.")

        if isinstance(lines_color, Color):
            if type(lines_color.a) == bool:
                lines_color.a = 0

        if isinstance(faces_color, Color):
            if type(faces_color.a) == bool:
                faces_color.a = 0

        if isinstance(display_ls, bool):
            self.display_ls = display_ls

        self.side_length = side_length
        self.lines_color = lines_color
        self.faces_color = faces_color
        self.lines_width = lines_width
        self.polyhedron = generate_icosahedron(side_length)[1]
        self.ls = Localview()

        self.center = Vertex(0.0, 0.0, 0.0)

    def update_pos(self, matrix):
        ''' Apply changing contains in the matrix argument. '''

        if not isinstance(matrix, Matrix):
            raise TypeError(matrix, Matrix)

        center = []
        tmp_polyhedron = []

        for polygon in self.polyhedron:
            # Loop over every polygon from the polyhedron.
            tmp_polygon = []

            for vertex in polygon:
                # Loop over every vertice from the polygon.

                res_vertex = matrix * vertex  # Multiply the current vertice with the matrix

                # Storing the new position from the vertice.
                tmp_polygon.append(
                    res_vertex)  # For the polyhedron polygon container.
                center.append(res_vertex)  # For polyhedron center computing.

            tmp_polyhedron.append(tmp_polygon)

        self.polyhedron = tmp_polyhedron  # Update the polygon container with the new postion from every vertice.

        self.center = get_center_from_polyhedron(
            center)  # Update the polyhedron center.

        self.ls = matrix * self.ls  # Update the localview.

    def display(self):
        ''' Icosahedron displaying method towards the settings. '''

        faces_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

        if self.display_mode == "lined" or self.display_mode == "faced":

            if self.display_mode == "lined" and self.lines_color:
                # Configuration of polygons lines displaying.
                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

                if self.lines_color:
                    # Lines color configuration.
                    glColor4ubv(self.lines_color.get_ubyte_v())

                glLineWidth(self.lines_width)

            elif self.display_mode == "faced":
                # Configuration of polygons faces displaying.
                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

                if self.faces_color and isinstance(self.faces_color, Color):
                    # Faces colorizing configuration.
                    glColor4ubv(self.faces_color.get_ubyte_v())

            for polygon in self.polyhedron:
                # We loop over the polyhedron polygons container.

                if self.faces_color and isinstance(
                        self.faces_color,
                        list) and self.display_mode == "faced":
                    # Faces multi-colorizing configuration.
                    glColor4ubv(
                        self.faces_color[faces_color_index].get_ubyte_v())

                # Displaying one polygon:
                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()

                faces_color_index += 1

        elif self.display_mode == "twice":

            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

            if self.faces_color and isinstance(self.faces_color, Color):
                glColor4ubv(self.faces_color.get_ubyte_v())

            for faces in self.polyhedron:
                # We loop over the polyhedron polygons container.

                if self.faces_color and isinstance(self.faces_color, list):
                    # Faces multi-colorizing configuration.
                    glColor4ubv(
                        self.faces_color[faces_color_index].get_ubyte_v())

                # Displaying one polygon face:
                glBegin(GL_POLYGON)
                for v in faces:
                    # We loop over the every vertice from the face.
                    glVertex3fv(v.get_vertex())
                glEnd()

                faces_color_index += 1

            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

            if self.lines_color:
                # Lines color configuration.
                glColor4ubv(self.lines_color.get_ubyte_v())

            glLineWidth(self.lines_width)

            # Displaying one polygon face edges:
            for faces in self.polyhedron:

                glBegin(GL_POLYGON)
                for v in faces:
                    # We loop over the every vertice from the face.
                    glVertex3fv(v.get_vertex())
                glEnd()

        if self.display_ls:
            # Displaying the Localview.
            self.ls.display(self.side_length * 2.0 / 10.0)

    def set_display_mode(self, display_mode):
        ''' Change the polyhedron display mode. 
        Value of argument display_mode should be:
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces willbe displayed.
    '''

        if display_mode == "lined" or display_mode == "faced" or display_mode == "twice":
            self.display_mode = display_mode
        else:
            raise ValueError("lined", "faced", "twice")

        self.display_mode = display_mode

    def set_lines_color(self, lines_color):
        ''' Change the lines color from the polyhedron.
        Value of argument lines_color should be:
        lines_color  = An objet <type 'Color'> representing the lines color.
    '''

        if lines_color:
            if not isinstance(lines_color, Color):
                raise TypeError("Argument lines_color", Color)

            if isinstance(lines_color.a, bool):
                lines_color.a = 0

        self.lines_color = lines_color

    def set_faces_color(self, faces_color):
        ''' Change the faces color(s) from the polyhedron.
        Value of argument faces_color should be:
        faces_color  = An objet <type 'Color'> representing the faces color.
                       An 20-items-list from object <type 'Color'>.
                       One item per icosahedron face. 
    '''

        if not isinstance(faces_color, Color) and not isinstance(
                faces_color, list):
            raise TypeError(faces_color, Color, list)

        elif isinstance(faces_color, list) and len(faces_color) != 20:
            print "Error faces_color argument:\nYou must give an list from 20 Color objects.\nOne Color object per face."
            quit()

        elif isinstance(faces_color, list) and len(faces_color) == 20:
            tmp = []
            faces_color_index = 0
            while faces_color_index < 20:
                if isinstance(faces_color[faces_color_index].a, bool):
                    faces_color[faces_color_index].a = 0
                faces_color_index += 1

        elif isinstance(faces_color, Color):
            if type(faces_color.a) == bool:
                faces_color.a = 0

        else:
            raise TypeError(Color)

        self.faces_color = faces_color

    def set_lines_width(self, lines_width):
        ''' Change the lines width from the polyhedron.
        Value of argument lines_width should be:
        lines_width  = An integer representing the lines width.
    '''
        if not isinstance(lines_width, int):
            raise TypeError("Argument lines_width", int)
        elif lines_width < 1:
            raise ValueError(lines_width, "Lines width value too little.")

        self.lines_width = lines_width

    def set_display_ls(self, display_ls):
        ''' Change the Localview displaying setting.
        Value of argument display_ls should be an boolean value:
        display_ls   = Define if the localview should be display.
    '''

        if isinstance(display_ls, bool):
            self.display_ls = display_ls
        else:
            raise TypeError("Argument display_ls", bool)

    def set_side_length(self, side_length):
        if not isinstance(side_length, int) and not isinstance(
                side_length, float):
            raise TypeError("Argument side_length", int, float)
        elif side_length < 0.0:
            raise ValueError(
                "Value of argument side_length must be greater than 0.0")

        self.side_length = side_length
        self.polyhedron = generate_icosahedron(side_length)[1]
        self.ls = Localview()

    def __doc__(self):
        ''' Print documentation '''

        print '''
コード例 #25
0
    def __init__(self,
                 side_length,
                 display_mode="lined",
                 lines_color=False,
                 quads_color=False,
                 triangles_color=False,
                 lines_width=1,
                 display_ls=False):
        ''' generate an 26 faces polyhedron object with the given side length settings.
           
        display_mode    = "lined" -> only the lines will be displayed.
        display_mode    = "faced" -> only the faces will be displayed.
        display_mode    = "twice" -> The lines and the faces will be displayed.
        lines_color     = an objet <type 'Color'> representing the lines color.
        quads_color     = an objet <type 'Color'> representing the quads color.
                          an 18-items-list contains <type 'Color'> objects.  
        triangles_color = an objet <type 'Color'> representing the triangles color.
                          an 8-items-list contains <type 'Color'> objects. 
        line_width      = an integer representing the lines width.
    '''

        if not isinstance(side_length, int) and not isinstance(
                side_length, float):
            raise TypeError(int, float)
        elif side_length < 0.0:
            raise ValueError("Value of side_length must be greater than 0.0")

        if display_mode == "lined" or display_mode == "faced" or display_mode == "twice":
            self.display_mode = display_mode
        else:
            raise ValueError("lined", "faced", "twice")

        if lines_color:
            if not isinstance(lines_color, Color):
                raise TypeError(lines_color, Color)

        if quads_color:
            if not isinstance(quads_color, Color) and not isinstance(
                    quads_color, list):
                raise TypeError(quads_color, Color, list)
            elif isinstance(quads_color, list) and len(quads_color) != 18:
                print "Error quads_color argument:\nYou must give an list from 18 Color objects.\nOne Color object per face."
                quit()
            elif isinstance(quads_color, list) and len(quads_color) == 18:
                tmp = []
                quads_color_index = 0
                while quads_color_index < 18:
                    if type(quads_color[quads_color_index].a) == bool:
                        quads_color[quads_color_index].a = 0
                    quads_color_index += 1

        if triangles_color:
            if not isinstance(triangles_color, Color) and not isinstance(
                    triangles_color, list):
                raise TypeError(triangles_color, Color, list)
            elif isinstance(triangles_color,
                            list) and len(triangles_color) != 8:
                print "Error triangles_color argument:\nYou must give an list from 8 Color objects.\nOne Color object per face."
                quit()
            elif isinstance(triangles_color,
                            list) and len(triangles_color) == 8:
                tmp = []
                triangles_color_index = 0
                while triangles_color_index < 8:
                    if type(triangles_color[triangles_color_index].a) == bool:
                        triangles_color[triangles_color_index].a = 0
                    triangles_color_index += 1

        if not isinstance(lines_width, int):
            raise TypeError(lines_width, int)
        elif lines_width < 1:
            raise ValueError(lines_width, "Lines width value too little.")

        if isinstance(lines_color, Color):
            if type(lines_color.a) == bool:
                lines_color.a = 0

        if isinstance(quads_color, Color):
            if type(quads_color.a) == bool:
                quads_color.a = 0

        if isinstance(triangles_color, Color):
            if type(triangles_color.a) == bool:
                triangles_color.a = 0

        if isinstance(display_ls, bool):
            self.display_ls = display_ls

        self.side_length = side_length
        self.lines_color = lines_color
        self.quads_color = quads_color
        self.triangles_color = triangles_color
        self.lines_width = lines_width
        self.triangles, self.quads = generate_polyhedron_26_faces(side_length)
        self.ls = Localview()

        self.center = Vertex(0.0, 0.0, 0.0)
コード例 #26
0
class Quad_Sphere(object) :
  def __init__(self,radius,basis,display_mode="lined",lines_color=False,faces_color=False,lines_width=1,display_ls=False) :
    ''' generate an quad sphere object with the given radius and polygone basis. 
    
        basis        = Integer taken as basis for the sphere generating.  
        radius       = Radius of the sphere. 
        display_mode = "lined" -> only the lines will be displayed.
        display_mode = "faced" -> only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces will be displayed.
        lines_color  = an objet <type 'Color'> representing the lines color.
        faces_color  = an objet <type 'Color'> representing the faces color.
        line_width   = an integer representing the lines width.
    '''
    
    if not isinstance(radius,int) and not isinstance(radius,float) :
      raise TypeError(int,float)
    elif radius <= 0.0 :
      raise ValueError("Value of radius must be greater than 0.0") 
    
    if not isinstance(basis,int) :
      raise TypeError(int)

    if basis < 6 or basis % 2 :
      print "the basis for the sphere must be greater as 5 and basis % 2 == 0 "
      quit()
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("Argument display_mode","lined","faced","twice")
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
    
    if faces_color :
      if not isinstance(faces_color,Color) : 
        raise TypeError("Argument faces_color",Color)
      
    if not isinstance(lines_width,int) :
      raise TypeError(lines_width,int)
    elif lines_width < 1 :
      raise ValueError("Lines width value too little.") 
      
    
    
    if isinstance(lines_color,Color) :
      if type(lines_color.a) == bool :
        lines_color.a=0
    
    if isinstance(faces_color,Color) :
      if type(faces_color.a) == bool :
	faces_color.a=0
    
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    
    self.lines_color=lines_color
    self.faces_color=faces_color
    self.lines_width=lines_width
    self.basis=basis
    self.radius=radius
    self.polygons=generate_quad_sphere(basis,radius)[0]
    self.ls=Localview()
    
    self.center=Vertex(0.0,0.0,0.0)    
    
  def update_pos(self,matrix) :
    ''' Apply changing contains in the matrix argument. '''
    
    if not isinstance(matrix, Matrix) :
      raise TypeError(matrix,Matrix)
    
    center=[]
    tmp_polyhedron=[]
    for lines in self.polygons :
      # Loop over every line from the sphere. 
      tmp_polygon=[]
      for vertex in lines :
	# Loop over every line from the line.
	
	res_vertex= matrix * vertex # Multiply the current vertice with the matrix
 	
 	# Storing the new position from the vertice.
 	tmp_polygon.append(res_vertex)  # For the sphere polygon container.
	center.append(res_vertex)       # For sphere center computing.
	
      tmp_polyhedron.append(tmp_polygon)
    
    self.polygons=tmp_polyhedron
    
    self.center=get_center_from_polyhedron(center)  
    
    self.ls= matrix * self.ls
    
    
    
  def display(self) :
    if self.display_mode == "lined" :
      if self.lines_color :
        # Lines color configuration. 	
        glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)    # Setting the line width given as argument.
      
      i=0
      while i < len(self.polygons) :
	# Loop displaying the lines of the polygons on an surface of the sphere.
	# We process by crossing the line displaying.
	ii=0
	glBegin(GL_LINE_LOOP)
	while ii < len(self.polygons[i]) :
	  glVertex3fv(self.polygons[i][ii].get_vertex())
	  ii += 1 
	glEnd()
	i += 1    
      
      
      i=0
      while i < len(self.polygons) :
	# Loop displaying the lines of the polygons on an surface of the sphere.
	# We process by crossing the line displaying.
	ii=0
	glBegin(GL_LINE_LOOP)
	while ii < len(self.polygons[i]) : 
	  glVertex3fv(self.polygons[ii][i].get_vertex())
	  ii += 1  
	glEnd()
	i += 1
	
    elif self.display_mode == "faced" :
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL) 
      
      if self.faces_color :
	# Faces color configuration. 
        glColor4ubv(self.faces_color.get_ubyte_v())
	
      i=0	
      while i < len(self.polygons) :
	# Iteration over the polygon container variable to compute the quads.
	ii=0
	while ii < self.basis-1 :
	  # We compute the quads: for spheres quads displaying.
	  glBegin(GL_QUADS)
	  if not i == self.basis-1 :
	    glVertex3fv(self.polygons[i][ii].get_vertex())
	    glVertex3fv(self.polygons[i+1][ii].get_vertex())
	    glVertex3fv(self.polygons[i+1][ii+1].get_vertex())
	    glVertex3fv(self.polygons[i][ii+1].get_vertex())
	  else :
	    glVertex3fv(self.polygons[i][ii].get_vertex())
	    glVertex3fv(self.polygons[0][ii].get_vertex())
	    glVertex3fv(self.polygons[0][ii+1].get_vertex())
	    glVertex3fv(self.polygons[i][ii+1].get_vertex())
          
          glEnd()
          
	  ii += 1
	i += 1
		  
      
    elif self.display_mode == "twice" :  
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL) 
      
      if self.faces_color :
        glColor4ubv(self.faces_color.get_ubyte_v())
	
      i=0	
      while i < len(self.polygons) :
	# Iteration over the polygon container variable to compute the quads.
	ii=0
	while ii < self.basis-1 :
	  # We compute the quads: for spheres quads displaying.
	  glBegin(GL_QUADS)
	  if not i == self.basis-1 :
	    glVertex3fv(self.polygons[i][ii].get_vertex())
	    glVertex3fv(self.polygons[i+1][ii].get_vertex())
	    glVertex3fv(self.polygons[i+1][ii+1].get_vertex())
	    glVertex3fv(self.polygons[i][ii+1].get_vertex())
	  else :
	    glVertex3fv(self.polygons[i][ii].get_vertex())
	    glVertex3fv(self.polygons[0][ii].get_vertex())
	    glVertex3fv(self.polygons[0][ii+1].get_vertex())
	    glVertex3fv(self.polygons[i][ii+1].get_vertex())
          
          glEnd()
          
	  ii += 1
	i += 1
	
      if self.lines_color :
        # Lines color configuration. 	
        glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)    # Setting the line width given as argument.
      
      i=0
      while i < len(self.polygons) :
	# Loop displaying the lines of the polygons on an surface of the sphere.
	# We process by crossing the line displaying.
	ii=0
	glBegin(GL_LINE_LOOP)
	while ii < len(self.polygons[i]) :
	  glVertex3fv(self.polygons[i][ii].get_vertex())
	  ii += 1 
	glEnd()
	i += 1    
      
      
      i=0
      while i < len(self.polygons) :
	# Loop displaying the lines of the polygons on an surface of the sphere.
	# We process by crossing the line displaying.
	ii=0
	glBegin(GL_LINE_LOOP)
	while ii < len(self.polygons[i]) : 
	  glVertex3fv(self.polygons[ii][i].get_vertex())
	  ii += 1  
	glEnd()
	i += 1	
	
    if self.display_ls :
      # Displaying the Localview.
      self.ls.display(self.radius*2.0/10.0)	
	
  def set_display_mode(self,display_mode) :
    ''' Change the sphere display mode. 
        Value of argument display_mode should be:
        display_mode = "lined" -> Only the lines will be displayed.
        display_mode = "faced" -> Only the faces will be displayed.
        display_mode = "twice" -> The lines and the faces willbe displayed.
    '''
    
    if display_mode == "lined" or display_mode == "faced" or display_mode == "twice" :
      self.display_mode=display_mode
    else :
      raise ValueError("lined","faced","twice")
    
    self.display_mode=display_mode
    
  def set_lines_color(self,lines_color) :
    ''' Change the lines color from the sphere.
        Value of argument lines_color should be:
        lines_color  = An objet <type 'Color'> representing the lines color.
    '''
    
    if lines_color :
      if not isinstance(lines_color,Color) :
        raise TypeError("Argument lines_color",Color)
      
      if isinstance(lines_color.a,bool) :
	lines_color.a=0
	
    self.lines_color=lines_color
    
  def set_faces_color(self,faces_color) :
    ''' Change the faces color(s) from the sphere.
        Value of argument faces_color should be:
        faces_color  = An objet <type 'Color'> representing the faces color.
    '''                   
    
    if isinstance(faces_color,Color) :
      if type(faces_color.a) == bool :
	faces_color.a=0	  
    
    else :
      raise TypeError(Color)
    
    self.faces_color=faces_color
    
  def set_lines_width(self,lines_width) :
    ''' Change the lines width from the sphere.
        Value of argument lines_width should be:
        lines_width  = An integer representing the lines width.
    '''
    if not isinstance(lines_width,int) :
      raise TypeError("Argument lines_width",int)
    elif lines_width < 1 :
      raise ValueError(lines_width,"Lines width value too little.") 
    
    self.lines_width=lines_width
    
  def set_display_ls(self,display_ls) :
    ''' Change the Localview displaying setting.
        Value of argument display_ls should be an boolean value:
        display_ls   = Define if the localview should be display.
    '''    
        
    if isinstance(display_ls,bool) :
      self.display_ls=display_ls
    else :
      raise TypeError("Argument display_ls",bool)
    
  def set_basis(self,basis) :
    ''' Change the quad sphere basis. '''
    
    if not isinstance(basis,int) :
      raise TypeError(int)

    if basis < 6 or basis % 2 :
      print "the basis for the sphere must be greater as 5 and basis % 2 == 0 "
      quit()
    
    self.basis=basis
    self.polygons=generate_quad_sphere(basis,self.radius)[0]
    self.ls=Localview()
    
  def set_radius(self,radius) :
    ''' Change the quad sphere radius. '''
    
    if not isinstance(radius,int) and not isinstance(radius,float) :
      raise TypeError(int,float)
    elif radius < 0.0 :
      raise ValueError("Value of radius must be greater than 0.0") 
    
    self.radius=radius
    self.polygons=generate_quad_sphere(self.basis,radius)[0]
    self.ls=Localview()
    
  
  def __doc__(self) :
    ''' Print documentation '''
    
    print '''