Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
a[1, i][1] *= -1
return a
np.random.seed(0)
a = np.empty([2, N, 2], dtype=np.float)
a[0, :] = -0.5 + np.random.random((N, 2)) # positions
a[1, :] = -0.5 + np.random.random((N, 2)) # velocities
a[0, :] *= (4 - 2*size)
dt = 1. / 30
step_numba = jit('f8[:,:,:](f8, f8, f8[:,:,:])')(step)
gr.setwindow(-2, 2, -2, 2)
gr.setviewport(0, 1, 0, 1)
gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE)
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
for plot in self._lstPlot:
plot.sizex, plot.sizey = self.sizex, self.sizey
plot.drawGR()
# logDomainCheck
logXinDomain = plot.logXinDomain()
logYinDomain = plot.logYinDomain()
if logXinDomain != self._logXinDomain:
self._logXinDomain = logXinDomain
self.logXinDomain.emit(self._logXinDomain)
if logYinDomain != self._logYinDomain:
self._logYinDomain = logYinDomain
self.logYinDomain.emit(self._logYinDomain)
if self._pickEvent:
event = self._pickEvent
gr.setviewport(*event.viewport)
wcPoint = event.getWC(event.viewport)
window = gr.inqwindow()
gr.setwindow(*event.getWindow())
gr.setmarkertype(gr.MARKERTYPE_PLUS)
gr.polymarker([wcPoint.x], [wcPoint.y])
gr.setwindow(*window)
def configure(self):
aspect_ratio = self.width / self.height
if aspect_ratio > 1:
rect = np.array([0, 1, 0, 1.0 / aspect_ratio])
self.size = self.width
else:
rect = np.array([0, aspect_ratio, 0, 1])
self.size = self.height
mwidth, mheight, width, height = gr.inqdspsize()
if width / (mwidth / 0.0256) < 200:
mwidth *= self.width / width
gr.setwsviewport(*rect * mwidth)
else:
gr.setwsviewport(*rect * 0.192)
gr.setwswindow(*rect)
gr.setviewport(*rect)
gr.setwindow(0, self.width, 0, self.height)
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))
x = -0.9223327810370947027656057193752719757635
y = 0.3102598350874576432708737495917724836010
f = 0.5
for i in range(200):
start = timer()
pixels = create_fractal(x-f, x+f, y-f, y+f, 500, 500, 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
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 double_pendulum(theta, length, mass):
gr.clearws()
gr.setviewport(0, 1, 0, 1)
direction = []
position = [(0, 0, 0)]
for i in range(2):
direction.append((np.sin(theta[i]) * length[i] * 2,
-np.cos(theta[i]) * length[i] * 2, 0))
position.append([position[-1][j] + direction[-1][j] for j in range(3)])
gr3.clear()
# draw pivot point
gr3.drawcylindermesh(1, (0, 0.2, 0), (0, 1, 0), (0.4, 0.4, 0.4), 0.4, 0.05)
gr3.drawcylindermesh(1, (0, 0.2, 0), (0, -1, 0), (0.4, 0.4, 0.4), 0.05, 0.2)
gr3.drawspheremesh(1, (0,0,0), (0.4, 0.4, 0.4), 0.05)
# draw rods
gr3.drawcylindermesh(2, position, direction,
(0.6, 0.6, 0.6) * 2, (0.05, 0.05),
def plot_domain(color_func, f, re=(-1, 1), im=(-1, 1), N=100, n=15):
w = func_vals(f, re, im, N)
domc = color_func(w, n) * 255
width, height = domc.shape[:2]
domc = np.append(domc, np.ones((width, height, 1)) * 255, axis=2)
domc = domc.astype(np.uint8)
domc = domc.view('
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] + np.sin(theta[i]) * length[i]]
y = [pivot[1], pivot[1] - np.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
blockdim = (32, 8)
griddim = (32, 16)
f = 0.5
for i in range(200):
start = timer()
d_image = cuda.to_device(image)
mandel_kernel[griddim, blockdim](x-f, x+f, y-f, y+f, d_image, 400)
d_image.to_host()
dt = timer() - start
print("Mandelbrot created in %f s" % dt)
ca = 1000.0 + image.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