コード例 #1
0
ファイル: textext.py プロジェクト: gitGNU/gnu_pyformex
    def __init__(self,val,pos,prefix='',**kargs):
        # Make sure we have strings
        val = [ str(i) for i in val ]
        pos = at.checkArray(pos,shape=(len(val),-1))
        if len(val) != pos.shape[0]:
            raise ValueError("val and pos should have same length")

        # concatenate all strings
        val = [ prefix+str(v) for v in val ]
        cs = at.cumsum([0,] + [ len(v) for v in val ])
        val = ''.join(val)
        nc = cs[1:] - cs[:-1]

        pos = [ at.multiplex(p,n,0) for p,n in zip(pos,nc) ]
        pos = np.concatenate(pos,axis=0)
        pos = at.multiplex(pos,4,1)

        # Create the grids for the strings
        F = Formex('4:0123')
        grid = Formex.concatenate([ F.replic(n) for n in nc ])

        # Create a text with the concatenation
        Text.__init__(self,val,pos=pos,grid=grid,**kargs)
コード例 #2
0
def Grid(nx=(1, 1, 1),
         ox=(0.0, 0.0, 0.0),
         dx=(1.0, 1.0, 1.0),
         lines='b',
         planes='b',
         linecolor=colors.black,
         planecolor=colors.white,
         alpha=0.3,
         **kargs):
    """Creates a (set of) grid(s) in (some of) the coordinate planes.

    Parameters:

    - `nx`: a list of 3 integers, specifying the number of divisions of the
      grid in the three coordinate directions. A zero value may be specified
      to avoid the grid to extend in that direction. Thus, setting the last
      value to zero will result in a planar grid in the xy-plane.
    - `ox`: a list of 3 floats: the origin of the grid.
    - `dx`: a list of 3 floats: the step size in each coordinate direction.
    - `planes`: one of 'first', 'box', 'all', 'no' (the string can be
      shortened to the first chartacter): specifies how many planes are
      drawn in each direction: 'f' only draws the first, 'b' draws the first
      and the last, resulting in a box, 'a' draws all planes,
      'n' draws no planes.

    Returns a list with up to two Meshes: the planes, and the lines.

    """
    from pyformex import simple
    from pyformex.olist import List
    from pyformex.mesh import Mesh
    G = List()

    planes = planes[:1].lower()
    P = []
    L = []
    for i in range(3):
        n0, n1, n2 = np.roll(nx, i)
        d0, d1, d2 = np.roll(dx, i)
        if n0 * n1:
            if planes != 'n':
                M = simple.rectangle(b=n0 * d0, h=n1 * d1)
                if n2:
                    if planes == 'b':
                        M = M.replic(2, dir=2, step=n2 * d2)
                    elif planes == 'a':
                        M = M.replic(n2 + 1, dir=2, step=d2)
                P.append(M.rollAxes(-i).toMesh())
            if lines != 'n':
                M = Formex('1').scale(n0*d0).replic(n1+1,dir=1,step=d1) + \
                    Formex('2').scale(n1*d1).replic(n0+1,dir=0,step=d0)
                if n2:
                    if lines == 'b':
                        M = M.replic(2, dir=2, step=n2 * d2)
                    elif lines == 'a':
                        M = M.replic(n2 + 1, dir=2, step=d2)

                L.append(M.rollAxes(-i).toMesh())

    if P:
        M = Mesh.concatenate(P)
        M.attrib(name='__grid_planes__',
                 mode='flat',
                 lighting=False,
                 color=planecolor,
                 alpha=alpha,
                 **kargs)
        G.append(M)
    if L:
        M = Mesh.concatenate(L)
        M.attrib(name='__grid_lines__',
                 mode='flat',
                 lighting=False,
                 color=linecolor,
                 alpha=0.6,
                 **kargs)
        G.append(M)

    return G.trl(ox)