def draw_ellipse(ell, alpha=1.0, color=1):
    gr.setfillintstyle(1)  # solid (default is no fill)
    gr.setfillcolorind(color)
    gr.settransparency(alpha)
    gr.setlinewidth(2)
    # gr.polyline(ell[0, :], ell[1, :])
    gr.fillarea(ell[0, :], ell[1, :])
    gr.settransparency(1.0)
Exemple #2
0
def pendulum(theta, length, mass):
    l = length[0] + length[1]
    gr.clearws()
    gr.setviewport(0, 1, 0, 1)
    gr.setwindow(-l, l, -l, l)
    gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE)
    gr.setmarkercolorind(86)
    pivot = [0, 0.775]                         # draw pivot point
    gr.fillarea([-0.2, 0.2, 0.2, -0.2], [0.75, 0.75, 0.8, 0.8])
    for i in range(2):
        x = [pivot[0], pivot[0] + sin(theta[i]) * length[i]]
        y = [pivot[1], pivot[1] - cos(theta[i]) * length[i]]
        gr.polyline(x, y)                   # draw rod
        gr.setmarkersize(3 * mass[i])
        gr.polymarker([x[1]], [y[1]])       # draw bob
        pivot = [x[1], y[1]]
    gr.updatews()
    return
Exemple #3
0
def pendulum(theta, length, mass):
    l = length[0] + length[1]
    gr.clearws()
    gr.setviewport(0, 1, 0, 1)
    gr.setwindow(-l, l, -l, l)
    gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE)
    gr.setmarkercolorind(86)
    pivot = [0, 0.775]  # draw pivot point
    gr.fillarea([-0.2, 0.2, 0.2, -0.2], [0.75, 0.75, 0.8, 0.8])
    for i in range(2):
        x = [pivot[0], pivot[0] + sin(theta[i]) * length[i]]
        y = [pivot[1], pivot[1] - cos(theta[i]) * length[i]]
        gr.polyline(x, y)  # draw rod
        gr.setmarkersize(3 * mass[i])
        gr.polymarker([x[1]], [y[1]])  # draw bob
        pivot = [x[1], y[1]]
    gr.updatews()
    return
Exemple #4
0
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()
Exemple #5
0
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()
Exemple #6
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()
Exemple #7
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)