Esempio n. 1
0
 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'))
Esempio n. 2
0
 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.)
Esempio n. 3
0
 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.)
Esempio n. 4
0
 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.)
Esempio n. 5
0
 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.)
Esempio n. 6
0
    def draw(self, wsviewport=None):
        if self.xvalues is not None and self.widths is not None:
            maxidx = np.argmax(self.xvalues)
            rangex = (self.xvalues.min(),
                      self.xvalues[maxidx] + self.widths[maxidx])
        else:
            rangex = (0.0, 100.0)
        if self.yvalues is not None:
            rangey = gr.adjustrange(0.0, self.yvalues.max())
        else:
            rangey = (0.0, 8.0)

        if wsviewport is None:
            gr.setwsviewport(0, self.mwidth, 0, self.mheight)
        else:
            gr.setwsviewport(*wsviewport)
        gr.setwswindow(0, self.sizex, 0, self.sizey)
        gr.setviewport(0.075 * self.sizex, 0.95 * self.sizex,
                       0.075 * self.sizey, 0.95 * self.sizey)
        gr.setwindow(rangex[0], rangex[1], rangey[0], rangey[1])
        gr.setcharheight(0.012)

        gr.setfillintstyle(1)
        gr.setfillcolorind(0)
        gr.fillrect(rangex[0], rangex[1], rangey[0], rangey[1])

        if self.xvalues is not None and self.yvalues is not None \
                and self.widths is not None:
            gr.setfillintstyle(1)
            gr.setfillcolorind(2)
            for i in range(self.xvalues.size):
                gr.fillrect(self.xvalues[i],
                            self.xvalues[i] + self.widths[i] * 0.8,
                            0.0, self.yvalues[i])
        else:
            gr.text(0.45 * self.sizex, 0.5 * self.sizey, "no data")

        gr.setlinecolorind(1)
        xtick = floor(0.02 * (rangex[1] - rangey[0]) * 100.0) / 100.0
        ytick = floor(0.04 * (rangey[1] - rangey[0]) * 50.0) / 50.0
        gr.axes(xtick, ytick, rangex[0], rangey[0], 10, 5, 0.0075)
        gr.axes(xtick, ytick, rangex[1], rangey[1], -10, -5, -0.0075)

        if self.title is not None:
            gr.text(0.8 * self.sizex, 0.9 * self.sizey, self.title)
Esempio n. 7
0
    def draw(self, wsviewport=None):
        if self.xvalues is not None and self.widths is not None:
            maxidx = np.argmax(self.xvalues)
            rangex = (self.xvalues.min(),
                      self.xvalues[maxidx] + self.widths[maxidx])
        else:
            rangex = (0.0, 100.0)
        if self.yvalues is not None:
            rangey = gr.adjustrange(0.0, self.yvalues.max())
        else:
            rangey = (0.0, 8.0)

        if wsviewport is None:
            gr.setwsviewport(0, self.mwidth, 0, self.mheight)
        else:
            gr.setwsviewport(*wsviewport)
        gr.setwswindow(0, self.sizex, 0, self.sizey)
        gr.setviewport(0.075 * self.sizex, 0.95 * self.sizex,
                       0.075 * self.sizey, 0.95 * self.sizey)
        gr.setwindow(rangex[0], rangex[1], rangey[0], rangey[1])
        gr.setcharheight(0.012)

        gr.setfillintstyle(1)
        gr.setfillcolorind(0)
        gr.fillrect(rangex[0], rangex[1], rangey[0], rangey[1])

        if self.xvalues is not None and self.yvalues is not None \
                and self.widths is not None:
            gr.setfillintstyle(1)
            gr.setfillcolorind(2)
            for i in range(self.xvalues.size):
                gr.fillrect(self.xvalues[i],
                            self.xvalues[i] + self.widths[i] * 0.8,
                            0.0, self.yvalues[i])
        else:
            gr.text(0.45 * self.sizex, 0.5 * self.sizey, "no data")

        gr.setlinecolorind(1)
        xtick = floor(0.02 * (rangex[1] - rangey[0]) * 100.0) / 100.0
        ytick = floor(0.04 * (rangey[1] - rangey[0]) * 50.0) / 50.0
        gr.axes(xtick, ytick, rangex[0], rangey[0], 10, 5, 0.0075)
        gr.axes(xtick, ytick, rangex[1], rangey[1], -10, -5, -0.0075)

        if self.title is not None:
            gr.text(0.8 * self.sizex, 0.9 * self.sizey, self.title)
