Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
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)
n = int(round((phi_max - phi_min) / tick + 0.5))
for i in range(n + 1):
angle_label = phi_min + i * tick
if _plt.kwargs.get('phiflip', False):
angle = phi_max - i * tick
else:
angle = angle_label
sinf = np.sin(np.radians(angle))
cosf = np.cos(np.radians(angle))
pline = np.array([r_min / r_max, 1])
if phi_min <= angle <= phi_max:
if i % 2 == 0 and not (i == n and phi_max % 360 == phi_min % 360):
gr.setlinecolorind(88)
gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_HALF)
x, y = gr.wctondc(1.1 * cosf, 1.1 * sinf)
gr.textext(x, y, "%g\xb0" % angle_label)
else:
gr.setlinecolorind(90)
else:
angle = np.clip(angle, phi_min, phi_max)
gr.setlinecolorind(88)
sinf = np.sin(np.radians(angle))
cosf = np.cos(np.radians(angle))
gr.polyline(cosf * pline, sinf * pline)
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 = (r_min + i * tick) / r_max
gr.setlinecolorind(88)
r = np.clip(r, 0, 1)
if i % 2 == 1 and r <= 1:
gr.setlinecolorind(90)
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()
gr3.drawcylindermesh(1, (x, y, 0), (np.sin(theta), np.cos(theta), 0), (1, 0, 0), 0.05, A)
gr3.drawconemesh(1, (x + np.sin(theta) * A, y + np.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 / np.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
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
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()
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()
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()
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