Пример #1
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))
Пример #2
0
def show(molecule,
         width=500,
         height=500,
         show_bonds=True,
         bonds_method='radii',
         bonds_param=None,
         camera=None,
         title='mogli'):
    """
    Interactively show the given molecule with OpenGL. By default, bonds are
    drawn, if this is undesired the show_bonds parameter can be set to False.
    For information on the bond calculation, see Molecule.calculate_bonds.
    If you pass a tuple of camera position, center of view and an up vector to
    the camera parameter, the camera will be set accordingly. Otherwise the
    molecule will be viewed in the direction of the z axis, with the y axis
    pointing upward.
    """
    global _camera
    molecule.positions -= np.mean(molecule.positions, axis=0)
    max_atom_distance = np.max(la.norm(molecule.positions, axis=1))
    if show_bonds:
        molecule.calculate_bonds(bonds_method, bonds_param)

    # If GR3 was initialized earlier, it would use a different context, so
    # it will be terminated first.
    gr3.terminate()

    # Initialize GLFW and create an OpenGL context
    glfw.init()
    glfw.window_hint(glfw.SAMPLES, 16)
    window = glfw.create_window(width, height, title, None, None)
    glfw.make_context_current(window)
    glEnable(GL_MULTISAMPLE)

    # Set up the camera (it will be changed during mouse rotation)
    if camera is None:
        camera_distance = -max_atom_distance * 2.5
        camera = ((0, 0, camera_distance), (0, 0, 0), (0, 1, 0))
    camera = np.array(camera)
    _camera = camera

    # Create the GR3 scene
    gr3.setbackgroundcolor(255, 255, 255, 0)
    _create_gr3_scene(molecule, show_bonds)
    # Configure GLFW
    glfw.set_cursor_pos_callback(window, _mouse_move_callback)
    glfw.set_mouse_button_callback(window, _mouse_click_callback)
    glfw.swap_interval(1)
    # Start the GLFW main loop
    while not glfw.window_should_close(window):
        glfw.poll_events()
        width, height = glfw.get_window_size(window)
        glViewport(0, 0, width, height)
        _set_gr3_camera()
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        gr3.drawimage(0, width, 0, height, width, height,
                      gr3.GR3_Drawable.GR3_DRAWABLE_OPENGL)
        glfw.swap_buffers(window)
    glfw.terminate()
    gr3.terminate()
