def sphere2(nx, ny, r=1, bot=-90, top=90): """Return a sphere consisting of line elements. A sphere with radius r is modeled by a regular grid of nx longitude circles, ny latitude circles and their diagonals. The 3 sets of lines can be distinguished by their property number: 1: diagonals, 2: meridionals, 3: horizontals. The sphere caps can be cut off by specifying top and bottom latitude angles (measured in degrees from 0 at north pole to 180 at south pole. """ base = Formex('l:543', [1, 2, 3]) # single cell d = base.select([0]).replic2(nx, ny, 1, 1) # all diagonals m = base.select([1]).replic2(nx, ny, 1, 1) # all meridionals h = base.select([2]).replic2(nx, ny + 1, 1, 1) # all horizontals grid = m + d + h s = float(top - bot) / ny return grid.translate([0, bot / s, 1]).spherical(scale=[360. / nx, s, r])
def __init__(self,text,pos,gravity=None,size=18,width=None,font=None,lineskip=1.0,grid=None,texmode=4,**kargs): """Initialize the Text actor.""" # split the string on newlines text = str(text).split('\n') # set pos and offset3d depending on pos type (2D vs 3D rendering) pos = at.checkArray(pos) if pos.shape[-1] == 2: rendertype = 2 pos = [pos[0],pos[1],0.] offset3d = None else: rendertype = 1 offset3d = Coords(pos) pos = [0.,0.,0.] if offset3d.ndim > 1: if offset3d.shape[0] != len(text[0]): raise ValueError("Length of text(%s) and pos(%s) should match!" % (len(text),len(pos))) # Flag vertex offset to shader rendertype = -1 # set the font characteristics if font is None: font = FontTexture.default(size) if isinstance(font,(str,unicode)): font = FontTexture(font,size) if width is None: #print("Font %s / %s" % (font.height,font.width)) aspect = float(font.width) / font.height width = size * aspect self.width = width # set the alignment if gravity is None: gravity = 'E' alignment = ['0','0','0'] if 'W' in gravity: alignment[0] = '+' elif 'E' in gravity: alignment[0] = '-' if 'S' in gravity: alignment[1] = '+' elif 'N' in gravity: alignment[1] = '-' alignment = ''.join(alignment) # record the lengths of the lines, join all characters # together, create texture coordinates for all characters # create a geometry grid for the longest line lt = [ len(t) for t in text ] text = ''.join(text) texcoords = font.texCoords(text) if grid is None: grid = Formex('4:0123').replic(max(lt)) grid = grid.scale([width,size,0.]) # create the actor for the first line l = lt[0] g = grid.select(range(l)).align(alignment,pos) Actor.__init__(self,g,rendertype=rendertype,texture=font,texmode=texmode,texcoords=texcoords[:l],opak=False,ontop=True,offset3d=offset3d,**kargs) for k in lt[1:]: # lower the canvas y-value pos[1] -= font.height * lineskip g = grid.select(range(k)).align(alignment,pos) C = Actor(g,rendertype=rendertype,texture=font,texmode=texmode,texcoords=texcoords[l:l+k],opak=False,ontop=True,offset3d=offset3d,**kargs) self.children.append(C) # do next line l += k