Пример #1
0
def spin3 (nframes = 30, axis = array ([-1, 1, 0],  Float), tlimit = 60.,
   dtmin = 0.0, bracket_time = array ([2., 2.],  Float), lims = None,
   timing = 0, angle = 2. * pi) :

    """
    spin3 ( ) or spin3 (nframes) os spin3 (nframes, axis)
      Spin the current 3D display list about AXIS over NFRAMES.  Keywords
      tlimit= the total time allowed for the movie in seconds (default 60),
      dtmin= the minimum allowed interframe time in seconds (default 0.0),
      bracket_time= (as for movie function in movie.i), timing = 1 if
      you want timing measured and printed out, 0 if not.

      The default AXIS is [-1,1,0] and the default NFRAMES is 30.
    SEE ALSO: rot3
    """

    # Note on global variables (ZCM 2/21/97):
    # I see no better way of sharing these between spin3 and _spin3
    #   than making them global. Otherwise one would have to pass
    #   them to movie, which would then send them as arguments to
    #   _spin3. But because movie may call other routines, every one
    #   of them would have to have these values, necessary or not.
    #   So I have started their names with underscores; at least
    #   this makes them inaccessible outside this module.
    global _phi, _theta, _dtheta
    global _g_nframes
    _g_nframes = nframes
    _dtheta = angle / (nframes - 1)
    _theta = arccos (axis [2] / sqrt (axis [0] * axis [0] + axis [1] * axis [1] +
                    axis [2] * axis [2]))
    inc = axis [0] == axis [1] == 0
    _phi = arctan2 (axis [1], axis [0] + inc)
    orig = save3 ( )
    movie (_spin3, tlimit, dtmin, bracket_time, lims, timing = 0)
    restore3 (orig)
Пример #2
0
def spin3(nframes=30,
          axis=array([-1, 1, 0], float32),
          tlimit=60.,
          dtmin=0.0,
          bracket_time=array([2., 2.], float32),
          lims=None,
          timing=0,
          angle=2. * pi):
    """
    spin3 ( ) or spin3 (nframes) os spin3 (nframes, axis)
      Spin the current 3D display list about AXIS over NFRAMES.  Keywords
      tlimit= the total time allowed for the movie in seconds (default 60),
      dtmin= the minimum allowed interframe time in seconds (default 0.0),
      bracket_time= (as for movie function in movie.i), timing = 1 if
      you want timing measured and printed out, 0 if not.

      The default AXIS is [-1,1,0] and the default NFRAMES is 30.
    SEE ALSO: rot3
    """

    # Note on global variables (ZCM 2/21/97):
    # I see no better way of sharing these between spin3 and _spin3
    #   than making them global. Otherwise one would have to pass
    #   them to movie, which would then send them as arguments to
    #   _spin3. But because movie may call other routines, every one
    #   of them would have to have these values, necessary or not.
    #   So I have started their names with underscores; at least
    #   this makes them inaccessible outside this module.
    global _phi, _theta, _dtheta
    global _g_nframes
    _g_nframes = nframes
    _dtheta = angle / (nframes - 1)
    _theta = arccos(
        axis[2] /
        sqrt(axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2]))
    inc = axis[0] == axis[1] == 0
    _phi = arctan2(axis[1], axis[0] + inc)
    orig = save3()
    movie(_spin3, tlimit, dtmin, bracket_time, lims, timing=0)
    restore3(orig)