Пример #3
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))
Пример #4
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))
Пример #5
0
def double_pendulum(theta, length, mass):
    gr.clearws()
    gr.setviewport(0, 1, 0, 1)

    direction = []
    position = [(0, 0, 0)]
    for i in range(2):
        direction.append(
            (sin(theta[i]) * length[i] * 2, -cos(theta[i]) * length[i] * 2, 0))
        position.append([position[-1][j] + direction[-1][j] for j in range(3)])

    gr3.clear()
    # draw pivot point
    gr3.drawcylindermesh(1, (0, 0.2, 0), (0, 1, 0), (0.4, 0.4, 0.4), 0.4, 0.05)
    gr3.drawcylindermesh(1, (0, 0.2, 0), (0, -1, 0), (0.4, 0.4, 0.4), 0.05,
                         0.2)
    gr3.drawspheremesh(1, (0, 0, 0), (0.4, 0.4, 0.4), 0.05)
    # draw rods
    gr3.drawcylindermesh(2, position, direction, (0.6, 0.6, 0.6) * 2,
                         (0.05, 0.05), [l * 2 for l in length])
    # draw bobs
    gr3.drawspheremesh(2, position[1:], (1, 1, 1) * 2, [m * 0.2 for m in mass])

    gr3.drawimage(0, 1, 0, 1, 500, 500, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.updatews()
    return
Пример #6
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()
Пример #7
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()
Пример #8
0
def show(molecule, width=500, height=500,
         show_bonds=True, bonds_method='radii', bonds_param=None,
         camera=None, title='mogli'):
    """
    Interactively show the given molecule with OpenGL. By default, bonds are
    drawn, if this is undesired the show_bonds parameter can be set to False.
    For information on the bond calculation, see Molecule.calculate_bonds.
    If you pass a tuple of camera position, center of view and an up vector to
    the camera parameter, the camera will be set accordingly. Otherwise the
    molecule will be viewed in the direction of the z axis, with the y axis
    pointing upward.
    """
    global _camera
    molecule.positions -= np.mean(molecule.positions, axis=0)
    max_atom_distance = np.max(la.norm(molecule.positions, axis=1))
    if show_bonds:
        molecule.calculate_bonds(bonds_method, bonds_param)

    # If GR3 was initialized earlier, it would use a different context, so
    # it will be terminated first.
    gr3.terminate()

    # Initialize GLFW and create an OpenGL context
    glfw.init()
    glfw.window_hint(glfw.SAMPLES, 16)
    window = glfw.create_window(width, height, title, None, None)
    glfw.make_context_current(window)
    glEnable(GL_MULTISAMPLE)

    # Set up the camera (it will be changed during mouse rotation)
    if camera is None:
        camera_distance = -max_atom_distance*2.5
        camera = ((0, 0, camera_distance),
                  (0, 0, 0),
                  (0, 1, 0))
    camera = np.array(camera)
    _camera = camera

    # Create the GR3 scene
    gr3.setbackgroundcolor(255, 255, 255, 0)
    _create_gr3_scene(molecule, show_bonds)
    # Configure GLFW
    glfw.set_cursor_pos_callback(window, _mouse_move_callback)
    glfw.set_mouse_button_callback(window, _mouse_click_callback)
    glfw.swap_interval(1)
    # Start the GLFW main loop
    while not glfw.window_should_close(window):
        glfw.poll_events()
        width, height = glfw.get_window_size(window)
        glViewport(0, 0, width, height)
        _set_gr3_camera()
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        gr3.drawimage(0, width, 0, height,
                      width, height, gr3.GR3_Drawable.GR3_DRAWABLE_OPENGL)
        glfw.swap_buffers(window)
    glfw.terminate()
    gr3.terminate()
Пример #9
0
 def paint(self, width, height, usecurrentframebuffer=None, device_pixel_ratio=1):
     """
     Refresh the OpenGL scene.
     """
     self.width = width
     self.height = height
     self.set_camera(width, height)
     if usecurrentframebuffer is not None:
         self.usecurrentframebuffer = usecurrentframebuffer
     if self.usecurrentframebuffer:
         gr3.usecurrentframebuffer()
     gr3.drawimage(0, width*device_pixel_ratio, 0, height*device_pixel_ratio,
                   width, height, gr3.GR3_Drawable.GR3_DRAWABLE_OPENGL)
Пример #10
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)
Пример #11
0
def pendulum(t, theta, omega, acceleration):
    gr.clearws()
    gr.setviewport(0, 1, 0, 1)

    x, y = (sin(theta) * 3.0, -cos(theta) * 3.0)

    gr3.clear()
    # draw pivot point
    gr3.drawspheremesh(1, (0, 0, 0), (0.4, 0.4, 0.4), 0.1)
    # draw rod
    gr3.drawcylindermesh(1, (0, 0, 0), (x, y, 0), (0.6, 0.6, 0.6), 0.05, 3.0)
    # draw sphere
    gr3.drawspheremesh(1, (x, y, 0), (1, 1, 1), 0.25)
    # show angular velocity
    V = 0.3 * omega - sign(omega) * 0.15
    gr3.drawcylindermesh(1, (x, y, 0), (cos(theta), sin(theta), 0), (0, 0, 1),
                         0.05, V)
    gr3.drawconemesh(1, (x + cos(theta) * V, y + sin(theta) * V, 0),
                     (-y, x, 0), (0, 0, 1), 0.1,
                     sign(omega) * 0.25)
    # show angular acceleration
    A = 0.3 * acceleration
    gr3.drawcylindermesh(1, (x, y, 0), (sin(theta), cos(theta), 0), (1, 0, 0),
                         0.05, A)
    gr3.drawconemesh(1, (x + sin(theta) * A, y + cos(theta) * A, 0),
                     (x, -y, 0), (1, 0, 0), 0.1, 0.25)
    # draw GR3 objects
    gr3.drawimage(0, 1, 0.15, 0.85, 500, 350,
                  gr3.GR3_Drawable.GR3_DRAWABLE_GKS)

    gr.settextfontprec(2, gr.TEXT_PRECISION_STRING)
    gr.setcharheight(0.024)
    gr.settextcolorind(1)
    gr.textext(0.05, 0.96, 'Damped Pendulum')
    gr.mathtex(0.05, 0.9, '\\omega=\\dot{\\theta}')
    gr.mathtex(0.05, 0.83,
               '\\dot{\\omega}=-\\gamma\\omega-\\frac{g}{l}sin(\\theta)')
    gr.setcharheight(0.020)
    gr.textext(0.05, 0.20, 't:%7.2f' % t)
    gr.textext(0.05, 0.16, '\\theta:%7.2f' % (theta / pi * 180))
    gr.settextcolorind(4)
    gr.textext(0.05, 0.12, '\\omega:%7.2f' % omega)
    gr.settextcolorind(2)
    gr.textext(0.05, 0.08, 'y_{A}:%6.2f' % acceleration)
    gr.updatews()
    return