Esempio n. 8
0
 def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
     if ismath:
         self._draw_mathtext(gc, x, y, s, prop, angle)
     else:
         x, y = gr.wctondc(x, y)
         fontsize = prop.get_size_in_points()
         rgba = gc.get_rgb()[:4]
         color = gr.inqcolorfromrgb(rgba[0], rgba[1], rgba[2])
         gr.settransparency(rgba[3])
         gr.setcolorrep(color, rgba[0], rgba[1], rgba[2])
         gr.setcharheight(fontsize * self.nominal_fontsize)
         gr.settextcolorind(color)
         if angle != 0:
             gr.setcharup(-np.sin(angle * np.pi/180),
                          np.cos(angle * np.pi/180))
         else:
             gr.setcharup(0, 1)
         gr.text(x, y, s)
Esempio n. 9
0
 def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
     if ismath:
         self._draw_mathtext(gc, x, y, s, prop, angle)
     else:
         x, y = gr.wctondc(x, y)
         s = s.replace(u'\u2212', '-')
         fontsize = prop.get_size_in_points()
         rgba = gc.get_rgb()[:4]
         color = gr.inqcolorfromrgb(rgba[0], rgba[1], rgba[2])
         gr.settransparency(rgba[3])
         gr.setcolorrep(color, rgba[0], rgba[1], rgba[2])
         gr.setcharheight(fontsize * 0.0013)
         gr.settextcolorind(color)
         if angle != 0:
             gr.setcharup(-np.sin(angle * np.pi/180),
                          np.cos(angle * np.pi/180))
         else:
             gr.setcharup(0, 1)
         gr.text(x, y, s)
Esempio n. 10
0
    def draw(self, wsviewport=None):
        if self.xvalues is not None:
            rangex = (self.xvalues.min(), self.xvalues.max())
        else:
            rangex = (0, 10)
        if self.yvalues is not None:
            rangey = gr.adjustrange(self.yvalues.min(), self.yvalues.max())
        else:
            rangey = (0, 4)

        if wsviewport is None:
            gr.setwsviewport(0, self.mwidth, 0, self.mheight)
        else:
            gr.setwsviewport(*wsviewport)
        gr.setwswindow(0, self.sizex, 0, self.sizey)
        gr.setviewport(0.075 * self.sizex, 0.95 * self.sizex,
                       0.075 * self.sizey, 0.95 * self.sizey)
        gr.setwindow(rangex[0], rangex[1], rangey[0], rangey[1])
        gr.setcharheight(0.012)

        gr.setfillintstyle(1)
        gr.setfillcolorind(0)
        gr.fillrect(rangex[0], rangex[1], rangey[0], rangey[1])

        if self.xvalues is not None and self.yvalues is not None:
            gr.setlinecolorind(2)
            gr.polyline(self.xvalues, self.yvalues)
        else:
            gr.text(0.4 * self.sizex, 0.5 * self.sizey, "no elements selected")

        gr.setlinecolorind(1)
        gr.axes(0.2, 0.2, rangex[0], rangey[0], 5, 5, 0.0075)
        gr.axes(0.2, 0.2, rangex[1], rangey[1], -5, -5, -0.0075)

        if self.title is not None:
            gr.text(0.8 * self.sizex, 0.9 * self.sizey, self.title)
Esempio n. 11
0
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()
Esempio n. 12
0
    def draw(self, wsviewport=None):
        if self.xvalues is not None:
            rangex = (self.xvalues.min(), self.xvalues.max())
        else:
            rangex = (0, 10)
        if self.yvalues is not None:
            rangey = gr.adjustrange(self.yvalues.min(), self.yvalues.max())
        else:
            rangey = (0, 4)

        if wsviewport is None:
            gr.setwsviewport(0, self.mwidth, 0, self.mheight)
        else:
            gr.setwsviewport(*wsviewport)
        gr.setwswindow(0, self.sizex, 0, self.sizey)
        gr.setviewport(0.075 * self.sizex, 0.95 * self.sizex,
                       0.075 * self.sizey, 0.95 * self.sizey)
        gr.setwindow(rangex[0], rangex[1], rangey[0], rangey[1])
        gr.setcharheight(0.012)

        gr.setfillintstyle(1)
        gr.setfillcolorind(0)
        gr.fillrect(rangex[0], rangex[1], rangey[0], rangey[1])

        if self.xvalues is not None and self.yvalues is not None:
            gr.setlinecolorind(2)
            gr.polyline(self.xvalues, self.yvalues)
        else:
            gr.text(0.4 * self.sizex, 0.5 * self.sizey, "no elements selected")

        gr.setlinecolorind(1)
        gr.axes(0.2, 0.2, rangex[0], rangey[0], 5, 5, 0.0075)
        gr.axes(0.2, 0.2, rangex[1], rangey[1], -5, -5, -0.0075)

        if self.title is not None:
            gr.text(0.8 * self.sizex, 0.9 * self.sizey, self.title)
Esempio n. 13
0
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()
Esempio n. 14
0
 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.)
