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_image(self):
if not self.needs_refresh:
return
self.needs_refresh = False
gr.clearws()
gr.setwindow(0, self.w, 0, self.h)
gr.setviewport(0, 1, 0, 1)
gr3.setbackgroundcolor(1, 1, 1, 0)
vertices, normals = gr3.triangulate(data, (1.0/64, 1.0/64, 1.0/128), (-0.5, -0.5, -0.5), self.isolevel)
mesh = gr3.createmesh(len(vertices)*3, vertices, normals, np.ones(vertices.shape))
gr3.drawmesh(mesh, 1, (0,0,0), (0,0,1), (0,1,0), (1,1,1), (1,1,1))
center = spherical_to_cartesian(-2, np.pi*self.y / self.h+np.pi/2, np.pi*self.x / self.w)
up = spherical_to_cartesian(1, np.pi*self.y / self.h+np.pi, np.pi*self.x / self.w)
gr3.cameralookat(center[0], center[1], -0.25+center[2], 0, 0, -0.25, up[0], up[1], up[2])
gr3.drawimage(0, self.w, 0, self.h, self.w, self.h, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
if self.export:
gr3.export("mri.html", 800, 800)
print("Saved current isosurface to mri.html")
self.export = False
gr3.clear()
x = -0.9223327810370947027656057193752719757635
y = 0.3102598350874576432708737495917724836010
f = 0.5
for i in range(200):
start = timer()
image = np.zeros((500, 500), dtype=np.uint8)
pixels = create_fractal(x-f, x+f, y-f, y+f, image, 400)
dt = timer() - start
print("Mandelbrot created in %f s" % dt)
ca = 1000.0 + pixels.ravel()
gr.clearws()
gr.setviewport(0, 1, 0, 1)
gr.setcolormap(13)
gr.cellarray(0, 1, 0, 1, 500, 500, ca)
gr.updatews()
f *= 0.9
gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP)
gr.setcharup(-1., 0.)
tbx = gr.inqtext(0, 0, self.ylabel)[0]
tbx = [gr.wctondc(0, yi)[0] for yi in tbx]
dxYLabel = max(tbx) - min(tbx)
gr.text(self.offsetYLabel + xmin - dxYLabel / 2. - .075,
ymin + (ymax - ymin) / 2., self.ylabel)
gr.setcharup(0., 1.)
# -- draw legend and calculate ROIs for legend items -----------------
if self._legend:
x, y = xmin, y - dyXLabel - charHeightUnscaled
if y < 0:
vp = self.viewport
vp[2] += dyXLabel
self.viewport = vp # propagate update (calls setter)
gr.clearws()
self.drawGR()
else:
# preserve old values
ltype = gr.inqlinetype()
mtype = gr.inqmarkertype()
lcolor = gr.inqlinecolorind()
mcolor = gr.inqmarkercolorind()
lwidth = gr.inqlinewidth()
window = gr.inqwindow()
scale = gr.inqscale()
gr.setviewport(0, self.sizex, 0, self.sizey)
gr.setwindow(0, self.sizex, 0, self.sizey)
self._legendROI = []
for axes in self._lstAxes:
if redraw:
break
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()
gr3.setquality(4)
gr3.drawimage(0.15, 0.5, 0.46, 0.81,175,175, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
gr.settextcolorind(1)
gr.settextfontprec(6,0)
setcharheight(0.02)
settextalign(TEXT_HALIGN_LEFT, TEXT_VALIGN_BASE)
gr.mathtex(0.05,0.01,"i\\hbar\\frac{\\partial\\psi}{\\partial t} = \\frac{\\hbar^2}{2m}\\nabla^2\\psi + V(\\mathbf{r})\\psi")
x = list(range(5))
y = list(range(5))
selntran(0)
# text fonts
for i in range(-1, -23, -1):
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(4, [-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(2, x, y) # draw rod
gr.setmarkersize(3 * mass[i])
gr.polymarker(1, [x[1]], [y[1]]) # draw bob
pivot = [x[1], y[1]]
gr.updatews()
return
def draw(self):
gr.clearws()
gr.setwswindow(0, self._sizex, 0, self._sizey)
gr.setviewport(0, self._sizex, 0, self._sizey)
if self._projection == 'perspective':
gr.setperspectiveprojection(
near_plane=0.1,
far_plane=1000,
fov=15
)
else:
gr.setorthographicprojection(
left=-60, right=60,
bottom=-60, top=60,
near_plane=-60, far_plane=60
)
gr.axes3d(10, 10, 10, 50, 50, 0, 2, 2, 2, -0.0075)
self.update()
def paintEvent(self, event):
self._painter = QPainter()
self._painter.begin(self)
self._painter.fillRect(0, 0, self.width(), self.height(), self._bgColor)
os.environ["GKSconid"] = getGKSConnectionId(self, self._painter)
gr.clearws()
self.draw()
gr.updatews()
self._painter.end()
vertical_alignment = {
'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 horizontal_alignment:
for valign in vertical_alignment:
gr.settextalign(horizontal_alignment[halign], vertical_alignment[valign])
x = -0.1 + horizontal_alignment[halign] * 0.3
y = 1.1 - vertical_alignment[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)
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):