Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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.encode("latin-1"))
#!/usr/bin/env python
# -*- animation -*-
"""
Animation of rotating DNA
"""
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()
and curve.markertype is not None):
gr.setmarkertype(curve.markertype)
gr.polymarker([x + lineWidth / 2.], [ys])
elif curve.markertype is not None:
gr.setmarkertype(curve.markertype)
gr.polymarker([x + lineWidth / 2.], [ys])
ybase = (y - charHeightUnscaled / 2) * self.sizey
ytop = (y + charHeightUnscaled / 2) * self.sizey
roi = RegionOfInterest(Point(x, ybase),
Point(x, ytop),
reference=curve,
regionType=RegionOfInterest.LEGEND)
x += lineWidth + .01
if curve.visible:
gr.settextcolorind(1)
else:
gr.settextcolorind(83)
gr.settextalign(gr.TEXT_HALIGN_LEFT,
gr.TEXT_VALIGN_HALF)
gr.text(x, ys, curve.legend)
gr.settextcolorind(1)
x += textWidth
roi.append(Point(x, ytop), Point(x, ybase))
self._legendROI.append(roi)
# gr.polyline(roi.x, roi.y)
tbx = gr.inqtext(0, 0, "X")[0]
charWidth = max(tbx) - min(tbx)
x += charWidth
# restore old values
gr.setlinecolorind(lcolor)
gr.setmarkercolorind(mcolor)
# 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), (np.cos(theta), np.sin(theta), 0), (0, 0, 1), 0.05, V)
gr3.drawconemesh(1, (x + np.cos(theta) * V, y + np.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), (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
A = 0.3 * acceleration
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
ybase = (y - charHeightUnscaled / 2) * self.sizey
ytop = (y + charHeightUnscaled / 2) * self.sizey
roi = RegionOfInterest(Point(x, ybase),
Point(x, ytop),
reference=curve,
regionType=RegionOfInterest.LEGEND)
x += lineWidth + .01
if curve.visible:
gr.settextcolorind(1)
else:
gr.settextcolorind(83)
gr.settextalign(gr.TEXT_HALIGN_LEFT,
gr.TEXT_VALIGN_HALF)
gr.text(x, ys, curve.legend)
gr.settextcolorind(1)
x += textWidth
roi.append(Point(x, ytop), Point(x, ybase))
self._legendROI.append(roi)
# gr.polyline(roi.x, roi.y)
tbx = gr.inqtext(0, 0, "X")[0]
charWidth = max(tbx) - min(tbx)
x += charWidth
# restore old values
gr.setlinecolorind(lcolor)
gr.setmarkercolorind(mcolor)
gr.setlinetype(ltype)
gr.setmarkertype(mtype)
gr.setlinewidth(lwidth)
# restore viewport and window
gr.setviewport(*self.viewportscaled)
gr.setwindow(*window)
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)
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()