Esempio n. 15
0
File: latin1.py Progetto: faroit/gr
#!/usr/bin/python
# -*- coding: latin-1 -*-

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()

Esempio n. 16
0
File: spectrum.py Progetto: j-fu/gr
start = time.time()

while time.time() - start < 10:
    try:
        power = get_spectrum()
        peakind = signal.find_peaks_cwt(power, numpy.array([5]))
    except (IOError):
        continue

    gr.clearws()
    gr.setlinewidth(1)
    gr.setlinecolorind(1)
    gr.grid(1, 5, 50, 0, 1, 2)
    gr.axes(1, 5, 50, 0, 1, 2, -0.008)
    gr.setcharheight(0.020)
    gr.text(0.15, 0.965, '100Hz')
    gr.text(0.47, 0.965, '1kHz')
    gr.text(0.79, 0.965, '10kHz')
    gr.setlinecolorind(4)
    gr.polyline(f[1:], power[1:])
    for p in peakind:
        if power[p] > 10:
            gr.setlinewidth(2)
            gr.setlinecolorind(2)
            xe, ye = parabolic(f[p], power, p)
            print(xe, ye)
            gr.polyline([xe] * 2, [0, ye])
    gr.updatews()

Esempio n. 17
0
# 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()
Esempio n. 18
0
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)
Esempio n. 19
0
File: particles.py Progetto: j-fu/gr
gr.setmarkersize(1.0)

start = time.time()
t0 = start

n = 0
t = 0
worker = 'CPython'

while t < 6:

    if t > 3:
        if worker == 'CPython':
            t0 = now
            n = 0
        a = step_numba(dt, size, a)
        worker = 'Numba'
    else:
        a = step(dt, size, a)

    gr.clearws()
    gr.setmarkercolorind(75)
    gr.polymarker(a[0, :, 0], a[0, :, 1])
    if n > 0:
        gr.text(0.01, 0.95, '%10s: %4d fps' % (worker, int(n / (now - t0))))
    gr.updatews()

    now = time.time()
    n += 1
    t = now - start
Esempio n. 20
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)
Esempio n. 21
0
gr.setregenflags(gr.MPL_POSTPONE_UPDATE)

for t in range(100):

    plt.cla()
    fig = plt.subplot(133)
    fig.xaxis.set_ticks([-100, 0, 100])
    fig.yaxis.set_ticks([])
    plt.ylim([0, 1000])
    plt.hist(angles[t], 20, normed=0, facecolor='g', alpha=0.5)
    plt.show()

    gr.setviewport(0, 0.7, 0, 0.7)
    gr.setwindow(0.1, 0.9, 0.05, 0.85)
    mogli.draw(molecules[t],
               bonds_param=1.15,
               camera=((60, 0, 0), (0, 0, 0), (0, 1, 0)))

    gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_HALF)
    gr.text(0.35, 0.7,
            '700K (%.1f ps)  # of bonds: %d' % (t / 10.0, len(angles[t])))
    lens.append(len(angles[t]))
    if t > 0:
        gr.setwindow(0, 10, 3500, 5000)
        gr.setviewport(0.1, 0.6, 0.05, 0.1)
        gr.axes(1, 0, 0, 3500, 2, 0, 0.005)
        gr.polyline(np.arange(t + 1) / 10.0, lens)

    gr.updatews()
Esempio n. 22
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)
Esempio n. 23
0
import gr
import mogli

molecules = mogli.read('examples/dna.xyz')
mogli.ATOM_RADIUS = 3
gr.clearws()
gr.setviewport(0, 1, 0, 1)
mogli.draw(molecules[0], bonds_param=1.15, camera=((60, 0, 0),
                                                    (0, 0, 0),
                                                    (0, 1, 0)))
gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP)
gr.text(0.5, 1.0, 'DNA example')
gr.updatews()
Esempio n. 24
0
gr.setscale(1)

start = time.time()

while time.time() - start < 10:
    try:
        power = get_spectrum()
        peakind = signal.find_peaks_cwt(power, numpy.array([5]))
    except (IOError):
        continue

    gr.clearws()
    gr.setlinewidth(1)
    gr.setlinecolorind(1)
    gr.grid(1, 5, 50, 0, 1, 2)
    gr.axes(1, 5, 50, 0, 1, 2, -0.008)
    gr.setcharheight(0.020)
    gr.text(0.15, 0.965, "100Hz")
    gr.text(0.47, 0.965, "1kHz")
    gr.text(0.79, 0.965, "10kHz")
    gr.setlinecolorind(4)
    gr.polyline(f[1:], power[1:])
    for p in peakind:
        if power[p] > 10:
            gr.setlinewidth(2)
            gr.setlinecolorind(2)
            xe, ye = parabolic(f[p], power, p)
            print(xe, ye)
            gr.polyline([xe] * 2, [0, ye])
    gr.updatews()
