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 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
def pendulum(t, theta, omega, acceleration): gr.clearws() gr.setviewport(0, 1, 0, 1) x = [0.5, 0.5 + np.sin(theta) * 0.4] y = [0.8, 0.8 - np.cos(theta) * 0.4] # draw pivot point gr.fillarea([0.46, 0.54, 0.54, 0.46], [0.79, 0.79, 0.81, 0.81]), gr.setlinecolorind(1) gr.setlinewidth(2) gr.polyline(x, y) # draw rod gr.setmarkersize(5) gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE) gr.setmarkercolorind(86) gr.polymarker([x[1]], [y[1]]) # draw bob gr.setlinecolorind(4) V = 0.05 * omega # show angular velocity gr.drawarrow(x[1], y[1], x[1] + V * np.cos(theta), y[1] + V * np.sin(theta)) gr.setlinecolorind(2) A = 0.05 * acceleration # show angular acceleration gr.drawarrow(x[1], y[1], x[1] + A * np.sin(theta), y[1] + A * np.cos(theta)) gr.settextfontprec(2, gr.TEXT_PRECISION_STRING) gr.setcharheight(0.032) gr.settextcolorind(1) gr.textext(0.05, 0.95, 'Damped Pendulum') gr.setcharheight(0.040) gr.mathtex(0.4, 0.22, '\\omega=\\dot{\\theta}') gr.mathtex(0.4, 0.1, '\\dot{\\omega}=-\\gamma\\omega-\\frac{g}{l}sin(\\theta)') gr.setcharheight(0.028) gr.textext(0.05, 0.22, 't:%7.2f' % t) gr.textext(0.05, 0.16, '\\theta:%7.2f' % (theta / np.pi * 180)) gr.settextcolorind(4) gr.textext(0.05, 0.10, '\\omega:%7.2f' % omega) gr.settextcolorind(2) gr.textext(0.05, 0.04, 'y_{A}:%6.2f' % acceleration) gr.updatews()
def pendulum(t, theta, omega, acceleration): gr.clearws() gr.setviewport(0, 1, 0, 1) x = [0.5, 0.5 + sin(theta) * 0.4] y = [0.8, 0.8 - cos(theta) * 0.4] # draw pivot point gr.fillarea([0.46, 0.54, 0.54, 0.46], [0.79, 0.79, 0.81, 0.81]), gr.setlinecolorind(1) gr.setlinewidth(2) gr.polyline(x, y) # draw rod gr.setmarkersize(5) gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE) gr.setmarkercolorind(86) gr.polymarker([x[1]], [y[1]]) # draw bob gr.setlinecolorind(4) V = 0.05 * omega # show angular velocity gr.drawarrow(x[1], y[1], x[1] + V*cos(theta), y[1] + V*sin(theta)) gr.setlinecolorind(2) A = 0.05 * acceleration # show angular acceleration gr.drawarrow(x[1], y[1], x[1] + A*sin(theta), y[1] + A*cos(theta)) gr.settextfontprec(2, gr.TEXT_PRECISION_STRING) gr.setcharheight(0.032) gr.settextcolorind(1) gr.textext(0.05, 0.95, 'Damped Pendulum') gr.setcharheight(0.040) gr.mathtex(0.4, 0.22, '\\omega=\\dot{\\theta}') gr.mathtex(0.4, 0.1, '\\dot{\\omega}=-\\gamma\\omega-\\frac{g}{l}sin(\\theta)') gr.setcharheight(0.028) gr.textext(0.05, 0.22, 't:%7.2f' % t) gr.textext(0.05, 0.16, '\\theta:%7.2f' % (theta / pi * 180)) gr.settextcolorind(4) gr.textext(0.05, 0.10, '\\omega:%7.2f' % omega) gr.settextcolorind(2) gr.textext(0.05, 0.04, 'y_{A}:%6.2f' % acceleration) gr.updatews()
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)
#!/usr/bin/env/python # -*- coding: utf-8 -*- import gr gr.selntran(0) gr.settextfontprec(2, 0) gr.setcharheight(0.024) gr.text(0.05, 0.85, ' !"#$%&\'()*+,-./') gr.text(0.05, 0.80, '0123456789:;<=>?') gr.text(0.05, 0.75, '@ABCDEFGHIJKLMNO') gr.text(0.05, 0.70, 'PQRSTUVWXYZ[\]^_') gr.text(0.05, 0.65, '`abcdefghijklmno') gr.text(0.05, 0.60, '"pqrstuvwxyz{|}~') gr.text(0.5, 0.85, ' ¡¢£¤¥¦§¨©ª«¬®¯') gr.text(0.5, 0.80, '°±²³´µ¶·¸¹º»¼½¾¿') gr.text(0.5, 0.75, 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ') gr.text(0.5, 0.70, 'ÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß') gr.text(0.5, 0.65, 'àáâãäåæçèéêëìíîï') gr.text(0.5, 0.60, 'ðñòóôõö÷øùúûüýþÿ') gr.updatews()
""" 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()
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)