示例#1
0
    def draw_image(self):
        if not self.needs_refresh:
            return
        self.needs_refresh = False
        w, h = (self.w, self.h)
        clearws()
        setwindow(0, self.w, 0, self.h)
        setviewport(0, 1, 0, 1)

        setbackgroundcolor(1, 1, 1, 0)
        vertices, normals = triangulate(data, \
          (1.0/64, 1.0/64, 1.0/128), (-0.5, -0.5, -0.5), self.isolevel)
        mesh = createmesh(len(vertices)*3, vertices, normals, \
          ones(vertices.shape))
        drawmesh(mesh, 1, (0,0,0), (0,0,1), (0,1,0), (1,1,1), (1,1,1))
        center = spherical_to_cartesian(-2, pi*self.y/self.h+pi/2, pi*self.x/self.w)
        up = spherical_to_cartesian(1, pi*self.y/self.h+pi, pi*self.x/self.w)
        cameralookat(center[0], center[1], -0.25+center[2], 0, 0, -0.25, up[0], up[1], up[2])
        drawimage(0, self.w, 0, self.h, \
          self.w, self.h, GR3_Drawable.GR3_DRAWABLE_GKS)
        if self.export:
            export("mri.html", 800, 800)
            print("Saved current isosurface to mri.html")
            self.export = False
        clear()
        deletemesh(c_int(mesh.value))
示例#2
0
    def draw_image(self):
        w, h = (self.w, self.h)
        clearws()
        setwindow(0, self.w, 0, self.h)
        setviewport(0, 1, 0, 1)

        setbackgroundcolor(1, 1, 1, 0)
        vertices, normals = triangulate(data, \
          (1.0/64, 1.0/64, 1.0/128), (-0.5, -0.5, -0.5), self.isolevel)
        mesh = createmesh(len(vertices)*3, vertices, normals, \
          ones(vertices.shape))
        drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 1, 1),
                 (1, 1, 1))
        center = spherical_to_cartesian(-2, pi * self.y / self.h + pi / 2,
                                        pi * self.x / self.w)
        up = spherical_to_cartesian(1, pi * self.y / self.h + pi,
                                    pi * self.x / self.w)
        cameralookat(center[0], center[1], -0.25 + center[2], 0, 0, -0.25,
                     up[0], up[1], up[2])
        drawimage(0, self.w, 0, self.h, \
          self.w, self.h, GR3_Drawable.GR3_DRAWABLE_GKS)
        if self.export:
            export("mri.html", 800, 800)
            print("Saved current isosurface to mri.html")
            self.export = False
        clear()
        deletemesh(c_int(mesh.value))