Пример #3
0
def run (*itest) :
    """run() or run(i)
      Run examples of use of pl3d.i, plwf.i, and slice3.i.  With
      argument I = 1, 2, or 3, run that particular demonstration.
      Read the source code to understand the details of how the
      various effects are obtained.

      run (1) demonstrates the various effects which can be obtained
      with the plwf (plot wire frame) function.
      run (2) demonstrates shading effects controlled by the light3
      function
      run (3) demonstrates the slice3, slice2, and pl3tree functions,
      as well as changing the orientation of the 3D object
    """
    global making_movie

    if len (itest) == 0 or itest [0] == 1 :
        set_draw3_ (0)
        x = span (-1, 1, 64, 64)
        y = transpose (x)
        z = (x + y) * exp (-6.*(x*x+y*y))
        limits_(square = 1)
        print "Plot wire frame: plwf (z, y, x)"
        orient3 ( )
        light3 ( )
        plwf (z, y, x)
        [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively
        limits (xmin, xmax, ymin, ymax)
        plt("opaque wire mesh", .30, .42)
        paws ( )

        print 'plwf(z,y,x,shade=1,ecolor="red")'
        plwf(z,y,x,shade=1,ecolor="red")
        [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively
        limits (xmin, xmax, ymin, ymax)
        paws()

        print "plwf(z,y,x,shade=1,edges=0)"
        plwf(z,y,x,shade=1,edges=0)
        [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively
        limits (xmin, xmax, ymin, ymax)
        paws ( )

        print "light3 ( diffuse=.1, specular=1., sdir=array([0,0,-1]))"
        light3 ( diffuse=.1, specular=1., sdir=array([0,0,-1]))
        [xmin, xmax, ymin, ymax] = draw3(1)
        limits (xmin, xmax, ymin, ymax)
        paws ( )

        print "light3 ( diffuse=.5, specular=1., sdir=array([1,.5,1]))"
        light3 ( diffuse=.5, specular=1., sdir=array([1,.5,1]))
        [xmin, xmax, ymin, ymax] = draw3 (1)
        limits (xmin, xmax, ymin, ymax)
        paws ( )

        print "light3 ( ambient=.1,diffuse=.1,specular=1.,"
        print "   sdir=array([[0,0,-1],[1,.5,1]]),spower=array([4,2]))"
        light3 ( ambient=.1,diffuse=.1,specular=1.,
               sdir=array([[0,0,-1],[1,.5,1]]),spower=array([4,2]))
        [xmin, xmax, ymin, ymax] = draw3(1)
        limits (xmin, xmax, ymin, ymax)
        paws ( )

    if len (itest) == 0 or itest [0] == 2 :

        set_draw3_ (0)
        x = span (-1, 1, 64, 64)
        y = transpose (x)
        z = (x + y) * exp (-6.*(x*x+y*y))
        print "Default lighting:  light3()"
        orient3 ( )
        light3 ( )
        plwf (z,y,x,shade=1,edges=0)
        [xmin, xmax, ymin, ymax] = draw3 (1) # not necessary interactively
        limits (xmin, xmax, ymin, ymax)
        paws( )

        print "light3(diffuse=.2,specular=1)"
        light3(diffuse=.2,specular=1)
        limits_(square = 1)
        [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively
        limits (xmin, xmax, ymin, ymax)
        paws()

        print "movie(demo5_light, lims = [xmin, xmax, ymin, ymax])"
        print "demo5_light calls:"
        print "light3 (sdir = array ( [cos(theta), .25, sin(theta)], Float))"
        making_movie = 1
        movie(demo5_light, lims = [xmin, xmax, ymin, ymax])
        making_movie = 0
        fma()
        demo5_light(1)
        paws()
        light3()

    if len (itest) == 0 or itest [0] == 3 :

        nx = demo5_n [0]
        ny = demo5_n [1]
        nz = demo5_n [2]
        xyz = zeros ( (3, nx, ny, nz), Float)
        xyz [0] = multiply.outer ( span (-1, 1, nx), ones ( (ny, nz), Float))
        xyz [1] = multiply.outer ( ones (nx, Float),
           multiply.outer ( span (-1, 1, ny), ones (nz, Float)))
        xyz [2] = multiply.outer ( ones ( (nx, ny), Float), span (-1, 1, nz))
        r = sqrt (xyz [0] ** 2 + xyz [1] **2 + xyz [2] **2)
        theta = arccos (xyz [2] / r)
        phi = arctan2 (xyz [1] , xyz [0] + logical_not (r))
        y32 = sin (theta) ** 2 * cos (theta) * cos (2 * phi)
        m3 = mesh3 (xyz, funcs = [r * (1. + y32)])
        del r, theta, phi, xyz, y32

        print "   test uses " + `(nx - 1) * (ny - 1) * (nz - 1)` + " cells"
        elapsed = [0., 0., 0.]
        elapsed = timer_ (elapsed)
        elapsed0 = elapsed

        [nv, xyzv, dum] = slice3 (m3, 1, None, None, value = .50)
            # (inner isosurface)
        [nw, xyzw, dum] = slice3 (m3, 1, None, None, value = 1.)
            # (outer isosurface)
        pxy = plane3 ( array ([0, 0, 1], Float ), zeros (3, Float))
        pyz = plane3 ( array ([1, 0, 0], Float ), zeros (3, Float))
        [np, xyzp, vp] = slice3 (m3, pyz, None, None, 1)
            # (pseudo-colored slice)
        [np, xyzp, vp] = slice2 (pxy, np, xyzp, vp)
            # (cut slice in half)
        [nv, xyzv, d1, nvb, xyzvb, d2] = \
            slice2x (pxy, nv, xyzv, None)
        [nv, xyzv, d1] = \
            slice2 (- pyz, nv, xyzv, None)
            # (...halve one of those halves)
        [nw, xyzw, d1, nwb, xyzwb, d2] = \
            slice2x ( pxy , nw, xyzw, None)
            # (split outer in halves)
        [nw, xyzw, d1] = \
            slice2 (- pyz, nw, xyzw, None)

        elapsed = timer_ (elapsed)
        timer_print ("slicing time", elapsed - elapsed0)

        fma ()
        print 'Generate palette for pl3tree:  split_palette ("earth.gp")'
        split_palette ("earth.gp")
        print "gnomon -- turn on gnomon"
        gnomon (1)

        print "pl3tree with 1 slicing plane, 2 isosurfaces"
        clear3 ()
        # Make sure we don't draw till ready
        set_draw3_ (0)
        pl3tree (np, xyzp, vp, pyz)
        pl3tree (nvb, xyzvb)
        pl3tree (nwb, xyzwb)
        pl3tree (nv, xyzv)
        pl3tree (nw, xyzw)
        orient3 ()
        light3 (diffuse = .2, specular = 1)
        limits ()
        limits (square=1)
        demo5_light (1)
        paws ()
        hcp ()

        print "spin3 animated rotation, use rot3 or orient3 for one frame"
        # don't want limits to autoscale during animation
        lims = limits ( )
        spin3 ()
        limits ( ) # back to autoscaling
        demo5_light (1)
        paws ()

        light3 ()
        gnomon (0)
        limits (square = 1)
        palette ("gray.gp")

#  .. PR is not available.  Comment out this section.
#   if len (itest) == 0 or itest [0] == 4 :
#      from PR import *
#      f = PR ('./bills_plot')
#      n_nodes = f.NumNodes
#      n_z = f.NodesOnZones
#      x = f.XNodeCoords
#      y = f.YNodeCoords
#      z = f.ZNodeCoords
#      c = f.ZNodeVelocity
#      n_zones = f.NumZones
#      # Put vertices in right order for Gist
#      n_z = transpose (
#         take (transpose (n_z), array ( [0, 4, 3, 7, 1, 5, 2, 6]),axis=0))
#      m3 = mesh3 (x, y, z, funcs = [c], verts = n_z ) # [0:10])
#      [nv, xyzv, cv] = slice3 (m3, 1, None, None, 1, value = .9 * max (c) )
#      pyz = plane3 ( array ([1, 0, 0], Float ), zeros (3, Float))
#      pxz = plane3 ( array ([0, 1, 0], Float ), zeros (3, Float))
#
#      # draw a colored plane first
#      fma ()
#      clear3 ()
#      # Make sure we don't draw till ready
#      set_draw3_ (0)
#      [np, xyzp, vp] = slice3 (m3, pyz, None, None, 1)
#      pl3tree (np, xyzp, vp, pyz, split = 0)
#      palette ("rainbow.gp")
#      orient3 ()
#      demo5_light (1)
#      paws ()
#
#
#     [nv, xyzv, d1] = \
#         slice2 (- pyz, nv, xyzv, None)
#      [nw, xyzw, cw] = slice3 (m3, 1, None, None, 1, value = .9 * min (c) )
#     [nw, xyzw, d1] = \
#         slice2 (- pyz, nw, xyzw, None)
#      [nvi, xyzvi, cvi] = slice3 (m3, 1, None, None, 1, value = .5 * min (c) )
#      [nvi, xyzvi, cvi] = \
#          slice2 (- pyz, nvi, xyzvi, cvi)
#      [nvj, xyzvj, cvj] = slice3 (m3, 1, None, None, 1, value = .5 * max (c) )
#      [nvj, xyzvj, cvj] = \
#          slice2 (- pyz, nvj, xyzvj, cvj)
#
#      fma ()
#      print "gnomon -- turn on gnomon"
#      gnomon (1)
#      clear3 ()
#      # Make sure we don't draw till ready
#      set_draw3_ (0)
#      pl3tree (nv, xyzv) # , cv)
#      pl3tree (nw, xyzw) # , cw)
#      pl3tree (nvi, xyzvi) # , cvi)
#      pl3tree (nvj, xyzvj) # , cvi)
#      orient3 ()
#      light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1])
#      limits (square=1)
#      palette ("gray.gp")
#      demo5_light (1)
#      paws ()
#
#      print "spin3 animated rotation, use rot3 or orient3 for one frame"
#      # don't want limits to autoscale during animation
#      spin3 ()
#      limits ( ) # back to autoscaling
#      demo5_light (1)
#      paws ()
#
#      light3 ()
#      gnomon (0)
#      palette ("gray.gp")
#
#      draw3 ( 1 )
#      paws ()
#      clear3 ()
#      del nv, xyzv, cv, nw, xyzw, cw, nvi, xyzvi, cvi, nvj, xyzvj, cvj
#      # Make sure we don't draw till ready
#      set_draw3_ (0)
#      for i in range (8) :
#         [nv, xyzv, cv] = slice3 (m3, 1, None, None, 1, value = .9 * min (c) +
#             i * (.9 * max (c) - .9 * min (c)) / 8.)
#         [nv, xyzv, d1] = \
#             slice2 (pxz, nv, xyzv, None)
#         pl3tree (nv, xyzv)
#      orient3 ()
#      light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1])
#      limits (square=1)
#      palette ("heat.gp")
#      demo5_light (1)
#      paws ()
#      spin3 ()
#      limits ( ) # back to autoscaling
#      demo5_light (1)
#      paws ()
#      demo5_light (1)
#      paws ()
#
#   if len (itest) == 0 or itest [0] == 5 :
#      # Try bert's data
#      from PR import PR
#      f = PR ('./berts_plot')
#      nums = array ( [63, 63, 49], Int)
#      dxs = array ( [2.5, 2.5, 10.], Float )
#      x0s = array ( [-80., -80., 0.0], Float )
#      c = f.c
#
#      m3 = mesh3 (nums, dxs, x0s, funcs = [transpose (c)])
#      [nv, xyzv, dum] = slice3 (m3, 1, None, None, value = 6.5)
#      fma ()
#      clear3 ()
#      print "gnomon -- turn on gnomon"
#      gnomon (1)
#      # Make sure we don't draw till ready
#      set_draw3_ (0)
#      palette ("rainbow.gp")
#      pl3tree (nv, xyzv)
#      orient3 ()
#      light3 (diffuse = .2, specular = 1)
#      limits (square=1)
#      demo5_light (1)
#      paws ()
#      spin3 ()
#      demo5_light (1)
#      paws ()
#   if len (itest) == 0 or itest [0] == 6 :
#      # Try Bill's irregular mesh
#      from PR import PR
#      f = PR ("ball.s0001")
#      ZLss = f.ZLstruct_shapesize
#      ZLsc = f.ZLstruct_shapecnt
#      ZLsn = f.ZLstruct_nodelist
#      x = f.sap_mesh_coord0
#      y = f.sap_mesh_coord1
#      z = f.sap_mesh_coord2
#      c = f.W_vel_data
#      # Now we need to convert this information to avs-style data
#      istart = 0 # beginning index into ZLstruct_nodelist
#      NodeError = "NodeError"
#      ntet = 0
#      nhex = 0
#      npyr = 0
#      nprism = 0
#      nz_tet = []
#      nz_hex = []
#      nz_pyr = []
#      nz_prism = []
#      for i in range (4) :
#         if ZLss [i] == 4 : # TETRAHEDRON
#            nz_tet = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]],
#                     (ZLsc [i], ZLss [i]))
#            ntet = ZLsc [i]
#            istart = istart + ZLss [i] * ZLsc [i]
#         elif ZLss[i] == 5 : # PYRAMID
#            nz_pyr = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]],
#                     (ZLsc [i], ZLss [i]))
#            npyr = ZLsc [i]
#            # Now reorder the points (bill has the apex last instead of first)
#            nz_pyr = transpose (
#               take (transpose (nz_pyr), array ( [4, 0, 1, 2, 3]),axis=0))
#            istart = istart + ZLss [i] * ZLsc [i]
#         elif ZLss[i] == 6 : # PRISM
#            nz_prism = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]],
#                     (ZLsc [i], ZLss [i]))
#            nprism = ZLsc [i]
#            # now reorder the points (bill goes around a square face
#            # instead of traversing the opposite sides in the same direction.
#            nz_prism = transpose (
#               take (transpose (nz_prism), array ( [0, 1, 3, 2, 4, 5]),axis=0))
#            istart = istart + ZLss [i] * ZLsc [i]
#         elif ZLss[i] == 8 : # HEXAHEDRON
#            nz_hex = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]],
#                     (ZLsc [i], ZLss [i]))
#            # now reorder the points (bill goes around a square face
#            # instead of traversing the opposite sides in the same direction.
#            nz_hex = transpose (
#               take (transpose (nz_hex), array ( [0, 1, 3, 2, 4, 5, 7, 6]),axis=0))
#            nhex = ZLsc [i]
#            istart = istart + ZLss [i] * ZLsc [i]
#         else :
#            raise NodeError, `ZLss[i]` + "is an incorrect number of nodes."

#      m3 = mesh3 (x, y, z, funcs = [c], verts = [nz_tet, nz_pyr, nz_prism,
#         nz_hex])
#      [nv, xyzv, cv] = slice3 (m3, 1, None, None, 1, value = .9 * max (c) )
#      pyz = plane3 ( array ([1, 0, 0], Float ), zeros (3, Float))
#      pxz = plane3 ( array ([0, 1, 0], Float ), zeros (3, Float))
#
#      # draw a colored plane first
#      fma ()
#      clear3 ()
#      # Make sure we don't draw till ready
#      set_draw3_ (0)
#      [np, xyzp, vp] = slice3 (m3, pyz, None, None, 1)
#      pl3tree (np, xyzp, vp, pyz, split = 0)
#      palette ("rainbow.gp")
#      orient3 ()
#      limits (square=1)
#      demo5_light (1)
#      paws ()
#
#      [nw, xyzw, cw] = slice3 (m3, 1, None, None, 1, value = .9 * min (c) )
#      [nvi, xyzvi, cvi] = slice3 (m3, 1, None, None, 1, value = .1 * min (c) )
#      [nvi, xyzvi, cvi] = \
#          slice2 (- pyz, nvi, xyzvi, cvi)
#      [nvj, xyzvj, cvj] = slice3 (m3, 1, None, None, 1, value = .1 * max (c) )
#      [nvj, xyzvj, cvj] = \
#          slice2 (- pyz, nvj, xyzvj, cvj)
#      [nvii, xyzvii, cvii] = slice3 (m3, 1, None, None, 1,
#         value = 1.e-12 * min (c) )
#      [nvii, xyzvii, cvii] = \
#          slice2 (- pyz, nvii, xyzvii, cvii)
#      [nvjj, xyzvjj, cvjj] = slice3 (m3, 1, None, None, 1,
#         value = 1.e-12 * max (c) )
#      [nvjj, xyzvjj, cvjj] = \
#          slice2 (- pyz, nvjj, xyzvjj, cvjj)
#
#      fma ()
#      print "gnomon -- turn on gnomon"
#      gnomon (1)
#      clear3 ()
#      # Make sure we don't draw till ready
#      set_draw3_ (0)
#      pl3tree (nv, xyzv) # , cv)
#      pl3tree (nw, xyzw) # , cw)
#      pl3tree (nvi, xyzvi) # , cvi)
#      pl3tree (nvj, xyzvj) # , cvj)
#      pl3tree (nvii, xyzvii) # , cvii)
#      pl3tree (nvjj, xyzvjj) # , cvjj)
#      orient3 ()
#      light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1])
#      limits (square=1)
#      palette ("gray.gp")
#      demo5_light (1)
#      paws ()
#      palette ("heat.gp")
#      paws ()

    if len (itest) == 0 or itest [0] == 7 :

        print "Test plwf on the sombrero function"
        # compute sombrero function
        x = arange (-20, 21, dtype = Float)
        y = arange (-20, 21, dtype = Float)
        z = zeros ( (41, 41), Float)
        r = sqrt (add.outer ( x ** 2, y **2)) + 1e-6
        z = sin (r) / r
        fma ()
        clear3 ()
        gnomon (0)
        # Make sure we don't draw till ready
        set_draw3_ (0)
        palette ("rainbow.gp")
        limits (square=1)
        orient3 ()
        light3 ()
        plwf (z, fill = z, ecolor = "black")
        [xmin, xmax, ymin, ymax] = draw3 (1)
        limits (xmin, xmax, ymin, ymax)
        paws ()

        print "Try smooth contours, log mode:"
        print 'plzcont (nv, xyzv, contours = 20, scale = "normal")'
        [nv, xyzv, dum] = slice3mesh (x, y, z)
        zmult = max (max (abs (x)), max (abs (y)))
        plzcont (nv, xyzv, contours = 20, scale = "normal")
        [xmin, xmax, ymin, ymax] = draw3 (1)
        limits (xmin, xmax, ymin, ymax)
        paws ()

        print 'plzcont (nv, xyzv, contours = 20, scale = "lin", edges=1)'
        plzcont (nv, xyzv, contours = 20, scale = "lin", edges=1)
        [xmin, xmax, ymin, ymax] = draw3 (1)
        limits (xmin, xmax, ymin, ymax)
        paws ()

        print 'plwf (z, fill = z, shade = 1, ecolor = "black")'
        plwf (z, fill = z, shade = 1, ecolor = "black")
        [xmin, xmax, ymin, ymax] = draw3 (1)
        limits (xmin, xmax, ymin, ymax)
        paws ()

        print "plwf (z, fill = z, shade = 1, edges = 0)"
        plwf (z, fill = z, shade = 1, edges = 0)
        [xmin, xmax, ymin, ymax] = draw3 (1)
        limits (xmin, xmax, ymin, ymax)
        paws ()

        print "light3(diffuse=.2,specular=1)"
        print "demo5_light calls:"
        print "light3 (sdir = array ( [cos(theta), .25, sin(theta)], Float))"
        light3(diffuse=.2,specular=1)
        making_movie = 1
        movie(demo5_light, lims = [xmin, xmax, ymin, ymax])
        making_movie = 0
        fma()
        demo5_light(1)
        paws ()

        print "plwf (z, fill = None, shade = 1, edges = 0)"
        plwf (z, fill = None, shade = 1, edges = 0)
        [xmin, xmax, ymin, ymax] = draw3 (1)
        palette("gray.gp")
        limits (xmin, xmax, ymin, ymax)
        paws ()


    if len (itest) == 0 or itest [0] == 8 :

        print "Test pl3surf on the sombrero function"
        # compute sombrero function
        nc1 = 100
        nv1 = nc1 + 1
        br = - (nc1 / 2)
        tr = nc1 / 2 + 1
        x = arange (br, tr, dtype = Float) * 40. / nc1
        y = arange (br, tr, dtype = Float) * 40. / nc1
        z = zeros ( (nv1, nv1), Float)
        r = sqrt (add.outer ( x ** 2, y **2)) + 1e-6
        z = sin (r) / r
        # In order to use pl3surf, we need to construct a mesh
        # using mesh3. The way I am going to do that is to define
        # a function on the 3d mesh so that the sombrero function
        # is its 0-isosurface.
        z0 = min (ravel (z))
        z0 = z0 - .05 * abs (z0)
        maxz = max (ravel (z))
        maxz = maxz + .05 * abs (maxz)
        zmult = max (max (abs (x)), max (abs (y)))
        dz = (maxz - z0)
        nxnynz = array ( [nc1, nc1, 1], Int)
        dxdydz = array ( [1.0, 1.0, zmult*dz], Float )
        x0y0z0 = array ( [float (br), float (br), z0*zmult], Float )
        meshf = zeros ( (nv1, nv1, 2), Float )
        meshf [:, :, 0] = zmult*z - (x0y0z0 [2])
        meshf [:, :, 1] = zmult*z - (x0y0z0 [2] + dxdydz [2])

        m3 = mesh3 (nxnynz, dxdydz, x0y0z0, funcs = [meshf])
        fma ()
        # Make sure we don't draw till ready
        set_draw3_ (0)
        pldefault(edges=0)
        [nv, xyzv, col] = slice3 (m3, 1, None, None, value = 0.)
        orient3 ()
        pl3surf (nv, xyzv)
        lim = draw3 (1)
        limits (lim [0], lim [1], 1.5*lim [2], 1.5*lim [3])
        palette ("gray.gp")
        paws ()

        print "Try new slicing function (slice3mesh) to get color graph"
        [nv, xyzv, col] = slice3mesh (nxnynz [0:2], dxdydz [0:2], x0y0z0 [0:2],
           zmult * z, color = zmult * z)
        pl3surf (nv, xyzv, values = col)
        lim = draw3 (1)
        dif = 0.5 * (lim [3] - lim [2])
        limits (lim [0], lim [1], lim [2] - dif, lim [3] + dif)

        palette ("rainbow.gp")
        paws ()

        print "Try plzcont -- see if smooth mode is possible"
        print "plzcont (nv, xyzv)"
        palette ("heat.gp")
        plzcont (nv, xyzv)
        draw3 (1)
        paws ()

        print "plzcont (nv, xyzv, contours = 20)"
        plzcont (nv, xyzv, contours = 20)
        draw3 (1)
        paws ()

        print 'plzcont (nv, xyzv, contours = 20, scale = "log")'
        plzcont (nv, xyzv, contours = 20, scale = "log")
        draw3(1)
        paws ()

        print 'plzcont (nv, xyzv, contours = 20, scale = "normal")'
        plzcont (nv, xyzv, contours = 20, scale = "normal")
        draw3(1)
        paws ()

    if len (itest) == 0 or itest [0] == 9 :

        vsf = 0.
        c = 1
        s = 1000.
        kmax = 25
        lmax = 35

        # The following computations define an interesting 3d surface.

        xr = multiply.outer (
           arange (1, kmax + 1, dtype = Float), ones (lmax, Float))
        yr = multiply.outer (
           ones (kmax, Float), arange (1, lmax + 1, dtype = Float))
        zt = 5. + xr + .2 * random_sample (kmax, lmax)   # ranf (xr)
        rt = 100. + yr + .2 * random_sample (kmax, lmax)   # ranf (yr)
        z = s * (rt + zt)
        z = z + .02 * z * random_sample (kmax, lmax)   # ranf (z)
        ut = rt/sqrt (rt ** 2 + zt ** 2)
        vt = zt/sqrt (rt ** 2 + zt ** 2)
        ireg =  multiply.outer ( ones (kmax, Float), ones (lmax, Float))
        ireg [0:1, 0:lmax]=0
        ireg [0:kmax, 0:1]=0
        ireg [1:15, 7:12]=2
        ireg [1:15, 12:lmax]=3
        ireg [3:7, 3:7]=0
        freg=ireg + .2 * (1. - random_sample (kmax, lmax))  # ranf (ireg))
        freg=array (freg, Float)
        #rt [4:6, 4:6] = -1.e8
        z [3:10, 3:12] = z [3:10, 3:12] * .9
        z [5, 5] = z [5, 5] * .9
        z [17:22, 15:18] = z [17:22, 15:18] * 1.2
        z [16, 16] = z [16, 16] * 1.1
        orient3 ()
        print "plwf (freg, shade = 1, edges = 0)"
        plwf (freg, shade = 1, edges = 0)
        [xmin, xmax, ymin, ymax] = draw3 (1)
        limits (xmin, xmax, ymin, ymax)
        paws ()

        print "two slice3mesh and two pl3tree"
        nxny = array ( [kmax - 1, lmax - 1])
        x0y0 = array ( [0., 0.])
        dxdy = array ( [1., 1.])
        [nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, freg)
        [nw, xyzw, col] = slice3mesh (nxny, dxdy, x0y0, freg + ut)
        pl3tree (nv, xyzv)
        pl3tree (nw, xyzw)
        draw3 (1)
        limits ( )
        paws ()

        print "light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1])"
        light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1])
        demo5_light (1)
        paws ()

        print "[nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, freg, color = freg)"
        [nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, freg, color = freg)
        pl3surf (nv, xyzv, values = col)
        draw3 (1)
        palette ("rainbow.gp")
        paws ()

        print 'palette ("rainbow.gp")'
        [nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, freg, color = z)
        pl3surf (nv, xyzv, values = col)
        draw3 (1)
        paws ()

        print 'palette ("stern.gp")'
        palette ("stern.gp")
        paws ()

        print "[nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, z, color = z)"
        [nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, z, color = z)
        pl3surf (nv, xyzv, values = col)
        orient3(phi=0,theta=0)
        draw3 (1)
        paws ()

        print 'palette ("gray.gp")'
        print "light3 ( diffuse=.1, specular=1., sdir=array([0,0,-1]))"
        set_draw3_ (0)
        palette ("gray.gp")
        light3 ( diffuse=.1, specular=1., sdir=array([0,0,-1]))
        pl3surf (nv, xyzv)
        draw3 (1)
        paws ()

#     spin3 ()
#     paws ()

    hcp_finish ()
Пример #4
0
def run(*itest):
    """run() or run(i)
     Run examples of use of pl3d.i, plwf.i, and slice3.i.  With
     argument I = 1, 2, or 3, run that particular demonstration.
     Read the source code to understand the details of how the
     various effects are obtained.

     run (1) demonstrates the various effects which can be obtained
     with the plwf (plot wire frame) function.
     run (2) demonstrates shading effects controlled by the light3
     function
     run (3) demonstrates the slice3, slice2, and pl3tree functions,
     as well as changing the orientation of the 3D object
   """
    global making_movie

    if len(itest) == 0 or itest[0] == 1:
        set_draw3_(0)
        x = gistfuncs.span(-1, 1, 64, 64)
        y = transpose(x)
        z = (x + y) * exp(-6. * (x * x + y * y))
        limits_(square=1)
        print "Plot wire frame: plwf (z, y, x)"
        orient3()
        light3()
        plwf(z, y, x)
        [xmin, xmax, ymin, ymax] = draw3(1)  # not necessary interactively
        limits(xmin, xmax, ymin, ymax)
        plt("opaque wire mesh", .30, .42)
        paws()

        print 'plwf(z,y,x,shade=1,ecolor="red")'
        plwf(z, y, x, shade=1, ecolor="red")
        [xmin, xmax, ymin, ymax] = draw3(1)  # not necessary interactively
        limits(xmin, xmax, ymin, ymax)
        paws()

        print "plwf(z,y,x,shade=1,edges=0)"
        plwf(z, y, x, shade=1, edges=0)
        [xmin, xmax, ymin, ymax] = draw3(1)  # not necessary interactively
        limits(xmin, xmax, ymin, ymax)
        paws()

        print "light3 ( diffuse=.1, specular=1., sdir=array([0,0,-1]))"
        light3(diffuse=.1, specular=1., sdir=array([0, 0, -1]))
        [xmin, xmax, ymin, ymax] = draw3(1)
        limits(xmin, xmax, ymin, ymax)
        paws()

        print "light3 ( diffuse=.5, specular=1., sdir=array([1,.5,1]))"
        light3(diffuse=.5, specular=1., sdir=array([1, .5, 1]))
        [xmin, xmax, ymin, ymax] = draw3(1)
        limits(xmin, xmax, ymin, ymax)
        paws()

        print "light3 ( ambient=.1,diffuse=.1,specular=1.,"
        print "   sdir=array([[0,0,-1],[1,.5,1]]),spower=array([4,2]))"
        light3(ambient=.1,
               diffuse=.1,
               specular=1.,
               sdir=array([[0, 0, -1], [1, .5, 1]]),
               spower=array([4, 2]))
        [xmin, xmax, ymin, ymax] = draw3(1)
        limits(xmin, xmax, ymin, ymax)
        paws()

    if len(itest) == 0 or itest[0] == 2:

        set_draw3_(0)
        x = gistfuncs.span(-1, 1, 64, 64)
        y = transpose(x)
        z = (x + y) * exp(-6. * (x * x + y * y))
        print "Default lighting:  light3()"
        orient3()
        light3()
        plwf(z, y, x, shade=1, edges=0)
        [xmin, xmax, ymin, ymax] = draw3(1)  # not necessary interactively
        limits(xmin, xmax, ymin, ymax)
        paws()

        print "light3(diffuse=.2,specular=1)"
        light3(diffuse=.2, specular=1)
        limits_(square=1)
        [xmin, xmax, ymin, ymax] = draw3(1)  # not necessary interactively
        limits(xmin, xmax, ymin, ymax)
        paws()

        print "movie(demo5_light, lims = [xmin, xmax, ymin, ymax])"
        print "demo5_light calls:"
        print "light3 (sdir = array ( [cos(theta), .25, sin(theta)], float32))"
        making_movie = 1
        movie(demo5_light, lims=[xmin, xmax, ymin, ymax])
        making_movie = 0
        fma()
        demo5_light(1)
        paws()
        light3()

    if len(itest) == 0 or itest[0] == 3:

        nx = demo5_n[0]
        ny = demo5_n[1]
        nz = demo5_n[2]
        xyz = zeros((3, nx, ny, nz), float32)
        xyz[0] = multiply.outer(gistfuncs.span(-1, 1, nx),
                                ones((ny, nz), float32))
        xyz[1] = multiply.outer(
            ones(nx, float32),
            multiply.outer(gistfuncs.span(-1, 1, ny), ones(nz, float32)))
        xyz[2] = multiply.outer(ones((nx, ny), float32),
                                gistfuncs.span(-1, 1, nz))
        r = sqrt(xyz[0]**2 + xyz[1]**2 + xyz[2]**2)
        theta = arccos(xyz[2] / r)
        phi = arctan2(xyz[1], xyz[0] + logical_not(r))
        y32 = sin(theta)**2 * cos(theta) * cos(2 * phi)
        m3 = mesh3(xyz, funcs=[r * (1. + y32)])
        del r, theta, phi, xyz, y32

        print "   test uses " + ` (nx - 1) * (ny - 1) * (nz - 1) ` + " cells"
        elapsed = [0., 0., 0.]
        elapsed = timer_(elapsed)
        elapsed0 = elapsed

        [nv, xyzv, dum] = slice3(m3, 1, None, None, value=.50)
        # (inner isosurface)
        [nw, xyzw, dum] = slice3(m3, 1, None, None, value=1.)
        # (outer isosurface)
        pxy = plane3(array([0, 0, 1], float32), zeros(3, float32))
        pyz = plane3(array([1, 0, 0], float32), zeros(3, float32))
        [np, xyzp, vp] = slice3(m3, pyz, None, None, 1)
        # (pseudo-colored slice)
        [np, xyzp, vp] = slice2(pxy, np, xyzp, vp)
        # (cut slice in half)
        [nv, xyzv, d1, nvb, xyzvb, d2] = \
            slice2x (pxy, nv, xyzv, None)
        [nv, xyzv, d1] = \
            slice2 (- pyz, nv, xyzv, None)
        # (...halve one of those halves)
        [nw, xyzw, d1, nwb, xyzwb, d2] = \
            slice2x ( pxy , nw, xyzw, None)
        # (split outer in halves)
        [nw, xyzw, d1] = \
            slice2 (- pyz, nw, xyzw, None)

        elapsed = timer_(elapsed)
        timer_print("slicing time", elapsed - elapsed0)

        fma()
        print 'Generate palette for pl3tree:  split_palette ("earth.gp")'
        split_palette("earth.gp")
        print "gnomon -- turn on gnomon"
        gnomon(1)

        print "pl3tree with 1 slicing plane, 2 isosurfaces"
        clear3()
        # Make sure we don't draw till ready
        set_draw3_(0)
        pl3tree(np, xyzp, vp, pyz)
        pl3tree(nvb, xyzvb)
        pl3tree(nwb, xyzwb)
        pl3tree(nv, xyzv)
        pl3tree(nw, xyzw)
        orient3()
        light3(diffuse=.2, specular=1)
        limits()
        limits(square=1)
        demo5_light(1)
        paws()
        hcp()

        print "spin3 animated rotation, use rot3 or orient3 for one frame"
        # don't want limits to autoscale during animation
        lims = limits()
        spin3()
        limits()  # back to autoscaling
        demo5_light(1)
        paws()

        light3()
        gnomon(0)
        limits(square=1)
        palette("gray.gp")

#  .. PR is not available.  Comment out this section.
#   if len (itest) == 0 or itest [0] == 4 :
#      from PR import *
#      f = PR ('./bills_plot')
#      n_nodes = f.NumNodes
#      n_z = f.NodesOnZones
#      x = f.XNodeCoords
#      y = f.YNodeCoords
#      z = f.ZNodeCoords
#      c = f.ZNodeVelocity
#      n_zones = f.NumZones
#      # Put vertices in right order for Gist
#      n_z = transpose (
#         take (transpose (n_z), array ( [0, 4, 3, 7, 1, 5, 2, 6])))
#      m3 = mesh3 (x, y, z, funcs = [c], verts = n_z ) # [0:10])
#      [nv, xyzv, cv] = slice3 (m3, 1, None, None, 1, value = .9 * max (c) )
#      pyz = plane3 ( array ([1, 0, 0], float32 ), zeros (3, float32))
#      pxz = plane3 ( array ([0, 1, 0], float32 ), zeros (3, float32))
#
#      # draw a colored plane first
#      fma ()
#      clear3 ()
#      # Make sure we don't draw till ready
#      set_draw3_ (0)
#      [np, xyzp, vp] = slice3 (m3, pyz, None, None, 1)
#      pl3tree (np, xyzp, vp, pyz, split = 0)
#      palette ("rainbow.gp")
#      orient3 ()
#      demo5_light (1)
#      paws ()
#
#
#     [nv, xyzv, d1] = \
#         slice2 (- pyz, nv, xyzv, None)
#      [nw, xyzw, cw] = slice3 (m3, 1, None, None, 1, value = .9 * min (c) )
#     [nw, xyzw, d1] = \
#         slice2 (- pyz, nw, xyzw, None)
#      [nvi, xyzvi, cvi] = slice3 (m3, 1, None, None, 1, value = .5 * min (c) )
#      [nvi, xyzvi, cvi] = \
#          slice2 (- pyz, nvi, xyzvi, cvi)
#      [nvj, xyzvj, cvj] = slice3 (m3, 1, None, None, 1, value = .5 * max (c) )
#      [nvj, xyzvj, cvj] = \
#          slice2 (- pyz, nvj, xyzvj, cvj)
#
#      fma ()
#      print "gnomon -- turn on gnomon"
#      gnomon (1)
#      clear3 ()
#      # Make sure we don't draw till ready
#      set_draw3_ (0)
#      pl3tree (nv, xyzv) # , cv)
#      pl3tree (nw, xyzw) # , cw)
#      pl3tree (nvi, xyzvi) # , cvi)
#      pl3tree (nvj, xyzvj) # , cvi)
#      orient3 ()
#      light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1])
#      limits (square=1)
#      palette ("gray.gp")
#      demo5_light (1)
#      paws ()
#
#      print "spin3 animated rotation, use rot3 or orient3 for one frame"
#      # don't want limits to autoscale during animation
#      spin3 ()
#      limits ( ) # back to autoscaling
#      demo5_light (1)
#      paws ()
#
#      light3 ()
#      gnomon (0)
#      palette ("gray.gp")
#
#      draw3 ( 1 )
#      paws ()
#      clear3 ()
#      del nv, xyzv, cv, nw, xyzw, cw, nvi, xyzvi, cvi, nvj, xyzvj, cvj
#      # Make sure we don't draw till ready
#      set_draw3_ (0)
#      for i in range (8) :
#         [nv, xyzv, cv] = slice3 (m3, 1, None, None, 1, value = .9 * min (c) +
#             i * (.9 * max (c) - .9 * min (c)) / 8.)
#         [nv, xyzv, d1] = \
#             slice2 (pxz, nv, xyzv, None)
#         pl3tree (nv, xyzv)
#      orient3 ()
#      light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1])
#      limits (square=1)
#      palette ("heat.gp")
#      demo5_light (1)
#      paws ()
#      spin3 ()
#      limits ( ) # back to autoscaling
#      demo5_light (1)
#      paws ()
#      demo5_light (1)
#      paws ()
#
#   if len (itest) == 0 or itest [0] == 5 :
#      # Try bert's data
#      from PR import PR
#      f = PR ('./berts_plot')
#      nums = array ( [63, 63, 49], int32)
#      dxs = array ( [2.5, 2.5, 10.], float32 )
#      x0s = array ( [-80., -80., 0.0], float32 )
#      c = f.c
#
#      m3 = mesh3 (nums, dxs, x0s, funcs = [transpose (c)])
#      [nv, xyzv, dum] = slice3 (m3, 1, None, None, value = 6.5)
#      fma ()
#      clear3 ()
#      print "gnomon -- turn on gnomon"
#      gnomon (1)
#      # Make sure we don't draw till ready
#      set_draw3_ (0)
#      palette ("rainbow.gp")
#      pl3tree (nv, xyzv)
#      orient3 ()
#      light3 (diffuse = .2, specular = 1)
#      limits (square=1)
#      demo5_light (1)
#      paws ()
#      spin3 ()
#      demo5_light (1)
#      paws ()
#   if len (itest) == 0 or itest [0] == 6 :
#      # Try Bill's irregular mesh
#      from PR import PR
#      f = PR ("ball.s0001")
#      ZLss = f.ZLstruct_shapesize
#      ZLsc = f.ZLstruct_shapecnt
#      ZLsn = f.ZLstruct_nodelist
#      x = f.sap_mesh_coord0
#      y = f.sap_mesh_coord1
#      z = f.sap_mesh_coord2
#      c = f.W_vel_data
#      # Now we need to convert this information to avs-style data
#      istart = 0 # beginning index into ZLstruct_nodelist
#      NodeError = "NodeError"
#      ntet = 0
#      nhex = 0
#      npyr = 0
#      nprism = 0
#      nz_tet = []
#      nz_hex = []
#      nz_pyr = []
#      nz_prism = []
#      for i in range (4) :
#         if ZLss [i] == 4 : # TETRAHEDRON
#            nz_tet = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]],
#                     (ZLsc [i], ZLss [i]))
#            ntet = ZLsc [i]
#            istart = istart + ZLss [i] * ZLsc [i]
#         elif ZLss[i] == 5 : # PYRAMID
#            nz_pyr = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]],
#                     (ZLsc [i], ZLss [i]))
#            npyr = ZLsc [i]
#            # Now reorder the points (bill has the apex last instead of first)
#            nz_pyr = transpose (
#               take (transpose (nz_pyr), array ( [4, 0, 1, 2, 3])))
#            istart = istart + ZLss [i] * ZLsc [i]
#         elif ZLss[i] == 6 : # PRISM
#            nz_prism = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]],
#                     (ZLsc [i], ZLss [i]))
#            nprism = ZLsc [i]
#            # now reorder the points (bill goes around a square face
#            # instead of traversing the opposite sides in the same direction.
#            nz_prism = transpose (
#               take (transpose (nz_prism), array ( [0, 1, 3, 2, 4, 5])))
#            istart = istart + ZLss [i] * ZLsc [i]
#         elif ZLss[i] == 8 : # HEXAHEDRON
#            nz_hex = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]],
#                     (ZLsc [i], ZLss [i]))
#            # now reorder the points (bill goes around a square face
#            # instead of traversing the opposite sides in the same direction.
#            nz_hex = transpose (
#               take (transpose (nz_hex), array ( [0, 1, 3, 2, 4, 5, 7, 6])))
#            nhex = ZLsc [i]
#            istart = istart + ZLss [i] * ZLsc [i]
#         else :
#            raise NodeError, `ZLss[i]` + "is an incorrect number of nodes."

#      m3 = mesh3 (x, y, z, funcs = [c], verts = [nz_tet, nz_pyr, nz_prism,
#         nz_hex])
#      [nv, xyzv, cv] = slice3 (m3, 1, None, None, 1, value = .9 * max (c) )
#      pyz = plane3 ( array ([1, 0, 0], float32 ), zeros (3, float32))
#      pxz = plane3 ( array ([0, 1, 0], float32 ), zeros (3, float32))
#
#      # draw a colored plane first
#      fma ()
#      clear3 ()
#      # Make sure we don't draw till ready
#      set_draw3_ (0)
#      [np, xyzp, vp] = slice3 (m3, pyz, None, None, 1)
#      pl3tree (np, xyzp, vp, pyz, split = 0)
#      palette ("rainbow.gp")
#      orient3 ()
#      limits (square=1)
#      demo5_light (1)
#      paws ()
#
#      [nw, xyzw, cw] = slice3 (m3, 1, None, None, 1, value = .9 * min (c) )
#      [nvi, xyzvi, cvi] = slice3 (m3, 1, None, None, 1, value = .1 * min (c) )
#      [nvi, xyzvi, cvi] = \
#          slice2 (- pyz, nvi, xyzvi, cvi)
#      [nvj, xyzvj, cvj] = slice3 (m3, 1, None, None, 1, value = .1 * max (c) )
#      [nvj, xyzvj, cvj] = \
#          slice2 (- pyz, nvj, xyzvj, cvj)
#      [nvii, xyzvii, cvii] = slice3 (m3, 1, None, None, 1,
#         value = 1.e-12 * min (c) )
#      [nvii, xyzvii, cvii] = \
#          slice2 (- pyz, nvii, xyzvii, cvii)
#      [nvjj, xyzvjj, cvjj] = slice3 (m3, 1, None, None, 1,
#         value = 1.e-12 * max (c) )
#      [nvjj, xyzvjj, cvjj] = \
#          slice2 (- pyz, nvjj, xyzvjj, cvjj)
#
#      fma ()
#      print "gnomon -- turn on gnomon"
#      gnomon (1)
#      clear3 ()
#      # Make sure we don't draw till ready
#      set_draw3_ (0)
#      pl3tree (nv, xyzv) # , cv)
#      pl3tree (nw, xyzw) # , cw)
#      pl3tree (nvi, xyzvi) # , cvi)
#      pl3tree (nvj, xyzvj) # , cvj)
#      pl3tree (nvii, xyzvii) # , cvii)
#      pl3tree (nvjj, xyzvjj) # , cvjj)
#      orient3 ()
#      light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1])
#      limits (square=1)
#      palette ("gray.gp")
#      demo5_light (1)
#      paws ()
#      palette ("heat.gp")
#      paws ()

    if len(itest) == 0 or itest[0] == 7:

        print "Test plwf on the sombrero function"
        # compute sombrero function
        x = arange(-20, 21, dtype=float32)
        y = arange(-20, 21, dtype=float32)
        z = zeros((41, 41), float32)
        r = sqrt(add.outer(x**2, y**2)) + 1e-6
        z = sin(r) / r
        fma()
        clear3()
        gnomon(0)
        # Make sure we don't draw till ready
        set_draw3_(0)
        palette("rainbow.gp")
        limits(square=1)
        orient3()
        light3()
        plwf(z, fill=z, ecolor="black")
        [xmin, xmax, ymin, ymax] = draw3(1)
        limits(xmin, xmax, ymin, ymax)
        paws()

        print "Try smooth contours, log mode:"
        print 'plzcont (nv, xyzv, contours = 20, scale = "normal")'
        [nv, xyzv, dum] = slice3mesh(x, y, z)
        zmult = max(max(abs(x)), max(abs(y)))
        plzcont(nv, xyzv, contours=20, scale="normal")
        [xmin, xmax, ymin, ymax] = draw3(1)
        limits(xmin, xmax, ymin, ymax)
        paws()

        print 'plzcont (nv, xyzv, contours = 20, scale = "lin", edges=1)'
        plzcont(nv, xyzv, contours=20, scale="lin", edges=1)
        [xmin, xmax, ymin, ymax] = draw3(1)
        limits(xmin, xmax, ymin, ymax)
        paws()

        print 'plwf (z, fill = z, shade = 1, ecolor = "black")'
        plwf(z, fill=z, shade=1, ecolor="black")
        [xmin, xmax, ymin, ymax] = draw3(1)
        limits(xmin, xmax, ymin, ymax)
        paws()

        print "plwf (z, fill = z, shade = 1, edges = 0)"
        plwf(z, fill=z, shade=1, edges=0)
        [xmin, xmax, ymin, ymax] = draw3(1)
        limits(xmin, xmax, ymin, ymax)
        paws()

        print "light3(diffuse=.2,specular=1)"
        print "demo5_light calls:"
        print "light3 (sdir = array ( [cos(theta), .25, sin(theta)], float32))"
        light3(diffuse=.2, specular=1)
        making_movie = 1
        movie(demo5_light, lims=[xmin, xmax, ymin, ymax])
        making_movie = 0
        fma()
        demo5_light(1)
        paws()

        print "plwf (z, fill = None, shade = 1, edges = 0)"
        plwf(z, fill=None, shade=1, edges=0)
        [xmin, xmax, ymin, ymax] = draw3(1)
        palette("gray.gp")
        limits(xmin, xmax, ymin, ymax)
        paws()

    if len(itest) == 0 or itest[0] == 8:

        print "Test pl3surf on the sombrero function"
        # compute sombrero function
        nc1 = 100
        nv1 = nc1 + 1
        br = -(nc1 / 2)
        tr = nc1 / 2 + 1
        x = arange(br, tr, dtype=float32) * 40. / nc1
        y = arange(br, tr, dtype=float32) * 40. / nc1
        z = zeros((nv1, nv1), float32)
        r = sqrt(add.outer(x**2, y**2)) + 1e-6
        z = sin(r) / r
        # In order to use pl3surf, we need to construct a mesh
        # using mesh3. The way I am going to do that is to define
        # a function on the 3d mesh so that the sombrero function
        # is its 0-isosurface.
        z0 = min(ravel(z))
        z0 = z0 - .05 * abs(z0)
        maxz = max(ravel(z))
        maxz = maxz + .05 * abs(maxz)
        zmult = max(max(abs(x)), max(abs(y)))
        dz = (maxz - z0)
        nxnynz = array([nc1, nc1, 1], int32)
        dxdydz = array([1.0, 1.0, zmult * dz], float32)
        x0y0z0 = array([float(br), float(br), z0 * zmult], float32)
        meshf = zeros((nv1, nv1, 2), float32)
        meshf[:, :, 0] = zmult * z - (x0y0z0[2])
        meshf[:, :, 1] = zmult * z - (x0y0z0[2] + dxdydz[2])

        m3 = mesh3(nxnynz, dxdydz, x0y0z0, funcs=[meshf])
        fma()
        # Make sure we don't draw till ready
        set_draw3_(0)
        pldefault(edges=0)
        [nv, xyzv, col] = slice3(m3, 1, None, None, value=0.)
        orient3()
        pl3surf(nv, xyzv)
        lim = draw3(1)
        limits(lim[0], lim[1], 1.5 * lim[2], 1.5 * lim[3])
        palette("gray.gp")
        paws()

        print "Try new slicing function (slice3mesh) to get color graph"
        [nv, xyzv, col] = slice3mesh(nxnynz[0:2],
                                     dxdydz[0:2],
                                     x0y0z0[0:2],
                                     zmult * z,
                                     color=zmult * z)
        pl3surf(nv, xyzv, values=col)
        lim = draw3(1)
        dif = 0.5 * (lim[3] - lim[2])
        limits(lim[0], lim[1], lim[2] - dif, lim[3] + dif)

        palette("rainbow.gp")
        paws()

        print "Try plzcont -- see if smooth mode is possible"
        print "plzcont (nv, xyzv)"
        palette("heat.gp")
        plzcont(nv, xyzv)
        draw3(1)
        paws()

        print "plzcont (nv, xyzv, contours = 20)"
        plzcont(nv, xyzv, contours=20)
        draw3(1)
        paws()

        print 'plzcont (nv, xyzv, contours = 20, scale = "log")'
        plzcont(nv, xyzv, contours=20, scale="log")
        draw3(1)
        paws()

        print 'plzcont (nv, xyzv, contours = 20, scale = "normal")'
        plzcont(nv, xyzv, contours=20, scale="normal")
        draw3(1)
        paws()

    if len(itest) == 0 or itest[0] == 9:

        vsf = 0.
        c = 1
        s = 1000.
        kmax = 25
        lmax = 35

        # The following computations define an interesting 3d surface.

        xr = multiply.outer(arange(1, kmax + 1, dtype=float32),
                            ones(lmax, float32))
        yr = multiply.outer(ones(kmax, float32),
                            arange(1, lmax + 1, dtype=float32))
        zt = 5. + xr + .2 * random_sample(kmax, lmax)  # ranf (xr)
        rt = 100. + yr + .2 * random_sample(kmax, lmax)  # ranf (yr)
        z = s * (rt + zt)
        z = z + .02 * z * random_sample(kmax, lmax)  # ranf (z)
        ut = rt / sqrt(rt**2 + zt**2)
        vt = zt / sqrt(rt**2 + zt**2)
        ireg = multiply.outer(ones(kmax, float32), ones(lmax, float32))
        ireg[0:1, 0:lmax] = 0
        ireg[0:kmax, 0:1] = 0
        ireg[1:15, 7:12] = 2
        ireg[1:15, 12:lmax] = 3
        ireg[3:7, 3:7] = 0
        freg = ireg + .2 * (1. - random_sample(kmax, lmax))  # ranf (ireg))
        freg = array(freg, float32)
        #rt [4:6, 4:6] = -1.e8
        z[3:10, 3:12] = z[3:10, 3:12] * .9
        z[5, 5] = z[5, 5] * .9
        z[17:22, 15:18] = z[17:22, 15:18] * 1.2
        z[16, 16] = z[16, 16] * 1.1
        orient3()
        print "plwf (freg, shade = 1, edges = 0)"
        plwf(freg, shade=1, edges=0)
        [xmin, xmax, ymin, ymax] = draw3(1)
        limits(xmin, xmax, ymin, ymax)
        paws()

        print "two slice3mesh and two pl3tree"
        nxny = array([kmax - 1, lmax - 1])
        x0y0 = array([0., 0.])
        dxdy = array([1., 1.])
        [nv, xyzv, col] = slice3mesh(nxny, dxdy, x0y0, freg)
        [nw, xyzw, col] = slice3mesh(nxny, dxdy, x0y0, freg + ut)
        pl3tree(nv, xyzv)
        pl3tree(nw, xyzw)
        draw3(1)
        limits()
        paws()

        print "light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1])"
        light3(ambient=0, diffuse=.5, specular=1, sdir=[0, 0, -1])
        demo5_light(1)
        paws()

        print "[nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, freg, color = freg)"
        [nv, xyzv, col] = slice3mesh(nxny, dxdy, x0y0, freg, color=freg)
        pl3surf(nv, xyzv, values=col)
        draw3(1)
        palette("rainbow.gp")
        paws()

        print 'palette ("rainbow.gp")'
        [nv, xyzv, col] = slice3mesh(nxny, dxdy, x0y0, freg, color=z)
        pl3surf(nv, xyzv, values=col)
        draw3(1)
        paws()

        print 'palette ("stern.gp")'
        palette("stern.gp")
        paws()

        print "[nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, z, color = z)"
        [nv, xyzv, col] = slice3mesh(nxny, dxdy, x0y0, z, color=z)
        pl3surf(nv, xyzv, values=col)
        orient3(phi=0, theta=0)
        draw3(1)
        paws()

        print 'palette ("gray.gp")'
        print "light3 ( diffuse=.1, specular=1., sdir=array([0,0,-1]))"
        set_draw3_(0)
        palette("gray.gp")
        light3(diffuse=.1, specular=1., sdir=array([0, 0, -1]))
        pl3surf(nv, xyzv)
        draw3(1)
        paws()


#     spin3 ()
#     paws ()

    hcp_finish()
Пример #5
0
def main(info):  
    feedback = None
    special_format=False
###########################################################################################
#calc
###########################################################################################
    op=False
    nu=False
    current_theme_file=open("data/settings/current_theme.txt","r")
    current_theme=current_theme_file.readline()
    current_theme_file.close()
    for i in range(0,len(operator)):
        if operator[i] in info:
            op=True
    for i in range(0,len(number)):
        if number[i] in info:
            nu=True
    if op==True and nu==True:
        feedback = calc(info)
###########################################################################################
#去符号
###########################################################################################
    q=False
    if info[-2:]=='?'or info[-1:]=='?':
        q=True
    origin_info=info
    info=info.decode("gbk").encode("utf8") 
    for i in range(0,len(en_punctuation)):
        while en_punctuation[i].decode("gbk").encode("utf8") in info:
            info=info[:info.index(en_punctuation[i].decode("gbk").encode("utf8"))]+info[info.index(en_punctuation[i].decode("gbk").encode("utf8"))+1:]
    for i in range(0,len(cn_punctuation)):
        while cn_punctuation[i].decode("gbk").encode("utf8") in info:
            info=info[:info.index(cn_punctuation[i].decode("gbk").encode("utf8"))]+info[info.index(cn_punctuation[i].decode("gbk").encode("utf8"))+3:]
    info=info.decode("utf8").encode("gbk")

###########################################################################################
#cancel
###########################################################################################
    if '取消' in info:
        if '关机' in info or '关闭计算机'in info or '关闭电脑'in info:        
            subprocess.Popen('shutdown -a', shell=True)
            feedback ='您的关机计划已取消(设置关机计划时会自动取消之前的关机计划)'
        elif '重启' in info or '重新启动' in info:        
            subprocess.Popen('shutdown -a', shell=True)
            feedback ='您的重启计划已取消(设置重启计划时会自动取消之前的重启计划)'
        elif '注销' in info:        
            subprocess.Popen('shutdown -a', shell=True)
            feedback ='您的注销计划已取消'
        elif '提醒' in info:
            cancel()
            feedback ='已将所有提醒事项取消'

###########################################################################################
#search
########################################################################################### 
    if '搜索' in info:
        info=info[info.index('搜索')+4:]
        feedback=baidu(info)
    elif '搜一下' in info:
        info=info[info.index('搜一下')+6:]
        feedback=baidu(info)
    elif '百度一下' in info:
        info=info[info.index('百度一下')+8:]
        feedback=baidu(info)
    elif 'baidu一下' in info:
        info=info[info.index('baidu一下')+9:]
        feedback=baidu(info)
###########################################################################################
#weather
###########################################################################################
    if '天气'in info or '下雨吗'in info or '下雨了吗'in info or '有雨吗'in info or '下不下雨'in info or '什么天'in info or '晴天吗'in info or '下雪吗'in info or '下不下雪'in info or '温度'in info or '多少度'in info or '几度'in info or '气温'in info:
        city=False
        city_file=open("data/db/city1.txt","r")
        for i in range (0,2586):
            city_info=city_file.readline()
            city_name=city_info[10:].strip(" \n")
            if city_name in info:
                city=True
                break
        if city:
            feedback = city_weather(city_name)
        else:
            feedback = local_weather()
        if feedback:
            special_format = True
###########################################################################################
#xiaohua
###########################################################################################
    if "讲个笑话" in info or "内涵段子" in info:
        feedback=xiaohua()
        style_path_file=open("data/settings/style_path.txt","r")
        style_path=style_path_file.read()
        style_path_file.close()
        href_file=open(style_path+"href.txt","r")
        href=href_file.read()
        href_file.close()
        feedback = '<p style="font-family:Microsoft Yahei;font:24px">'+feedback+',do,御坂强忍着笑声说道<br><a style="text-decoration:none;color:#'+href+'" href="#">再来一个</a></p>'
        special_format=True
    if "内涵图" in info or "搞笑图" in info:
        feedback=neihan()
        style_path_file=open("data/settings/style_path.txt","r")
        style_path=style_path_file.read()
        style_path_file.close()
        href_file=open(style_path+"href.txt","r")
        href=href_file.read()
        href_file.close()
        feedback = feedback+'<a style="font-family:Microsoft Yahei;font:24px;text-decoration:none;color:#'+href+'" href="#">再来一个</a>'
        special_format=True
    if "让我开心一下" in info or "让我高兴一下" in info:
        style_path_file=open("data/settings/style_path.txt","r")
        style_path=style_path_file.read()
        style_path_file.close()
        href_file=open(style_path+"href.txt","r")
        href=href_file.read()
        href_file.close()
        if random.randint(0,1)==0:
            feedback=xiaohua()
            feedback = '<p style="font-family:Microsoft Yahei;font:24px">'+feedback+',do,御坂强忍着笑声说道<br><a style="text-decoration:none;color:#'+href+'" href="#">再来一个</a></p>'
        else:
            feedback=neihan()
            feedback = feedback+'<a style="font-family:Microsoft Yahei;font:24px;text-decoration:none;color:#'+href+'" href="#">再来一个</a>'
        special_format=True
###########################################################################################
#run
###########################################################################################
    exe=sys_app=sys_game=sys=web=None
    start=False
    if info[:4]=='打开':
        b=info[4:]
        start=True
    else:
        b=info
    if b=='显示桌面':
        os.startfile("bin\\Shows Desktop.lnk")
        feedback="正在为您显示桌面"
    elif b=='控制面板':
        sys_app='control'
    elif b=='显示':
        sys_app='DpiScaling'
    elif b=='计算器':
        sys_app='calc'
    elif b=='画图':
        sys_app='mspaint'
    elif b=='便笺':
        sys_app='StikyNot'
    elif b=='截图工具':
        sys_app='SnippingTool'     
    elif b=='录音机':
        sys_app='SoundRecorder'
    elif b.lower()=='cmd' or b=='命令行' or b=='命令提示符':
        sys_app='cmd'
    elif b=='放大镜':
        sys_app='Magnify'
    elif b.lower()=='windows移动中心' or b=='移动中心':
        sys_app='mblctr'
    elif b=='系统配置':
        sys_app='msconfig'
    elif b=='系统信息':
        sys_app='msinfo32'
    elif b=='用户账户':
        sys_app='Netplwiz'
    elif b=='屏幕键盘':
        sys_app='osk'
    elif b=='注册表编辑器' or b=='注册表':
        sys_app='regedt32'
    elif b=='音量合成器' or b=='音量合成' or b=='音量控制器' or b=='音量控制' or b=='音量':
        sys_app='SndVol'
    elif b=='任务管理器' or b.lower()=='windows任务管理器':
        sys_app='taskmgr'
    elif b=='关于' or b.lower()=='关于windows' or b.lower()=='windows版本' or b=='系统版本':
        sys_app='winver'
    elif b=='磁盘清理':
        sys_app='cleanmgr'
    elif b=='磁盘碎片整理':
        sys_app='dfrgui'
    elif b=='管理' or b=='计算机管理':
        sys_app='CompMgmtLauncher'
    elif b=='资源监视器':
        sys_app='resmon'
    elif b.lower()=='windows功能' or b.lower()=='打开或关闭windows功能':
        sys_app='OptionalFeatures'
    elif b=='备份和还原' or b=='备份' or b=='系统备份':
        sys_app='sdclt'
    elif b=='系统还原':
        sys_app='rstrui'
    elif b=='系统属性' or b=='系统高级属性' or b=='高级系统设置' or b=='高级系统属性':
        sys_app='SystemPropertiesAdvanced'
    elif b=='用户账户控制' or b=='账户控制':
        sys_app='UserAccountControlSettings'
    elif b=='轻松访问中心' or b=='轻松访问':
        sys_app='Utilman'
    elif b=='服务':
        sys_app='services.msc'
    elif b=='磁盘管理' or b=='磁盘管理器':
        sys_app='diskmgmt.msc'
    elif b=='设备管理器' or b=='设备管理':
        sys_app='devmgmt.msc'
    elif b=='打印管理' or b=='打印机管理' or b=='打印机':
        sys_app='printmanagement.msc'    
    elif b=='扫雷':
        sys_game='MineSweeper'
    elif b=='空当接龙':
        sys_game='FreeCell'
    elif b=='纸牌':
        sys_game='Solitaire'
    elif b=='蜘蛛纸牌':
        sys_game='SpiderSolitaire'
    elif b=='麻将':
        sys_game='Mahjong'
    elif b=='红心大战':
        sys_game='Hearts'
    elif b=='国际象棋':
        sys_game='Chess'
    elif b=='双陆棋':
        sys_game='InternetBackgammon'
    elif b=='三维弹球':
        sys_game='3DPinlinkall'
    elif b=='跳棋':
        sys_game='InternetCheckers'
    elif b=='黑桃王':
        sys_game='InternetSpades'
    elif b=='记事本':
        sys='notepad'
    elif b=='写字板':
        sys='write'
    elif b=='帮助' or b=='Windows帮助和支持':
        sys='winhlp32'
    elif b=='库' or b=='计算机' or b=='我的电脑' or b.lower()=='windows资源管理器':
        sys='explorer'
    elif b=='回收站':
        os.popen('explorer.exe ::{645FF040-5081-101B-9F08-00AA002F954E}')
        feedback='正在为您打开%s'%b
    elif b=='网上邻居' or b=='网络':
        os.popen('explorer.exe ::{208D2C60-3AEA-1069-A2D7-08002B30309D}')
        feedback='正在为您打开%s'%b
    elif b=='我的文档':
        os.popen('explorer.exe ::{450D8FBA-AD25-11D0-98A8-0800361B1103}')
        feedback='正在为您打开%s'%b
    elif b.lower()=='c盘'or b.lower()=='c':
        os.popen('%SystemRoot%\explorer.exe /n,/e,C:\\')
        feedback='正在为您打开%s盘'%b[:1]
    elif b.lower()=='d盘'or b.lower()=='d':
        os.popen('%SystemRoot%\explorer.exe /n,/e,D:\\')
        feedback='正在为您打开%s盘'%b[:1]
    elif b.lower()=='e盘'or b.lower()=='e':
        os.popen('%SystemRoot%\explorer.exe /n,/e,E:\\')
        feedback='正在为您打开%s盘'%b[:1]
    elif b.lower()=='f盘'or b.lower()=='f':
        os.popen('%SystemRoot%\explorer.exe /n,/e,F:\\')
        feedback='正在为您打开%s盘'%b[:1]
    elif b.lower()=='g盘'or b.lower()=='g':
        os.popen('%SystemRoot%\explorer.exe /n,/e,G:\\')
        feedback='正在为您打开%s盘'%b[:1]
    elif b.lower()=='h盘'or b.lower()=='h':
        os.popen('%SystemRoot%\explorer.exe /n,/e,H:\\')
        feedback='正在为您打开%s盘'%b[:1]
    elif b.lower()=='i盘'or b.lower()=='i':
        os.popen('%SystemRoot%\explorer.exe /n,/e,J:\\')
        feedback='正在为您打开%s盘'%b[:1]
    elif b.lower()=='j盘'or b.lower()=='j':
        os.popen('%SystemRoot%\explorer.exe /n,/e,K:\\')
        feedback='正在为您打开%s盘'%b[:1]
    elif b=='百度'or b=='浏览器'or b.lower()=='baidu':
        web='http://www.baidu.com'
    elif b=='贴吧'or b=='百度贴吧'or b=='tieba':
        web='http://tieba.baidu.com'
    elif b=='百度云':
        web='http://yun.baidu.com'
    elif b=='百度地图':
        web='http://map.baidu.com'
    elif b=='优酷'or b=='优酷网'or b.lower()=='youku':
        web='http://www.youku.com' 
    elif b=='土豆网':
        web='http://www.tudou.com' 
    elif b=='豆瓣'or b=='豆瓣网'or b.lower()=='douban':
        web='http://www.douban.com'
    elif b=='豆瓣电影':
        web='http://movie.douban.com'
    elif b=='QQ空间'or b.lower()=='qzone':
        web='http://qzone.qq.com'
    elif b=='网易':
        web='http://www.163.com'
    elif b=='网易邮箱'or b=='163邮箱':
        web='http://mail.163.com'
    elif b.lower()=='qq邮箱':
        web='http://mail.qq.com'
    elif b=='网易云音乐'or b=='网易音乐':
        web='http://music.163.com'
    elif b=='爱奇艺'or b.lower()=='iqiyi':
        web='http://www.iqiyi.com'
    elif b.lower()=='豆瓣fm':
        web='http://fm.douban.com'
    elif b=='搜狐'or b=='搜狐网':
        web='http://www.sohu.com'
    elif b=='搜狐视频':
        web='http://tv.sohu.com'
    elif b=='新浪'or b=='新浪网'or b.lower()=='sina':
        web='http://www.sina.com'
    elif b=='微博'or b=='新浪微博'or b.lower()=='weibo':
        web='http://www.weibo.com'
    elif b=='腾讯网'or b.lower()=='tencent':
        web='http://www.qq.com'
    elif b=='人人网':
        web='http://www.renren.com'
    elif b=='凤凰网':
        web='http://www.ifeng.com'
    elif b=='携程'or b=='携程网':
        web='http://www.ctrip.com'
    elif b=='去哪儿'or b=='去哪儿网'or b=='去哪'or b=='去哪网':
        web='http://www.qunar.com'
    elif b=='中关村'or b=='中关村在线':
        web='http://www.zol.com.cn'
    elif b=='汽车之家'or b=='autohome':
        web='http://www.autohome.com'
    elif b=='赶集网':
        web='http://www.ganji.com'
    elif b=='央视网'or b.lower()=='cctv':
        web='http://www.ctrip.com'
    elif b=='人民网':
        web='http://www.people.com.cn'
    elif b=='新华网':
        web='http://www.xinhuanet.com' 
    elif b=='环球网':
        web='http://www.huanqiu.com'
    elif b=='联合早报'or b=='联合早报网':
        web='http://www.zaobao.com'
    elif b=='网易新闻':
        web='http://news.163.com'
    elif b=='淘宝'or b=='淘宝网'or b.lower()=='taobao':
        web='http://www.taobao.com'
    elif b=='天猫'or b=='天猫网':
        web='http://www.tmall.com'
    elif b=='京东'or b=='京东网':
        web='http://www.jd.com'
    elif b=='亚马逊'or b.lower()=='amazon':
        web='http://www.amazon.cn'
    elif b=='苏宁易购':
        web='http://www.suning.com'
    elif b=='当当'or b=='当当网':
        web='http://www.dangdang.com'
    elif b=='美团'or b=='美团网':
        web='http://www.meituan.com'
    elif b=='美团外卖':
        web='http://waimai.meituan.com'
    elif b=='饿了么':
        web='http://www.ele.me'
    elif b=='美丽街':
        web='http://www.meilijie.com'
    elif b=='美丽说':
        web='http://www.meilishuo.com'
    elif b=='唯品会':
        web='http://www.vip.com'
    elif b=='1号店':
        web='http://www.yhd.com'
    elif b=='聚美优品':
        web='http://www.jumei.com'
    elif b=='聚划算':
        web='http://ju.taobao.com'
    elif b=='糯米'or b=='百度糯米'or b=='糯米团购':
        web='http://www.nuomi.com'
    elif b=='凡客'or b=='凡客诚品':
        web='http://www.vancl.com'
    elif b=='拉手'or b=='拉手网':
        web='http://www.lashou.com'
    elif b=='yitao':
        web='http://www.etao.com'
    elif b=='蘑菇街':
        web='http://www.mogujie.com'
    elif b=='爱淘宝':
        web='http://ai.taobao.com'
    elif b=='天涯网'or b=='天涯社区':
        web='http://www.tianya.com'
    elif b=='百合网':
        web='http://www.baihe.com'
    elif b=='珍爱网':
        web='http://www.zhenai.com'
    elif b=='世纪佳缘':
        web='http://www.jiayuan.com'
    elif b=='威锋网':
        web='http://www.weifeng.com'
    elif b=='猫扑网'or b=='猫扑大杂烩':
        web='http://www.mop.com'
    elif b=='大众点评':
        web='http://www.dianping.com'
    elif b=='58同城':
        web='http://www.58.com'
    elif b=='12306'or b=='火车票':
        web='http://www.12306.cn'
    elif b=='维基'or b=='维基百科'or b=='wikipedia':
        web='http://zh.wikipedia.org'
    elif b=='互动百科':
        web='http://www.baike.com'
    elif b.lower()=='lofter':
        web='http://www.lofter.com'
    elif b=='多看'or b=='多看阅读':
        web='http://www.duokan.com'
    elif b=='暴走漫画':
        web='http://www.baozoumanhua.com'
    elif b=='有妖气'or b=='有妖气漫画':
        web='http://www.u17.com'
    elif b=='果壳'or b=='果壳网':
        web='http://www.guokr.com'
    elif b=='36氪'or b.lower()=='36kr':
        web='http://www.36kr.com'
    elif b=='爱范儿'or b.lower()=='ifanr':
        web='http://www.ifanr.com'
    elif b=='煎蛋'or b=='煎蛋网':
        web='http://www.jiandan.com'
    elif b=='科学松鼠会':
        web='http://www.songshuhui.com'
    elif b=='技术宅社区':
        web='http://www.gn00.com'
    elif b=='技术宅的结界'or b.lower()=='0xaa55':
        web='http://www.0xaa55.com'
    elif b.lower()=='jackeriss'or b.lower()=='jc'or b.lower()=='jack criss':
        web='http://www.jackeriss.com'
    elif b=='慕课'or b=='慕课网':
        web='http://www.imooc.com'
    elif b=='智联招聘':
        web='http://www.zhaopin.com'
    elif b=='前程无忧':
        web='http://www.51job.com'
    elif b=='知乎'or b=='知乎网':
        web='http://www.zhihu.com'
    elif b=='虎嗅'or b=='虎嗅网':
        web='http://www.huxiu.com'
    elif b=='堆糖'or b=='堆糖网':
        web='http://www.duitang.com'
    elif b=='砍柴网':
        web='http://www.ikanchai.com'
    elif b=='哔哩哔哩'or b.lower()=='b站'or b.lower()=='bilibili':
        web='http://www.bilibili.com'
    elif b.lower()=='acfun'or b.lower()=='a站':
        web='http://www.acfun.tv'
    elif b=='斗鱼'or b=='斗鱼直播'or b.lower()=='斗鱼tv':
        web='http://www.douyutv.com'
    elif b.lower()=='yy'or b.lower()=='yy直播':
        web='http://www.yy.com'
    elif b=='战旗'or b.lower()=='战旗tv':
        web='http://www.zhanqi.tv'
    elif b=='17173':
        web='http://www.17173.com'
    elif b=='游民星空':
        web='http://www.gamesky.com'
    elif b=='战网':
        web='http://www.battlenet.cn'
    elif b.lower()=='steam':
        web='http://store.steampowered.com'
    elif b.lower()=='twitch':
        web='http://www.twitch.com'
    elif b=='推特'or b.lower()=='twitter':
        web='http://www.twitter.com'
    elif b=='脸书'or b.lower()=='facebook':
        web='http://www.facebook.com'
    elif b=='谷歌'or b.lower()=='google':
        web='http://www.google.com'
    elif b.lower()=='youtube':
        web='http://www.youtube.com'
    elif b.lower()=='ebay':
        web='http://www.ebay.com'
    elif b.lower()=='github':
        web='http://www.github.com'
    elif b=='雅虎'or b.lower()=='yahoo':
        web='http://www.yahoo.com'
    if sys_app:
        thread.start_new_thread(subprocess.Popen,(sys_app,))
        feedback='正在为您打开%s'%b           
    elif sys_game:
        thread.start_new_thread(os.startfile,(programfiles_path+'/Microsoft Games/'+sys_game+'/'+sys_game+'.exe',))
        feedback='正在为您打开%s'%b 
    elif sys:
        thread.start_new_thread(subprocess.Popen,(sys,))
        feedback='正在为您打开%s'%b
    elif web:
        webbrowser.open_new_tab(web)
        feedback='正在为您打开%s'%b
    if not feedback:
        if info.isalpha():
            if info.count(' ')<2:
                feedback=iciba(info)
###########################################################################################
#the_time
###########################################################################################
    if '几号' in info:
        if '今天' in info:
            feedback=time_now(0)
        elif '明天' in info:
            feedback=time_now(2)
        elif '大后天' in info:
            feedback=time_now(6)
        elif '后天' in info:
            feedback=time_now(4)
        elif '昨天' in info:
            feedback=time_now(8)
        elif '大前天' in info:
            feedback=time_now(12)
        elif '前天' in info:
            feedback=time_now(10)
    elif '星期几' in info or '周几' in info:
        if '今天' in info:
            feedback=time_now(1)
        elif '明天' in info:
            feedback=time_now(3)
        elif '大后天' in info:
            feedback=time_now(7)
        elif '后天' in info:
            feedback=time_now(5)
        elif '昨天' in info:
            feedback=time_now(9)
        elif '大前天' in info:
            feedback=time_now(13)
        elif '前天' in info:
            feedback=time_now(11)
    elif info == '时间' or info == '现在时间' or '几点了' in info or '现在几点' in info:
        feedback=time_now(14)
    elif info == '日期':
        feedback=time_now(15)
    elif '时间' in info and '日期' in info:
        feedback=time_now(16)
###########################################################################################
#chat
###########################################################################################
    chat_file=open("data/db/chat.txt","r")
    over=False
    answer=False
    Type=0
    while not over:
        chat_info=chat_file.readline().strip('\n')
        if chat_info=='':
            over=True
            break
        questions=chat_info[:chat_info.index('@')].split('#')
        answers=chat_info[chat_info.index('@')+1:].split('#')
        for i in range(0,len(questions)):
            if info == questions[i]:                
                answer=random.choice(answers)
                over=True
    chat_file.close()
    if answer:
        feedback = answer
    else:
        re_dirty_words=['不要说脏话,这显得你很low!','我已经警告过你了,请不要说脏话!','我TM的给TM的你TM的脸,你TM的别TM的给脸不要脸!']
        dirty_words_time=0
        dirty_words_file=open("data/db/dirty_words.txt","r")
        over=False
        while not over:
            dirty_words=dirty_words_file.readline().strip('\n')
            if dirty_words=='':
                over=True
                break
            if dirty_words in info:
                dirty_words_time_file=open("data/db/dirty_words_time.txt","r")
                dirty_words_time=int(dirty_words_time_file.readline().strip('\n'))
                feedback=re_dirty_words[dirty_words_time%len(re_dirty_words)]
                dirty_words_time+=1
                dirty_words_time_file.close()
                dirty_words_time_file=open("data/db/dirty_words_time.txt","w")
                dirty_words_time_file.write('%d'%dirty_words_time)
                dirty_words_time_file.close()
                over=True
        dirty_words_file.close()
###########################################################################################
#reminder
###########################################################################################
    if not feedback:
        if '提醒我' in info:
            event=info[info.index('提醒我')+6:]
            if event:
                remind='主人,该'+event+'了!'
                remind_file=open("data/db/reminder.txt","w")
                remind_file.write(remind)
                remind_file.close()
                when=info[:info.index('提醒我')]
                if when:
                    special_format=True
                    style_path_file=open("data/settings/style_path.txt","r")
                    style_path=style_path_file.read()
                    style_path_file.close()
                    href_file=open(style_path+"href.txt","r")
                    href=href_file.read()
                    href_file.close()
                    if '后'in when:
                        (h,m,s)=count_down(when)
                        h=int(h)
                        m=int(m)
                        s=int(s)
                        second=3600*h+60*m+s
                        thread.start_new_thread(reminder, (second,))
                        feedback ='<p style="font-family:Microsoft Yahei;font:24px">OK,不过在我提醒你之前你可不要关掉我哦,否则谁去提醒你?do,御坂耐心地说道<br><a style="text-decoration:none;color:#'+href+'" href="#">取消提醒</a></p>'
                    if not feedback:
                        exact_when=exact_time(when)
                        date=time.strftime("%Y%m%d", time.localtime())
                        whole_time=exact_when+date
                        second=time.mktime(time.strptime(whole_time,"%H:%M%Y%m%d"))-time.time()
                        thread.start_new_thread(reminder, (second,))
                        feedback ='<p style="font-family:Microsoft Yahei;font:24px">OK,不过在我提醒你之前你可不要关掉我哦,否则谁去提醒你?do,御坂耐心地说道<br><a style="text-decoration:none;color:#'+href+'" href="#">取消提醒</a></p>'
                else:
                    feedback="我没搞明白你让我什么时间提醒你,请用更清晰的表达再说一遍。"
            else:
                feedback="我没搞明白你让我提醒你做什么,请用更清晰的表达再说一遍。"
        else:
            shutdown=restart=False
            if '关机' in info:
                if '关机'==info:
                    subprocess.Popen('shutdown -s')
                    feedback='没时间告别了,再见~'
                    shutdown=False
                else:
                    when=info[:info.index('关机')]
                    shutdown=True
            elif '关电脑' in info:
                if '关电脑'==info:
                    subprocess.Popen('shutdown -s')
                    feedback='没时间告别了,再见~'
                    shutdown=False
                else:
                    when=info[:info.index('关电脑')]
                    shutdown=True
            elif '关闭计算机' in info:
                if '关闭计算机'==info:
                    subprocess.Popen('shutdown -s')
                    feedback='没时间告别了,再见~'
                    shutdown=False
                else:
                    when=info[:info.index('关闭计算机')]
                    shutdown=True
            elif '关闭电脑' in info:
                if '关闭电脑'==info:
                    subprocess.Popen('shutdown -s')
                    feedback='没时间告别了,再见~'
                    shutdown=False
                else:
                    when=info[:info.index('关闭电脑')]
                    shutdown=True
            if shutdown:
                special_format=True
                style_path_file=open("data/settings/style_path.txt","r")
                style_path=style_path_file.read()
                style_path_file.close()
                href_file=open(style_path+"href.txt","r")
                href=href_file.read()
                href_file.close()
                if '后'in when:
                    (h,m,s)=count_down(when)
                    h=int(h)
                    m=int(m)
                    s=int(s)
                    second=3600*h+60*m+s
                    subprocess.Popen('shutdown -a', shell=True)
                    subprocess.Popen('shutdown -s -t %d'%second, shell=True)
                    feedback ='<p style="font-family:Microsoft Yahei;font:24px">您的计算机将于'
                    if h!=0:
                        feedback +='%d小时'%h
                    if m!=0:
                        feedback +='%d分钟'%m
                    if s!=0:
                        feedback +='%d秒'%s            
                    feedback = feedback+'后关闭。do,御坂不舍地说道<br><a style="text-decoration:none;color:#'+href+'" href="#">取消关机</a></p>'
                if not feedback:
                    exact_when=exact_time(when)
                    date=time.strftime("%Y%m%d", time.localtime())
                    whole_time=exact_when+date
                    second=time.mktime(time.strptime(whole_time,"%H:%M%Y%m%d"))-time.time()
                    if second<0:
                        second+=86400
                    subprocess.Popen('shutdown -a', shell=True)        
                    subprocess.Popen('shutdown -s -t %d'%second, shell=True)
                    feedback ='<p style="font-family:Microsoft Yahei;font:24px">您的计算机将于'+exact_when+'关闭。do,御坂不舍地说道<br><a style="text-decoration:none;color:#'+href+'" href="#">取消关机</a></p>'
            else:
                if '重新启动' in info:
                    if '重新启动'==info:
                        subprocess.Popen('shutdown -r', shell=True)
                        feedback='放心吧,我们马上就会再见面的!'
                        restart=False
                    else:
                        when=info[:info.index('重新启动')]
                        restart=True
                elif '重启' in info:
                    if '重启'==info:
                        subprocess.Popen('shutdown -r', shell=True)
                        feedback='放心吧,我们马上就会再见面的!'
                        restart=False
                    else:
                        when=info[:info.index('重启')]
                        restart=True
                if restart:
                    special_format=True
                    style_path_file=open("data/settings/style_path.txt","r")
                    style_path=style_path_file.read()
                    style_path_file.close()
                    href_file=open(style_path+"href.txt","r")
                    href=href_file.read()
                    href_file.close()
                    if '后'in when:
                        (h,m,s)=count_down(when)
                        h=int(h)
                        m=int(m)
                        s=int(s)
                        second=3600*h+60*m+s
                        subprocess.Popen('shutdown -a', shell=True)
                        subprocess.Popen('shutdown -r -t %d'%second, shell=True)
                        feedback ='<p style="font-family:Microsoft Yahei;font:24px">您的计算机将于'
                        if h!=0:
                            feedback +='%d小时'%h
                        if m!=0:
                            feedback +='%d分钟'%m
                        if s!=0:
                            feedback +='%d秒'%s
                        feedback +='后重启。do,御坂不舍地说道<br><a style="text-decoration:none;color:#'+href+'" href="#">取消关机</a></p>'                                    
                    if not feedback:
                        exact_when=exact_time(when)
                        date=time.strftime("%Y%m%d", time.localtime())
                        whole_time=exact_when+date
                        second=time.mktime(time.strptime(whole_time,"%H:%M%Y%m%d"))-time.time()
                        if second<0:
                            second+=86400
                        subprocess.Popen('shutdown -a', shell=True)        
                        subprocess.Popen('shutdown -r -t %d'%second, shell=True)
                        feedback ='<p style="font-family:Microsoft Yahei;font:24px">您的计算机将于%s重启。do,御坂不舍地说道<br><a style="text-decoration:none;color:#'+href+'" href="#">取消关机</a></p>'%exact_when
                elif '注销'==info:
                    subprocess.Popen('shutdown -r', shell=True)
                    feedback='你还会回来的对吧?别离开太久,我会很想你的!'
                    logout=False
                elif '休眠'==info:
                    subprocess.Popen('powercfg -h on', shell=True)
                    subprocess.Popen('shutdown -h', shell=True)
                    feedback='冬天来了吗?嘛,不管了,我要休眠了……zzZ'
                    hibernation=False
                elif '睡眠'==info:
                    subprocess.Popen('powercfg -h off', shell=True)
                    subprocess.Popen('rundll32.exe powrprof.dll,SetSuspendState', shell=True)
                    subprocess.Popen('powercfg -h on', shell=True)
                    feedback ='……zzZ 啊?干嘛叫醒我?人家睡得正香呢!'
                elif '锁定'==info or '锁屏'==info or'锁定计算机'==info:
                    subprocess.Popen('rundll32 user32.dll,LockWorkStation', shell=True)
                    feedback ='钥匙拿了吗?那我可锁了啊!'

###########################################################################################
#wiki
###########################################################################################
    if not feedback:
        style_path_file=open("data/settings/style_path.txt","r")
        style_path=style_path_file.read().strip("style_sheets/")
        style_path_file.close()
        chat_file=open(style_path+"\\chat.txt","r")
        over=False
        answer=False
        Type=0
        while not over:
            chat_info=chat_file.readline().strip('\n')
            if chat_info=='':
                over=True
                break
            questions=chat_info[:chat_info.index('@')].split('#')
            answers=chat_info[chat_info.index('@')+1:].split('#')
            for i in range(0,len(questions)):
                if info == questions[i]:                
                    answer=random.choice(answers)
                    over=True
        chat_file.close()
        if answer:
            feedback = answer
    if info=="你好" or info=="嗨" or info=="哈喽" or info=="你好啊" or info=="您好":
        if "(" in current_theme and ")" in current_theme:
            feedback="你好,我叫大白,是你的私人健康助手"
    if "你是谁" in info or "你叫啥" in info or "你叫什么" in info or "叫什么名字" in info or "你的名字是什么" in info or "你叫啥名" in info:
        if "(" in current_theme and ")" in current_theme:
            feedback="你好,我叫大白,是你的私人健康助手"
        elif current_theme=="御坂10032号":
            feedback="我的名字是御坂,是姐姐大人的克隆体。"
        elif current_theme=="Stuart":
            feedback="我?Stuart!"
        elif current_theme=="哆啦A梦":
            feedback="我叫哆啦A梦,是一只来自22世纪的猫型机器人!"
    if "你多大了" in info or "你今年多大了" in info or "你几岁了" in info or "你今年几岁" in info or "你的年龄" in info:
        if "(" in current_theme and ")" in current_theme:
            feedback="就算我"+str(int(time.strftime("%Y", time.localtime()))-2014)+"岁吧!"
        elif current_theme=="御坂10032号":
            feedback="御坂今年14岁。"
        elif current_theme=="Stuart":
            feedback="你该看看电影《小黄人》在你们人类出现之前就有我们了!"
        elif current_theme=="哆啦A梦":
            feedback="我2112年出生,所以今年应该是"+str(int(time.strftime("%Y", time.localtime()))-2112)+"岁!"
    if "你的生日" in info or "你什么时候过生日" in info or "你啥时候生日" in info or "你的出生日期" in info or "你什么时候出生的" in info:
        if "(" in current_theme and ")" in current_theme:
            feedback="2014年11月07日 吧啦啦啦~"
        elif current_theme=="御坂10032号":
            feedback="御坂是克隆人,我已经不记得自己什么时候被制造出来了。我只知道姐姐大人的生日是5月2日。"
        elif current_theme=="Stuart":
            feedback="额...呵呵呵..."
        elif current_theme=="哆啦A梦":
            feedback="我是2112年9月3日出生的!"
    if "你是男的还是女的" in info or "你的性别" in info or "你是GG还是MM" in info or "你是妹子吗" in info or "你是汉子还是妹子" in info:
        if "(" in current_theme and ")" in current_theme:
            feedback="我的程序将我的声音设定为男性。"
        elif current_theme=="御坂10032号":
            feedback="御坂是妹妹。"
        elif current_theme=="Stuart":
            feedback="噗,我们貌似没有性别。啊哈哈哈哈!"
        elif current_theme=="哆啦A梦":
            feedback="我是公的!"
    if info=="扫描我" or info.lower()=="scan me":
        if "(" in current_theme and ")" in current_theme:
            feedback="扫描完成!你没有受到外伤,但是,你的荷尔蒙水平和神经递质都显示你有异常情绪波动,常见于青少年人群,症状鉴定:青春期躁动。直到你说“我很满意你的照顾”,我才会结束工作。"
        elif current_theme=="御坂10032号":
            feedback="用我的眼罩吗?"
        elif current_theme=="Stuart":
            feedback="我长那么大的眼睛可不是用来干这个的!"
        else:
            feedback="喂,看清楚了,我又不是大白!"
    if info=="我很满意你的照顾" or info=="我对你的照顾很满意":
        if "(" in current_theme and ")" in current_theme:
            quit()
        elif current_theme=="哆啦A梦":
            feedback="虽然我也是个机器人,但我的使命是让你幸福,在此之前我是不可能离开你的!"
        elif current_theme=="Stuart":
            feedback="谢谢主人!(内心:这个主人也太不卑鄙了,和Gru差远了!)"
        elif current_theme=="御坂10032号":
            feedback="...御坂哪里做的不好吗?"
    if "唱首歌" in info or "唱个歌" in info or "唱歌" in info:
        if current_theme=="Stuart":
            feedback="@sing"
            special_format=True
        elif current_theme=="御坂10032号":
            feedback="小黄人唱歌特别好听,我不骗你,真的!"
        elif current_theme=="哆啦A梦":
            feedback="我们中就小黄人出过专辑!你快去让他给你唱一首吧!"
        else:
            feedback="很抱歉我不会唱歌,不过我听说小黄人个个都是天生的歌手!"
    if info=="任意门" or info=="随意门":
        if current_theme=="哆啦A梦":
            fb=["","前"]
            zeros=["0","00","000"]
            feedback="欢迎来到公元"+random.choice(fb)+str(random.randint(1,99))+random.choice(zeros)+"年"
        elif current_theme=="Stuart":
            feedback="我只听说过红绿色盲,你竟然是黄蓝色盲!呵呵呵!"
        elif current_theme=="御坂10032号":
            feedback="御坂的能力是缺陷电气(Radio Noise),并不能制造你所说的任意门。"
        elif "(" in current_theme and ")" in current_theme:
            feedback="我是白胖子,不是蓝胖子!上一个我就被困在“任意门”中了,你忘了吗?"
    if not feedback:
        try:
            feedback = movie(info)
        except:
            pass
        if feedback:
            special_format=True
    if not feedback:
        try:
            feedback = zhidao(info)
        except:
            pass
    if not feedback:
        try:
            feedback = wiki(info)
        except:
            pass
        if feedback:
            special_format=True
    if not feedback:
        if info[-4:]=="是谁":
            info1=info[:-4]
            try:
                feedback = wiki(info1)
            except:
                pass
            if feedback:
                special_format=True
        elif info[:4]=="谁是":
            info1=info[4:]
            try:
                feedback = wiki(info1)
            except:
                pass
            if feedback:
                special_format=True
    if not feedback or feedback=='<p style="font-family:Microsoft Yahei;font:24px">请检查您的网络连接</p>'or feedback=='请检查您的网络连接':
        temp = None
        temp = blur(info,q)
        if temp:
            feedback=temp
    if not feedback:
        style_path_file=open("data/settings/style_path.txt","r")
        style_path=style_path_file.read()
        style_path_file.close()
        href_file=open(style_path+"href.txt","r")
        href=href_file.read()
        href_file.close()
        feedback = '不知道“'+origin_info+'”是什么意思,你可以<a style="text-decoration:none;color:#'+href+'"href="http://www.baidu.com/baidu?word='+origin_info+'">百度一下</a>'
    if special_format:
        feedback = '<p style="font-family:Microsoft Yahei;font:24px">'+current_theme+':</p>'+feedback
    else:
        style_path_file=open("data/settings/style_path.txt","r")
        style_path=style_path_file.read().strip("style_sheets/")
        style_path_file.close()
        tag_file=open(style_path+"\\tag.txt","r")
        tag=tag_file.read().split("\n")
        feedback = '<p style="font-family:Microsoft Yahei;font:24px">'+current_theme+':'+feedback+random.choice(tag)+'</p>'
    return feedback