Пример #12
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)
Пример #13
0
def pendulum(t, theta, omega, acceleration):
    gr.clearws()
    gr.setviewport(0, 1, 0, 1)
    
    x, y = (sin(theta) * 3.0, -cos(theta) * 3.0)
    
    gr3.clear()
    # draw pivot point
    gr3.drawspheremesh(1, (0, 0, 0), (0.4, 0.4, 0.4), 0.1)
    # draw rod
    gr3.drawcylindermesh(1, (0, 0, 0), (x, y, 0), (0.6, 0.6, 0.6), 0.05, 3.0)
    # draw sphere
    gr3.drawspheremesh(1, (x, y, 0), (1, 1, 1), 0.25)
    # show angular velocity
    V = 0.3 * omega - sign(omega) * 0.15
    gr3.drawcylindermesh(1, (x, y, 0), (cos(theta), sin(theta), 0), (0, 0, 1),
                         0.05, V)
    gr3.drawconemesh(1, (x + cos(theta) * V, y + sin(theta) * V, 0),
                     (-y, x, 0), (0, 0, 1), 0.1, sign(omega) * 0.25)
    # show angular acceleration
    A = 0.3 * acceleration
    gr3.drawcylindermesh(1, (x, y, 0), (sin(theta), cos(theta), 0), (1, 0, 0),
                         0.05, A)
    gr3.drawconemesh(1, (x + sin(theta) * A, y + cos(theta) * A, 0),
                     (x, -y, 0), (1, 0, 0), 0.1, 0.25)
    # draw GR3 objects
    gr3.drawimage(0, 1, 0.15, 0.85, 500, 350, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    
    gr.settextfontprec(2, gr.TEXT_PRECISION_STRING)
    gr.setcharheight(0.024)
    gr.settextcolorind(1)
    gr.textext(0.05, 0.96, 'Damped Pendulum')
    gr.mathtex(0.05, 0.9, '\\omega=\\dot{\\theta}')
    gr.mathtex(0.05, 0.83, '\\dot{\\omega}=-\\gamma\\omega-\\frac{g}{l}sin(\\theta)')
    gr.setcharheight(0.020)
    gr.textext(0.05, 0.20, 't:%7.2f' % t)
    gr.textext(0.05, 0.16, '\\theta:%7.2f' % (theta / pi * 180))
    gr.settextcolorind(4)
    gr.textext(0.05, 0.12, '\\omega:%7.2f' % omega)
    gr.settextcolorind(2)
    gr.textext(0.05, 0.08, 'y_{A}:%6.2f' % acceleration)
    gr.updatews()
    return
Пример #14
0
def draw(molecule,
         xmin=0,
         xmax=1,
         ymin=0,
         ymax=1,
         width=2000,
         height=2000,
         show_bonds=True,
         bonds_method='radii',
         bonds_param=None,
         camera=None):
    """
    Draw the given molecule with the GR framework. By default, bonds are drawn,
    if this is undesired the show_bonds parameter can be set to False.
    For information on the bond calculation, see Molecule.calculate_bonds.
    If you pass a tuple of camera position, center of view and an up vector to
    the camera parameter, the camera will be set accordingly. Otherwise the
    molecule will be viewed in the direction of the z axis, with the y axis
    pointing upward.
    """
    global _camera
    molecule.positions -= np.mean(molecule.positions, axis=0)
    max_atom_distance = np.max(la.norm(molecule.positions, axis=1))
    if show_bonds:
        molecule.calculate_bonds(bonds_method, bonds_param)

    if camera is None:
        camera_distance = -max_atom_distance * 2.5
        camera = ((0, 0, camera_distance), (0, 0, 0), (0, 1, 0))
    camera = np.array(camera)
    _camera = camera

    # Create the GR3 scene
    gr3.setbackgroundcolor(255, 255, 255, 0)
    _set_gr3_camera()
    _create_gr3_scene(molecule, show_bonds)
    glEnable(GL_DEPTH_TEST)
    gr3.setquality(gr3.GR3_Quality.GR3_QUALITY_OPENGL_16X_SSAA)
    gr3.drawimage(xmin, xmax, ymin, ymax, width, height,
                  gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    glBindFramebuffer(GL_FRAMEBUFFER, 0)
    glDisable(GL_DEPTH_TEST)
Пример #15
0
def draw(molecule,
         xmin=0, xmax=1, ymin=0, ymax=1, width=500, height=500,
         show_bonds=True, bonds_method='radii', bonds_param=None,
         camera=None):
    """
    Draw the given molecule with the GR framework. By default, bonds are drawn,
    if this is undesired the show_bonds parameter can be set to False.
    For information on the bond calculation, see Molecule.calculate_bonds.
    If you pass a tuple of camera position, center of view and an up vector to
    the camera parameter, the camera will be set accordingly. Otherwise the
    molecule will be viewed in the direction of the z axis, with the y axis
    pointing upward.
    """
    global _camera
    molecule.positions -= np.mean(molecule.positions, axis=0)
    max_atom_distance = np.max(la.norm(molecule.positions, axis=1))
    if show_bonds:
        molecule.calculate_bonds(bonds_method, bonds_param)

    if camera is None:
        camera_distance = -max_atom_distance*2.5
        camera = ((0, 0, camera_distance),
                  (0, 0, 0),
                  (0, 1, 0))
    camera = np.array(camera)
    _camera = camera

    # Create the GR3 scene
    gr3.setbackgroundcolor(255, 255, 255, 0)
    _set_gr3_camera()
    _create_gr3_scene(molecule, show_bonds)
    glEnable(GL_DEPTH_TEST)
    gr3.setquality(gr3.GR3_Quality.GR3_QUALITY_OPENGL_2X_SSAA)
    gr3.drawimage(xmin, xmax, ymin, ymax,
                  width, height, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    glBindFramebuffer(GL_FRAMEBUFFER, 0)
    glDisable(GL_DEPTH_TEST)
Пример #16
0
import gr
import gr3
gr.setviewport(0, 1, 0, 1)
for i in range(360):
    gr.clearws()
    gr3.clear()
    gr3.drawmolecule('dna.xyz', bond_delta=2, tilt=45, rotation=i)
    gr3.drawimage(0, 1, 0, 1, 500, 500, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.settextcolorind(0)
    gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP)
    gr.text(0.5, 1, "DNA rendered using gr3.drawmolecule")
    gr.updatews()
Пример #17
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)
Пример #18
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)
Пример #19
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)