示例#3
0
    def draw_image(self):
        if not self.needs_refresh:
            return
        self.needs_refresh = False
        gr.clearws()
        gr.setwindow(0, self.w, 0, self.h)
        gr.setviewport(0, 1, 0, 1)

        gr3.setbackgroundcolor(1, 1, 1, 0)
        vertices, normals = gr3.triangulate(data,
                                            (1.0 / 64, 1.0 / 64, 1.0 / 128),
                                            (-0.5, -0.5, -0.5), self.isolevel)
        mesh = gr3.createmesh(
            len(vertices) * 3, vertices, normals, np.ones(vertices.shape))
        gr3.drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 1, 1),
                     (1, 1, 1))
        center = spherical_to_cartesian(-2,
                                        np.pi * self.y / self.h + np.pi / 2,
                                        np.pi * self.x / self.w)
        up = spherical_to_cartesian(1, np.pi * self.y / self.h + np.pi,
                                    np.pi * self.x / self.w)
        gr3.cameralookat(center[0], center[1], -0.25 + center[2], 0, 0, -0.25,
                         up[0], up[1], up[2])
        gr3.drawimage(0, self.w, 0, self.h, self.w, self.h,
                      gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
        if self.export:
            gr3.export("mri.html", 800, 800)
            print("Saved current isosurface to mri.html")
            self.export = False
        gr3.clear()
        gr3.deletemesh(c_int(mesh.value))
示例#4
0
    def set_camera(self, width, height):
        """
        Update the shown scene after the perspective has changed.
        """
        rightt = self.mat[:3, 0]
        upt = self.mat[:3, 1]
        pt = self.mat[:3, 2] * self.d
        t = self.mat[:3, 3]

        self.proj_mat = create_perspective_projection_matrix(np.radians(self.fov), 1. * width / height, self.near, self.far)
        gr3.setcameraprojectionparameters(self.fov, self.near, self.far)
        self.lookat_mat = create_look_at_matrix(pt + t, t, upt)
        gr3.cameralookat(pt[0] + t[0], pt[1] + t[1], pt[2] + t[2], t[0], t[1], t[2], upt[0], upt[1], upt[2])
示例#5
0
def _plot_iso(v):
    global _plt
    viewport = _plt.kwargs['viewport']
    if viewport[3] - viewport[2] < viewport[1] - viewport[0]:
        width = viewport[3] - viewport[2]
        center_x = 0.5 * (viewport[0] + viewport[1])
        x_min = max(center_x - 0.5 * width, viewport[0])
        x_max = min(center_x + 0.5 * width, viewport[1])
        y_min = viewport[2]
        y_max = viewport[3]
    else:
        height = viewport[1] - viewport[0]
        center_y = 0.5 * (viewport[2] + viewport[3])
        x_min = viewport[0]
        x_max = viewport[1]
        y_min = max(center_y - 0.5 * height, viewport[2])
        y_max = min(center_y + 0.5 * height, viewport[3])

    gr.selntran(0)
    usable_vs = v[np.abs(v) != np.inf]
    if np.prod(usable_vs.shape) == 0:
        return
    v_max = usable_vs.max()
    v_min = usable_vs.min()
    if v_min == v_max:
        return
    uint16_max = np.iinfo(np.uint16).max
    v = (np.clip(v, v_min, v_max) - v_min) / (v_max - v_min) * uint16_max
    values = v.astype(np.uint16)
    nx, ny, nz = v.shape
    isovalue = _plt.kwargs.get('isovalue', 0.5)
    rotation = np.radians(_plt.kwargs.get('rotation', 40))
    tilt = np.radians(_plt.kwargs.get('tilt', 70))
    gr3.clear()
    mesh = gr3.createisosurfacemesh(values,
                                    (2 / (nx - 1), 2 / (ny - 1), 2 / (nz - 1)),
                                    (-1., -1., -1.),
                                    int(isovalue * uint16_max))
    color = _plt.kwargs.get('color', (0.0, 0.5, 0.8))
    gr3.setbackgroundcolor(1, 1, 1, 0)
    gr3.drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), color, (1, 1, 1))
    r = 2.5
    gr3.cameralookat(r * np.sin(tilt) * np.sin(rotation), r * np.cos(tilt),
                     r * np.sin(tilt) * np.cos(rotation), 0, 0, 0, 0, 1, 0)
    gr3.drawimage(x_min, x_max, y_min, y_max, 500, 500,
                  gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr3.deletemesh(mesh)
    gr.selntran(1)
示例#6
0
def _plot_iso(v):
    global _plt
    viewport = _plt.kwargs['viewport']
    if viewport[3] - viewport[2] < viewport[1] - viewport[0]:
        width = viewport[3] - viewport[2]
        center_x = 0.5 * (viewport[0] + viewport[1])
        x_min = max(center_x - 0.5 * width, viewport[0])
        x_max = min(center_x + 0.5 * width, viewport[1])
        y_min = viewport[2]
        y_max = viewport[3]
    else:
        height = viewport[1] - viewport[0]
        center_y = 0.5 * (viewport[2] + viewport[3])
        x_min = viewport[0]
        x_max = viewport[1]
        y_min = max(center_y - 0.5 * height, viewport[2])
        y_max = min(center_y + 0.5 * height, viewport[3])

    gr.selntran(0)
    usable_vs = v[np.abs(v) != np.inf]
    if np.prod(usable_vs.shape) == 0:
        return
    v_max = usable_vs.max()
    v_min = usable_vs.min()
    if v_min == v_max:
        return
    uint16_max = np.iinfo(np.uint16).max
    v = (np.clip(v, v_min, v_max) - v_min) / (v_max - v_min) * uint16_max
    values = v.astype(np.uint16)
    nx, ny, nz = v.shape
    isovalue = _plt.kwargs.get('isovalue', 0.5)
    rotation = np.radians(_plt.kwargs.get('rotation', 40))
    tilt = np.radians(_plt.kwargs.get('tilt', 70))
    gr3.clear()
    mesh = gr3.createisosurfacemesh(values, (2/(nx-1), 2/(ny-1), 2/(nz-1)),
                                    (-1., -1., -1.),
                                    int(isovalue * uint16_max))
    color = _plt.kwargs.get('color', (0.0, 0.5, 0.8))
    gr3.setbackgroundcolor(1, 1, 1, 0)
    gr3.drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), color, (1, 1, 1))
    r = 2.5
    gr3.cameralookat(r*np.sin(tilt)*np.sin(rotation), r*np.cos(tilt), r*np.sin(tilt)*np.cos(rotation), 0, 0, 0, 0, 1, 0)
    gr3.drawimage(x_min, x_max, y_min, y_max, 500, 500, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr3.deletemesh(mesh)
    gr.selntran(1)
示例#7
0
def display():
    global window_width, window_height, rx
    gr3.setbackgroundcolor(1, 1, 1, 1)
    # set up camera
    gr3.setcameraprojectionparameters(45, 1, 200)
    gr3.cameralookat(10 * math.cos(-rx * math.pi / 2),
                     10 * math.sin(-rx * math.pi / 2), 0, 0, 0, 0, 0, 0, 1)

    gr3.drawimage(0, window_width, 0, window_height, window_width,
                  window_height, gr3.GR3_Drawable.GR3_DRAWABLE_OPENGL)
    glViewport(0, 0, window_width, window_height)
    glDisable(GL_LIGHTING)
    glDisable(GL_DEPTH_TEST)
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glLoadIdentity()
    glMatrixMode(GL_PROJECTION)
    glPushMatrix()
    glLoadIdentity()
    glColor4f(1, 0, 0, 1)
    x, y = 0, 0.22
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"This is a GLUT window in which GR3 renders":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
    y -= 0.05
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"a scene. You can drag the mouse to rotate the":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
    y -= 0.05
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"molecule or right-click to open a context menu.":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_LIGHTING)
    glMatrixMode(GL_MODELVIEW)
    glPopMatrix()
    glMatrixMode(GL_PROJECTION)
    glPopMatrix()
    glutSwapBuffers()
    gr.clearws()
    selntran(0)
    gr3.setquality(4)
    gr3.drawimage(0, 0.5, 0.5, 1, 250, 250, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.settextcolorind(1)
    gr.settextfontprec(6, 0)

    x = list(range(5))
    y = list(range(5))

    nominalWindowHeight = 500.0
    pointSize = (8, 9, 10, 11, 12, 14, 18, 24, 36)
    s = "i\\hbar\\frac{\\partial\\psi}{\\partial t} = \\frac{\\hbar^2}{2m}\\nabla^2\\psi + V(\\mathbf{r})\\psi"
    x = 0.9
    y = 0.9
    gr.settextalign(3, 3)
    for i in range(8):
        gr.setcharheight(pointSize[i] / nominalWindowHeight)
        gr.mathtex(x, y, s)
        y -= 4 * pointSize[i] / nominalWindowHeight

    gr.setcharheight(0.1)
    gr.mathtex(0.9, 0.05, "Hello World!")
    gr.settextcolorind(8)
    gr.text(0.9, 0.05, "Hello World!")

    gr.updatews()

    gr3.setcameraprojectionparameters(45, 1, 200)
    gr3.cameralookat(10 * math.cos(-rx * math.pi / 2),
                     10 * math.sin(-rx * math.pi / 2), 0, 0, 0, 0, 0, 0, 1)
示例#8
0
l1 = 1.2  # length of rods
l2 = 1.0
m1 = 1.0  # weights of bobs
m2 = 1.5
t1 = 100.0  # inintial angles
t2 = -20.0

w1 = 0.0
w2 = 0.0
t = 0
dt = 0.04
state = array([t1, w1, t2, w2]) * pi / 180

gr3.init()
gr3.setcameraprojectionparameters(45, 1, 100)
gr3.cameralookat(6, -2, 4, 0, -2, 0, 0, 1, 0)
gr3.setbackgroundcolor(1, 1, 1, 1)
gr3.setlightdirection(1, 1, 10)

now = perf_counter()

while t < 30:
    start = now

    t, state = rk4(t, dt, state, pendulum_derivs)
    t1, w1, t2, w2 = state
    double_pendulum([t1, t2], [l1, l2], [m1, m2])

    now = perf_counter()
    if start + dt > now:
        time.sleep(start + dt - now)
示例#9
0
    np.save(filename+'.npy', filedata)
print('Done.')

positions = filedata[:, :3].astype(np.int32)
directions = filedata[:, 3:].astype(np.float32)

# define the values used for calculating the isosurface and the isolevel
isovalue = 0
values = directions[:, 2]

# negate the values, as we want negative z to define "inside"
isovalue = -isovalue
values = -values

# transform the values to the range [0, 1]
isovalue -= values.min()
values -= values.min()
isovalue /= values.max()
values /= values.max()

# write them into a contiguous array
nx, ny, nz = positions.max(axis=0)+1
data = np.zeros((nx, ny, nz), np.float32)
ix, iy, iz = positions.T
data[ix, iy, iz] = values

# write out an HTML file
gr3.cameralookat(0, 0, 2, 0, 0, 0, 0, 1, 0)
gr3.drawisosurfacemesh(data, isovalue=isovalue, step=[2.0/(nx-1), 2.0/(ny-1), 2.0/(nz-1)], offset=[-1, -1, -1], position=(0, 0, 0))
gr3.export("output.html", 1024, 1024)
示例#10
0
directions = filedata[:, 3:].astype(np.float32)

# define the values used for calculating the isosurface and the isolevel
isovalue = 0
values = directions[:, 2]

# negate the values, as we want negative z to define "inside"
isovalue = -isovalue
values = -values

# transform the values to the range [0, 1]
isovalue -= values.min()
values -= values.min()
isovalue /= values.max()
values /= values.max()

# write them into a contiguous array
nx, ny, nz = positions.max(axis=0) + 1
data = np.zeros((nx, ny, nz), np.float32)
ix, iy, iz = positions.T
data[ix, iy, iz] = values

# write out an HTML file
gr3.cameralookat(0, 0, 2, 0, 0, 0, 0, 1, 0)
gr3.drawisosurfacemesh(data,
                       isovalue=isovalue,
                       step=[2.0 / (nx - 1), 2.0 / (ny - 1), 2.0 / (nz - 1)],
                       offset=[-1, -1, -1],
                       position=(0, 0, 0))
gr3.export("output.html", 1024, 1024)
示例#11
0
    gr.settextcolorind(2)
    gr.textext(0.05, 0.08, 'y_{A}:%6.2f' % acceleration)
    gr.updatews()
    return

theta = 110.0  # initial angle
gamma = 0.1    # damping coefficient
L = 1          # pendulum length

t = 0
dt = 0.04
state = array([theta * pi / 180, 0])

gr3.init()
gr3.setcameraprojectionparameters(45, 1, 100)
gr3.cameralookat(0, -2, 6, 0, -2, 0, 0, 1, 0)
gr3.setbackgroundcolor(1, 1, 1, 1)
gr3.setlightdirection(1, 1, 10)
 
now = time.clock()

while t < 30:
    start = now

    t, state = rk4(t, dt, state, damped_pendulum_deriv)
    theta, omega = state
    acceleration = sqrt(2 * g * L * (1 - cos(theta)))
    pendulum(t, theta, omega, acceleration)
    
    now = time.clock()
    if start + dt > now:
示例#12
0
文件: mogli.py 项目: li012589/mogli
def _set_gr3_camera():
    """ Set the GR3 camera, using the global _camera variable. """
    eye, center, up = _camera
    gr3.cameralookat(eye[0], eye[1], eye[2],
                     center[0], center[1], center[2],
                     up[0], up[1], up[2])
示例#13
0
def display():
    global window_width, window_height, rx
    gr3.setbackgroundcolor(1,1,1,1)
    # Kamera einstellen
    gr3.setcameraprojectionparameters(45, 1, 200)
    gr3.cameralookat(10*math.cos(-rx*math.pi/2), 10*math.sin(-rx*math.pi/2), 0, 0, 0, 0, 0, 0, 1)

    gr3.drawimage(0, window_width, 0, window_height, window_width, window_height, gr3.GR3_Drawable.GR3_DRAWABLE_OPENGL)
    glViewport(0,0,window_width,window_height);
    glDisable(GL_LIGHTING)
    glDisable(GL_DEPTH_TEST)
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glLoadIdentity()
    glMatrixMode(GL_PROJECTION)
    glPushMatrix()
    glLoadIdentity()
    glColor4f(1,0,0,1)
    x, y = 0, 0.22
    glRasterPos2f(x*2-1,y*2-1)
    for c in u"Dies ist ein GLUT-Fenster, in dem mit GR3 eine":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,ord(c))
    y-=0.05
    glRasterPos2f(x*2-1,y*2-1)
    for c in u"Szene gerendert wird. Mit der Maus kann man":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,ord(c))
    y-=0.05
    glRasterPos2f(x*2-1,y*2-1)
    for c in u"das dargestellte Molekül rotieren lassen.":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,ord(c))
    y-=0.04
    glRasterPos2f(x*2-1,y*2-1)
    for c in u"(Rechtsklick öffnet das Kontextmenü)":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,ord(c))
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_LIGHTING)
    glMatrixMode(GL_MODELVIEW)
    glPopMatrix()
    glMatrixMode(GL_PROJECTION)
    glPopMatrix()
    glutSwapBuffers()
    gr.clearws()
    selntran(0)
    gr3.setquality(4)
    gr3.drawimage(0, 0.5, 0.5, 1, 250, 250, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.settextcolorind(1)
    gr.settextfontprec(6,0)
    
    x = list(range(5))
    y = list(range(5))
    
    nominalWindowHeight = 500.0
    pointSize = ( 8, 9, 10, 11, 12, 14, 18, 24, 36 )
    s = "i\\hbar\\frac{\\partial\\psi}{\\partial t} = \\frac{\\hbar^2}{2m}\\nabla^2\\psi + V(\\mathbf{r})\\psi"
    x = 0.9
    y = 0.9;
    gr.settextalign(3, 3)
    for i in range(8):
        gr.setcharheight(pointSize[i] / nominalWindowHeight)
        gr.mathtex(x, y, s)
        y -= 4 * pointSize[i] / nominalWindowHeight
    
    gr.setcharheight(0.1)
    gr.mathtex(0.9, 0.05, "Hello World!")
    gr.settextcolorind(8)
    gr.text(0.9, 0.05, "Hello World!")

    gr.updatews()
    
    gr3.setcameraprojectionparameters(45, 1, 200)
    gr3.cameralookat(10*math.cos(-rx*math.pi/2), 10*math.sin(-rx*math.pi/2), 0, 0, 0, 0, 0, 0, 1)
示例#14
0
    def initCamera(self, matrix):

        if self.camera is None:

            self.camera = Camera(matrix)
            gr3.cameralookat(self.camera.matrix)
示例#15
0
def draw(mesh, x=None, y=None, z=None):
    gr3.clear()
    gr3.drawmesh(mesh, 1, (0,0,0), (0,0,1), (0,1,0), (1,1,1), (1,1,1))
    gr3.drawslicemeshes(data,  x=x, y=y, z=z)
    gr.clearws()
    gr3.drawimage(0, 1, 0, 1, 500, 500, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.updatews()

data = np.fromfile("mri.raw", np.uint16)
data = data.reshape((64, 64, 93))
data[data > 2000] = 2000
data[:, :, :] = data / 2000.0 * np.iinfo(np.uint16).max

gr.setviewport(0, 1, 0, 1)
gr3.init()
gr3.cameralookat(-3, 2, -2, 0, 0, 0, 0, 0, -1)
mesh = gr3.createisosurfacemesh(data, isolevel=40000)

gr.setcolormap(1)
for z in np.linspace(0, 1, 300):
    draw(mesh, x=0.9, z=z)
for y in np.linspace(1, 0.5, 300):
    draw(mesh, x=0.9, y=y, z=1)
gr.setcolormap(19)
for x in np.linspace(0.9, 0, 300):
    draw(mesh, x=x, y=0.5, z=1)
for x in np.linspace(0, 0.9, 300):
    draw(mesh, x=x, z=1)

gr3.terminate()
示例#16
0
def _set_gr3_camera():
    """ Set the GR3 camera, using the global _camera variable. """
    eye, center, up = _camera
    gr3.cameralookat(eye[0], eye[1], eye[2],
                     center[0], center[1], center[2],
                     up[0], up[1], up[2])
示例#17
0
文件: glut_ex.py 项目: kaigaox/gr
def display():
    global window_width, window_height, rx
    gr3.setbackgroundcolor(1, 1, 1, 1)
    # Kamera einstellen
    gr3.setcameraprojectionparameters(45, 1, 200)
    gr3.cameralookat(10 * math.cos(-rx * math.pi / 2),
                     10 * math.sin(-rx * math.pi / 2), 0, 0, 0, 0, 0, 0, 1)

    gr3.drawimage(0, window_width, 0, window_height, window_width,
                  window_height, gr3.GR3_Drawable.GR3_DRAWABLE_OPENGL)
    glViewport(0, 0, window_width, window_height)
    glDisable(GL_LIGHTING)
    glDisable(GL_DEPTH_TEST)
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glLoadIdentity()
    glMatrixMode(GL_PROJECTION)
    glPushMatrix()
    glLoadIdentity()
    glColor4f(1, 0, 0, 1)
    x, y = 0, 0.22
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"Dies ist ein GLUT-Fenster, in dem mit GR3 eine":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
    y -= 0.05
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"Szene gerendert wird. Mit der Maus kann man":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
    y -= 0.05
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"das dargestellte Molekül rotieren lassen.":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
    y -= 0.04
    glRasterPos2f(x * 2 - 1, y * 2 - 1)
    for c in u"(Rechtsklick öffnet das Kontextmenü)":
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, ord(c))
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_LIGHTING)
    glMatrixMode(GL_MODELVIEW)
    glPopMatrix()
    glMatrixMode(GL_PROJECTION)
    glPopMatrix()
    glutSwapBuffers()
    gr.clearws()
    selntran(0)
    gr3.setquality(4)
    gr3.drawimage(0, 0.5, 0.5, 1, 250, 250, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.settextcolorind(1)
    gr.settextfontprec(6, 0)

    x = list(range(5))
    y = list(range(5))

    nominalWindowHeight = 500.0
    pointSize = (8, 9, 10, 11, 12, 14, 18, 24, 36)
    s = "i\\hbar\\frac{\\partial\\psi}{\\partial t} = \\frac{\\hbar^2}{2m}\\nabla^2\\psi + V(\\mathbf{r})\\psi"
    x = 0.9
    y = 0.9
    gr.settextalign(3, 3)
    for i in range(8):
        gr.setcharheight(pointSize[i] / nominalWindowHeight)
        gr.mathtex(x, y, s)
        y -= 4 * pointSize[i] / nominalWindowHeight

    gr.setcharheight(0.1)
    gr.mathtex(0.9, 0.05, "Hello World!")
    gr.settextcolorind(8)
    gr.text(0.9, 0.05, "Hello World!")

    gr.updatews()

    gr3.setcameraprojectionparameters(45, 1, 200)
    gr3.cameralookat(10 * math.cos(-rx * math.pi / 2),
                     10 * math.sin(-rx * math.pi / 2), 0, 0, 0, 0, 0, 0, 1)
示例#18
0
    gr.textext(0.05, 0.08, 'y_{A}:%6.2f' % acceleration)
    gr.updatews()
    return


theta = 110.0  # initial angle
gamma = 0.1  # damping coefficient
L = 1  # pendulum length

t = 0
dt = 0.04
state = array([theta * pi / 180, 0])

gr3.init()
gr3.setcameraprojectionparameters(45, 1, 100)
gr3.cameralookat(0, -2, 6, 0, -2, 0, 0, 1, 0)
gr3.setbackgroundcolor(1, 1, 1, 1)
gr3.setlightdirection(1, 1, 10)

now = time.clock()

while t < 30:
    start = now

    t, state = rk4(t, dt, state, damped_pendulum_deriv)
    theta, omega = state
    acceleration = sqrt(2 * g * L * (1 - cos(theta)))
    pendulum(t, theta, omega, acceleration)

    now = time.clock()
    if start + dt > now:
示例#19
0
    gr3.drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 1, 1),
                 (1, 1, 1))
    gr3.drawslicemeshes(data, x=x, y=y, z=z)
    gr.clearws()
    gr3.drawimage(0, 1, 0, 1, 500, 500, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.updatews()


data = np.fromfile("mri.raw", np.uint16)
data = data.reshape((64, 64, 93))
data[data > 2000] = 2000
data[:, :, :] = data / 2000.0 * np.iinfo(np.uint16).max

gr.setviewport(0, 1, 0, 1)
gr3.init()
gr3.cameralookat(-3, 2, -2, 0, 0, 0, 0, 0, -1)
mesh = gr3.createisosurfacemesh(data, isolevel=40000)

gr.setcolormap(1)
for z in np.linspace(0, 1, 300):
    draw(mesh, x=0.9, z=z)
for y in np.linspace(1, 0.5, 300):
    draw(mesh, x=0.9, y=y, z=1)
gr.setcolormap(19)
for x in np.linspace(0.9, 0, 300):
    draw(mesh, x=x, y=0.5, z=1)
for x in np.linspace(0, 0.9, 300):
    draw(mesh, x=x, z=1)

gr3.terminate()