def expose(self, widget, event): cr = widget.window.cairo_create() environ["GKS_WSTYPE"] = "142" pc = PyCairoContext.from_address(id(cr)) environ['GKSconid'] = "%lu" % pc.ctx cr.move_to(15, 15) cr.set_font_size(14) cr.show_text("Contour Plot using Gtk ...") seed(0) xd = uniform(-2, 2, 100) yd = uniform(-2, 2, 100) zd = xd * np.exp(-xd**2 - yd**2) gr.setviewport(0.15, 0.95, 0.1, 0.9) gr.setwindow(-2, 2, -2, 2) gr.setspace(-0.5, 0.5, 0, 90) gr.setmarkersize(1) gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE) gr.setcharheight(0.024) gr.settextalign(2, 0) gr.settextfontprec(3, 0) x, y, z = gr.gridit(xd, yd, zd, 200, 200) h = np.linspace(-0.5, 0.5, 20) gr.surface(x, y, z, 5) gr.contour(x, y, h, z, 0) gr.polymarker(xd, yd) gr.axes(0.25, 0.25, -2, -2, 2, 2, 0.01) gr.updatews()
def xtick(self, x, y, svalue, _value): gr.setcharup(-1., 1.) gr.settextalign(gr.TEXT_HALIGN_RIGHT, gr.TEXT_VALIGN_TOP) # We want to pass through the string value, but we are passed a bytes # object by the C layer and gr.text() needs a string. Since it is # encoded using latin1 again, this is the right encoding to use here. gr.text(x, y, svalue.decode('latin1'))
def _xtickCallBack(self, x, y, svalue, value): gr.setcharup(1., 1.) gr.settextalign(gr.TEXT_HALIGN_LEFT, gr.TEXT_VALIGN_TOP) gr.text(x, y, "%s (%s)" % (time.strftime("%H:%M:%S", time.localtime(self._startupTime + value)), svalue)) gr.setcharup(0., 1.)
def xtickCallBack(self, x, y, _svalue, value): gr.setcharup(-1., 1.) gr.settextalign(gr.TEXT_HALIGN_RIGHT, gr.TEXT_VALIGN_TOP) dx = .02 timeVal = time.localtime(value) gr.text(x + dx, y - 0.01, time.strftime(DATEFMT, timeVal)) gr.text(x - dx, y - 0.01, time.strftime(TIMEFMT, timeVal)) gr.setcharup(0., 1.)
def xtickCallBack(self, x, y, _svalue, value): gr.setcharup(-1. if self.leftTurnedLegend else 1., 1.) gr.settextalign(gr.TEXT_HALIGN_RIGHT if self.leftTurnedLegend else gr.TEXT_HALIGN_LEFT, gr.TEXT_VALIGN_TOP) dx = .015 timeVal = time.localtime(value) gr.text(x + (dx if self.leftTurnedLegend else -dx), y, time.strftime(DATEFMT, timeVal)) gr.text(x - (dx if self.leftTurnedLegend else -dx), y, time.strftime(TIMEFMT, timeVal)) gr.setcharup(0., 1.)
def xtickCallBack(self, x, y, _svalue, value): gr.setcharup(-1., 1.) gr.settextalign(gr.TEXT_HALIGN_RIGHT, gr.TEXT_VALIGN_TOP) dx = .02 timeVal = localtime(value) if self._showdate: gr.text(x + dx, y - 0.01, strftime(DATEFMT, timeVal)) if self._showsecs: gr.text(x - dx, y - 0.01, strftime(TIMEFMT, timeVal)) else: gr.text(x - dx, y - 0.01, strftime(SHORTTIMEFMT, timeVal)) gr.setcharup(0., 1.)
def _draw_legend(): global _plt viewport = _plt.kwargs['viewport'] num_labels = len(_plt.kwargs['labels']) location = _plt.kwargs.get('location', 1) gr.savestate() gr.selntran(0) gr.setscale(0) w = 0 for label in _plt.kwargs['labels']: tbx, tby = gr.inqtextext(0, 0, label) w = max(w, tbx[2]) num_lines = len(_plt.args) h = (num_lines + 1) * 0.03 if location in (8, 9, 10): px = 0.5 * (viewport[0] + viewport[1] - w) elif location in (2, 3, 6): px = viewport[0] + 0.11 else: px = viewport[1] - 0.05 - w if location in (5, 6, 7, 10): py = 0.5 * (viewport[2] + viewport[3] + h) - 0.03 elif location in (3, 4, 8): py = viewport[2] + h else: py = viewport[3] - 0.06 gr.setfillintstyle(gr.INTSTYLE_SOLID) gr.setfillcolorind(0) gr.fillrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * num_lines) gr.setlinetype(gr.LINETYPE_SOLID) gr.setlinecolorind(1) gr.setlinewidth(1) gr.drawrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * num_lines) i = 0 gr.uselinespec(" ") for (x, y, z, c, spec) in _plt.args: gr.savestate() mask = gr.uselinespec(spec) if mask in (0, 1, 3, 4, 5): gr.polyline([px - 0.07, px - 0.01], [py, py]) if mask & 2: gr.polymarker([px - 0.06, px - 0.02], [py, py]) gr.restorestate() gr.settextalign(gr.TEXT_HALIGN_LEFT, gr.TEXT_VALIGN_HALF) if i < num_labels: gr.textext(px, py, _plt.kwargs['labels'][i]) i += 1 py -= 0.03 gr.selntran(1) gr.restorestate()
def _plot_img(I): global _plt if isinstance(I, basestring): width, height, data = gr.readimage(I) if width == 0 or height == 0: return else: I = np.array(I) width, height = I.shape data = np.array(1000+(1.0*I - I.min()) / I.ptp() * 255, np.int32) if _plt.kwargs['clear']: gr.clearws() if not _plt.kwargs['ax']: _set_viewport('line', _plt.kwargs['subplot']) viewport = _plt.kwargs['viewport'] vp = _plt.kwargs['vp'] if width * (viewport[3] - viewport[2]) < height * (viewport[1] - viewport[0]): w = width / height * (viewport[3] - viewport[2]) x_min = max(0.5 * (viewport[0] + viewport[1] - w), viewport[0]) x_max = min(0.5 * (viewport[0] + viewport[1] + w), viewport[1]) y_min = viewport[2] y_max = viewport[3] else: h = height / width * (viewport[1] - viewport[0]) x_min = viewport[0] x_max = viewport[1] y_min = max(0.5 * (viewport[3] + viewport[2] - h), viewport[2]) y_max = min(0.5 * (viewport[3] + viewport[2] + h), viewport[3]) if 'cmap' in _plt.kwargs: warnings.warn('The parameter "cmap" has been replaced by "colormap". The value of "cmap" will be ignored.', stacklevel=3) colormap = _plt.kwargs.get('colormap', gr.COLORMAP_VIRIDIS) if colormap is not None: gr.setcolormap(colormap) gr.selntran(0) if isinstance(I, basestring): gr.drawimage(x_min, x_max, y_min, y_max, width, height, data) else: gr.cellarray(x_min, x_max, y_min, y_max, width, height, data) if 'title' in _plt.kwargs: gr.savestate() gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP) gr.textext(0.5 * (viewport[0] + viewport[1]), vp[3], _plt.kwargs['title']) gr.restorestate() gr.selntran(1)
def _plot_img(I): global _plt if isinstance(I, basestring): width, height, data = gr.readimage(I) if width == 0 or height == 0: return else: I = np.array(I) width, height = I.shape data = np.array(1000 + (1.0 * I - I.min()) / I.ptp() * 255, np.int32) if _plt.kwargs['clear']: gr.clearws() if not _plt.kwargs['ax']: _set_viewport('line', _plt.kwargs['subplot']) viewport = _plt.kwargs['viewport'] vp = _plt.kwargs['vp'] if width * (viewport[3] - viewport[2]) < height * (viewport[1] - viewport[0]): w = width / height * (viewport[3] - viewport[2]) x_min = max(0.5 * (viewport[0] + viewport[1] - w), viewport[0]) x_max = min(0.5 * (viewport[0] + viewport[1] + w), viewport[1]) y_min = viewport[2] y_max = viewport[3] else: h = height / width * (viewport[1] - viewport[0]) x_min = viewport[0] x_max = viewport[1] y_min = max(0.5 * (viewport[3] + viewport[2] - h), viewport[2]) y_max = min(0.5 * (viewport[3] + viewport[2] + h), viewport[3]) gr.setcolormap(_plt.kwargs.get('cmap', 1)) gr.selntran(0) if isinstance(I, basestring): gr.drawimage(x_min, x_max, y_min, y_max, width, height, data) else: gr.cellarray(x_min, x_max, y_min, y_max, width, height, data) if 'title' in _plt.kwargs: gr.savestate() gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP) gr.textext(0.5 * (viewport[0] + viewport[1]), vp[3], _plt.kwargs['title']) gr.restorestate() gr.selntran(1)
def _plot_img(I): global _plt if isinstance(I, basestring): width, height, data = gr.readimage(I) if width == 0 or height == 0: return else: I = np.array(I) width, height = I.shape data = np.array(1000+(1.0*I - I.min()) / I.ptp() * 255, np.int32) if _plt.kwargs['clear']: gr.clearws() if not _plt.kwargs['ax']: _set_viewport('line', _plt.kwargs['subplot']) viewport = _plt.kwargs['viewport'] vp = _plt.kwargs['vp'] if width * (viewport[3] - viewport[2]) < height * (viewport[1] - viewport[0]): w = width / height * (viewport[3] - viewport[2]) x_min = max(0.5 * (viewport[0] + viewport[1] - w), viewport[0]) x_max = min(0.5 * (viewport[0] + viewport[1] + w), viewport[1]) y_min = viewport[2] y_max = viewport[3] else: h = height / width * (viewport[1] - viewport[0]) x_min = viewport[0] x_max = viewport[1] y_min = max(0.5 * (viewport[3] + viewport[2] - h), viewport[2]) y_max = min(0.5 * (viewport[3] + viewport[2] + h), viewport[3]) gr.setcolormap(_plt.kwargs.get('cmap', 1)) gr.selntran(0) if isinstance(I, basestring): gr.drawimage(x_min, x_max, y_min, y_max, width, height, data) else: gr.cellarray(x_min, x_max, y_min, y_max, width, height, data) if 'title' in _plt.kwargs: gr.savestate() gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP) gr.textext(0.5 * (viewport[0] + viewport[1]), vp[3], _plt.kwargs['title']) gr.restorestate() gr.selntran(1)
def _draw_legend(): global _plt viewport = _plt.kwargs['viewport'] num_labels = len(_plt.kwargs['labels']) gr.savestate() gr.selntran(0) gr.setscale(0) w = 0 for label in _plt.kwargs['labels']: tbx, tby = gr.inqtextext(0, 0, label) w = max(w, tbx[2]) px = viewport[1] - 0.05 - w py = viewport[3] - 0.06 gr.setfillintstyle(gr.INTSTYLE_SOLID) gr.setfillcolorind(0) gr.fillrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * num_labels) gr.setlinetype(1) gr.setlinecolorind(1) gr.setlinewidth(1) gr.drawrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * num_labels) i = 0 gr.uselinespec(" ") for (x, y, z, c, spec) in _plt.args: gr.savestate() mask = gr.uselinespec(spec) if mask in (0, 1, 3, 4, 5): gr.polyline([px - 0.07, px - 0.01], [py, py]) if mask & 2: gr.polymarker([px - 0.06, px - 0.02], [py, py]) gr.restorestate() gr.settextalign(gr.TEXT_HALIGN_LEFT, gr.TEXT_VALIGN_HALF) if i < num_labels: gr.textext(px, py, _plt.kwargs['labels'][i]) i += 1 py -= 0.03 gr.selntran(1) gr.restorestate()
def _draw_polar_axes(): global _plt viewport = _plt.kwargs['viewport'] diag = ((viewport[1]-viewport[0])**2 + (viewport[3]-viewport[2])**2)**0.5 charheight = max(0.018 * diag, 0.012) window = _plt.kwargs['window'] r_min, r_max = window[2], window[3] gr.savestate() gr.setcharheight(charheight) gr.setlinetype(gr.LINETYPE_SOLID) tick = 0.5 * gr.tick(r_min, r_max) n = int(round((r_max - r_min) / tick + 0.5)) for i in range(n+1): r = i / n if i % 2 == 0: gr.setlinecolorind(88) if i > 0: gr.drawarc(-r, r, -r, r, 0, 359) gr.settextalign(gr.TEXT_HALIGN_LEFT, gr.TEXT_VALIGN_HALF) x, y = gr.wctondc(0.05, r) gr.text(x, y, "%g" % (r_min + i * tick)) else: gr.setlinecolorind(90) gr.drawarc(-r, r, -r, r, 0, 359) for alpha in range(0, 360, 45): sinf = np.sin(np.radians(alpha+90)) cosf = np.cos(np.radians(alpha+90)) gr.polyline([sinf, 0], [cosf, 0]) gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_HALF) x, y = gr.wctondc(1.1 * sinf, 1.1 * cosf) gr.textext(x, y, "%d^o" % alpha) gr.restorestate()
def _draw_axes(kind, pass_=1): global _plt viewport = _plt.kwargs['viewport'] vp = _plt.kwargs['vp'] x_tick, x_org, x_major_count = _plt.kwargs['xaxis'] y_tick, y_org, y_major_count = _plt.kwargs['yaxis'] gr.setlinecolorind(1) gr.setlinewidth(1) diag = ((viewport[1]-viewport[0])**2 + (viewport[3]-viewport[2])**2)**0.5 charheight = max(0.018 * diag, 0.012) gr.setcharheight(charheight) ticksize = 0.0075 * diag if kind in ('wireframe', 'surface', 'plot3', 'scatter3', 'trisurf'): z_tick, z_org, z_major_count = _plt.kwargs['zaxis'] if pass_ == 1: gr.grid3d(x_tick, 0, z_tick, x_org[0], y_org[0], z_org[0], 2, 0, 2) gr.grid3d(0, y_tick, 0, x_org[1], y_org[0], z_org[0], 0, 2, 0) else: gr.axes3d(x_tick, 0, z_tick, x_org[0], y_org[0], z_org[0], x_major_count, 0, z_major_count, -ticksize) gr.axes3d(0, y_tick, 0, x_org[1], y_org[0], z_org[0], 0, y_major_count, 0, ticksize) else: if kind == 'heatmap': ticksize = -ticksize else: gr.grid(x_tick, y_tick, 0, 0, x_major_count, y_major_count) gr.axes(x_tick, y_tick, x_org[0], y_org[0], x_major_count, y_major_count, ticksize) gr.axes(x_tick, y_tick, x_org[1], y_org[1], -x_major_count, -y_major_count, -ticksize) if 'title' in _plt.kwargs: gr.savestate() gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP) gr.textext(0.5*(viewport[0] + viewport[1]), vp[3], _plt.kwargs['title']) gr.restorestate() if kind in ('wireframe', 'surface', 'plot3', 'scatter3', 'trisurf'): x_label = _plt.kwargs.get('xlabel', '') y_label = _plt.kwargs.get('ylabel', '') z_label = _plt.kwargs.get('zlabel', '') gr.titles3d(x_label, y_label, z_label) else: if 'xlabel' in _plt.kwargs: gr.savestate() gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_BOTTOM) gr.textext(0.5 * (viewport[0] + viewport[1]), vp[2] + 0.5 * charheight, _plt.kwargs['xlabel']) gr.restorestate() if 'ylabel' in _plt.kwargs: gr.savestate() gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP) gr.setcharup(-1, 0) gr.textext(vp[0] + 0.5 * charheight, 0.5 * (viewport[2] + viewport[3]), _plt.kwargs['ylabel']) gr.restorestate()
def _draw_axes(kind, pass_=1): global _plt viewport = _plt.kwargs['viewport'] vp = _plt.kwargs['vp'] x_tick, x_org, x_major_count = _plt.kwargs['xaxis'] y_tick, y_org, y_major_count = _plt.kwargs['yaxis'] gr.setlinecolorind(1) gr.setlinewidth(1) diag = ((viewport[1]-viewport[0])**2 + (viewport[3]-viewport[2])**2)**0.5 charheight = max(0.018 * diag, 0.012) gr.setcharheight(charheight) ticksize = 0.0075 * diag if kind in ('wireframe', 'surface', 'plot3', 'scatter3', 'trisurf'): z_tick, z_org, z_major_count = _plt.kwargs['zaxis'] if pass_ == 1: gr.grid3d(x_tick, 0, z_tick, x_org[0], y_org[1], z_org[0], 2, 0, 2) gr.grid3d(0, y_tick, 0, x_org[0], y_org[1], z_org[0], 0, 2, 0) else: gr.axes3d(x_tick, 0, z_tick, x_org[0], y_org[0], z_org[0], x_major_count, 0, z_major_count, -ticksize) gr.axes3d(0, y_tick, 0, x_org[1], y_org[0], z_org[0], 0, y_major_count, 0, ticksize) else: if kind == 'heatmap': ticksize = -ticksize else: gr.grid(x_tick, y_tick, 0, 0, x_major_count, y_major_count) gr.axes(x_tick, y_tick, x_org[0], y_org[0], x_major_count, y_major_count, ticksize) gr.axes(x_tick, y_tick, x_org[1], y_org[1], -x_major_count, -y_major_count, -ticksize) if 'title' in _plt.kwargs: gr.savestate() gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP) gr.textext(0.5*(viewport[0] + viewport[1]), vp[3], _plt.kwargs['title']) gr.restorestate() if kind in ('wireframe', 'surface', 'plot3', 'scatter3', 'trisurf'): x_label = _plt.kwargs.get('xlabel', '') y_label = _plt.kwargs.get('ylabel', '') z_label = _plt.kwargs.get('zlabel', '') gr.titles3d(x_label, y_label, z_label) else: if 'xlabel' in _plt.kwargs: gr.savestate() gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_BOTTOM) gr.textext(0.5 * (viewport[0] + viewport[1]), vp[2] + 0.5 * charheight, _plt.kwargs['xlabel']) gr.restorestate() if 'ylabel' in _plt.kwargs: gr.savestate() gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP) gr.setcharup(-1, 0) gr.textext(vp[0] + 0.5 * charheight, 0.5 * (viewport[2] + viewport[3]), _plt.kwargs['ylabel']) gr.restorestate()
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)
""" Create a contour plot of irregular distributed data """ from numpy.random import uniform, seed import numpy as np import gr seed(0) xd = uniform(-2, 2, 100) yd = uniform(-2, 2, 100) zd = xd * np.exp(-xd ** 2 - yd ** 2) gr.setviewport(0.1, 0.95, 0.1, 0.95) gr.setwindow(-2, 2, -2, 2) gr.setspace(-0.5, 0.5, 0, 90) gr.setmarkersize(1) gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE) gr.setcharheight(0.024) gr.settextalign(2, 0) gr.settextfontprec(3, 0) x, y, z = gr.gridit(xd, yd, zd, 200, 200) h = np.linspace(-0.5, 0.5, 20) gr.surface(x, y, z, 5) gr.contour(x, y, h, z, 0) gr.polymarker(xd, yd) gr.axes(0.25, 0.25, -2, -2, 2, 2, 0.01) gr.updatews()
# coding: utf8 from gr import selntran, settextfontprec, settextalign, setcharheight, clearws, setcharup, text, inqtext, fillarea, updatews from math import pi, sin, cos from numpy import linspace s = 'Using inline math $\\frac{2hc^2}{\\lambda^5} \\frac{1}{e^{\\frac{hc}{\\lambda k_B T}} - 1}$ in GR text\nmixed with raw strings ' + r'$- \frac{{\hbar ^2}}{{2m}}\frac{{\partial ^2 \psi (x,t)}}{{\partial x^2 }} + U(x)\psi (x,t) = i\hbar \frac{{\partial \psi (x,t)}}{{\partial t}}$' + '\n– with line breaks\nand UTF-8 characters (ħπ),\nand rendered using GR\'s text attributes' selntran(0) settextfontprec(232, 3) settextalign(2, 3) setcharheight(0.02) for phi in linspace(0, 2 * pi, 360): clearws() setcharup(sin(phi), cos(phi)) text(0.5, 0.5, s) tbx, tby = inqtext(0.5, 0.5, s) fillarea(tbx, tby) updatews()
#!/usr/bin/env python """ Create a contour plot of irregular distributed data """ import numpy as np import gr np.random.seed(0) xd = np.random.uniform(-2, 2, 100) yd = np.random.uniform(-2, 2, 100) zd = xd * np.exp(-xd**2 - yd**2) gr.setviewport(0.1, 0.95, 0.1, 0.95) gr.setwindow(-2, 2, -2, 2) gr.setspace(-0.5, 0.5, 0, 90) gr.setmarkersize(1) gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE) gr.setcharheight(0.024) gr.settextalign(2, 0) gr.settextfontprec(3, 0) x, y, z = gr.gridit(xd, yd, zd, 200, 200) h = np.linspace(-0.5, 0.5, 20) gr.surface(x, y, z, 5) gr.contour(x, y, h, z, 0) gr.polymarker(xd, yd) gr.axes(0.25, 0.25, -2, -2, 2, 2, 0.01) gr.updatews()
import gr from math import sin, cos, pi import time hor_align = {'Left':1, 'Center':2, 'Right':3} vert_align = {'Top':1, 'Cap':2, 'Half':3, 'Base':4, 'Bottom':5} gr.selntran(0) gr.setcharheight(0.024) for angle in range(361): gr.setcharup(sin(-angle * pi/180), cos(-angle * pi/180)) gr.setmarkertype(2) gr.clearws() for halign in hor_align: for valign in vert_align: gr.settextalign(hor_align[halign], vert_align[valign]) x = -0.1 + hor_align[halign] * 0.3; y = 1.1 - vert_align[valign] * 0.2; s = halign + '\n' + valign + '\n' + 'third line' gr.polymarker([x], [y]) gr.text(x, y, s) tbx, tby = gr.inqtext(x, y, s) gr.fillarea(tbx, tby) gr.updatews() time.sleep(0.02)
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)
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)
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()
import gr horizontal_alignment = {'Left': 1, 'Center': 2, 'Right': 3} vertical_alignment = {'Top': 1, 'Cap': 2, 'Half': 3, 'Base': 4, 'Bottom': 5} gr.selntran(0) gr.setcharheight(0.024) for angle in range(361): gr.setcharup(sin(-angle * pi / 180), cos(-angle * pi / 180)) gr.setmarkertype(2) gr.clearws() for halign in horizontal_alignment: for valign in vertical_alignment: gr.settextalign(horizontal_alignment[halign], vertical_alignment[valign]) x = -0.1 + horizontal_alignment[halign] * 0.3 y = 1.1 - vertical_alignment[valign] * 0.2 s = halign + '\n' + valign + '\n' + 'third line' gr.polymarker([x], [y]) gr.text(x, y, s) tbx, tby = gr.inqtext(x, y, s) gr.fillarea(tbx, tby) gr.updatews() time.sleep(0.02)