Gorillaz Code
From Predictive Chemistry
Revision as of 13:49, 24 February 2016 by David M. Rogers (talk | contribs)
Use the following image files:
And base your work on the following code:
<source lang="python"> import matplotlib.pyplot as plt import Image, time import numpy as np
- 0. Import some images
L = np.array(Image.open("L.png")) # 208 x 208 R = np.array(Image.open("R.png")) # 205 x 205 ban = np.array(Image.open("banana.png")) # 105 x 100
L = L[:,:,0] R = R[:,:,0] ban = ban[:,:,0]
- print L.shape, R.shape, ban.shape
- exit()
x0 = 100 y0 = 50 x1 = 500 y1 = 400
def draw(x, y):
# 1. create an array Z = np.zeros((1000,1000))
# 2. Add images to array Z[x0:x0+208,y0:y0+208] = L Z[x1:x1+205,y1:y1+205] = R Z[x:x+105,y:y+100] = ban return Z
Z = draw(300,50)
- 3. show the array
plt.imshow(Z, cmap = plt.cm.gray) plt.show()
fig = plt.gcf() def animate(cb, args=(), n=200):
tstart = time.time() data = cb(*args) im = plt.imshow(data, origin='lowerleft') for i in range(1, n): data = cb(*args) im.set_data(data) fig.canvas.draw() print "FPS:", n/(time.time() - tstart)
- animate(draw, (50,100))
</source>