Esempio n. 25
0
            uyy = (ui[i, j + 1] - 2 * ui[i, j] + ui[i, j - 1]) / (dy * dy)
            u[i, j] = ui[i, j] + dt * a * (uxx + uyy)


diff_step_numba = jit('void(f8[:,:], f8[:,:])')(diff_step)

now = perf_counter()

t = 0
worker = 'CPython'

for m in range(timesteps):
    gr.clearws()

    start = now
    if t > 5:
        diff_step_numba(u, ui)
        worker = 'Numba'
    else:
        diff_step(u, ui)
    ui = numpy.copy(u)
    now = perf_counter()
    t = t + now - start

    c = 1000 + 255 * u.ravel()
    gr.setviewport(0, 1, 0, 1)
    gr.setcolormap(-32)
    gr.cellarray(0, 1, 0, 1, nx, ny, c)
    gr.text(0.01, 0.95, '%10s: %7.2f fps' % (worker, 1.0 / (now - start)))
    gr.updatews()
Esempio n. 26
0
gr.setscale(1)

start = time.time()

while time.time() - start < 10:
    try:
        power = get_spectrum()
        peakind = signal.find_peaks_cwt(power, np.array([5]))
    except (IOError):
        continue

    gr.clearws()
    gr.setlinewidth(1)
    gr.setlinecolorind(1)
    gr.grid(1, 5, 50, 0, 1, 2)
    gr.axes(1, 5, 50, 0, 1, 2, -0.008)
    gr.setcharheight(0.020)
    gr.text(0.15, 0.965, '100Hz')
    gr.text(0.47, 0.965, '1kHz')
    gr.text(0.79, 0.965, '10kHz')
    gr.setlinecolorind(4)
    gr.polyline(f[1:], power[1:])
    for p in peakind:
        if power[p] > 10:
            gr.setlinewidth(2)
            gr.setlinecolorind(2)
            xe, ye = parabolic(f[p], power, p)
            print(xe, ye)
            gr.polyline([xe] * 2, [0, ye])
    gr.updatews()
Esempio n. 27
0
gr.setmarkersize(1.0)

start = time.time()
t0 = start

n = 0
t = 0
worker = 'CPython'

while t < 6:

    if t > 3:
        if worker == 'CPython':
            t0 = now
            n = 0
        a = step_numba(dt, size, a)
        worker = 'Numba'
    else:
        a = step(dt, size, a)

    gr.clearws()
    gr.setmarkercolorind(75)
    gr.polymarker(a[0, :, 0], a[0, :, 1])
    if n > 0:
        gr.text(0.01, 0.95, '%10s: %4d fps' % (worker, int(n / (now - t0))))
    gr.updatews()

    now = time.time()
    n += 1
    t = now - start
Esempio n. 28
0
            uxx = ( ui[i+1,j] - 2*ui[i,j] + ui[i-1, j] )/(dx*dx)
            uyy = ( ui[i,j+1] - 2*ui[i,j] + ui[i, j-1] )/(dy*dy)
            u[i,j] = ui[i,j]+dt*a*(uxx+uyy)

diff_step_numba = jit('void(f8[:,:], f8[:,:])')(diff_step)

now = time.clock()

t = 0
worker = 'CPython'

for m in range(timesteps):
    gr.clearws()

    start = now
    if t > 5:
        diff_step_numba(u, ui)
        worker = 'Numba'
    else:
        diff_step(u, ui)
    ui = numpy.copy(u)
    now = time.clock()
    t = t + now - start

    c = 1000 + 255 * u.ravel()
    gr.setviewport(0, 1, 0, 1)
    gr.setcolormap(-32)
    gr.cellarray(0, 1, 0, 1, nx, ny, c)
    gr.text(0.01, 0.95, '%10s: %7.2f fps' % (worker, 1.0 / (now - start)))
    gr.updatews()
Esempio n. 29
0
#!/usr/bin/python
# -*- coding: latin-1 -*-

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()
Esempio n. 30
0
"""
Example for drawing a molecule using mogli and GR
"""
import gr
import mogli

molecules = mogli.read('examples/dna.xyz')
gr.clearws()
gr.setviewport(0, 1, 0, 1)
mogli.draw(molecules[0],
           bonds_param=1.15,
           camera=((60, 0, 0), (0, 0, 0), (0, 1, 0)))
gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP)
gr.text(0.5, 1.0, 'DNA example')
gr.updatews()
Esempio n. 31
0
File: utf8.py Progetto: kaigaox/gr
#!/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()
Esempio n. 32
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)
Esempio n. 33
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()
Esempio n. 34
0
 def yinttick(self, x, y, svalue, _value):
     gr.setcharheight(self._charheight)
     gr.text(x, y, svalue.decode('latin1'))