def animate(i): if i < fps * 1: ax.set(title='Original Data') lines.set_data(x[:i], y[:i]) elif i < fps * 2: pass # pause elif i < fps * 3: ax.set(title='Min-Max Scale to 0-1') # expand x and y axis xmin = np.linspace(1.7, -.3, fps) xmin = tween(1.7, -.3, easeInCubic, fps) ymin = tween(y.min() - .3, -.3, easeInCubic, fps) ax.set(xlim=(xmin[i % fps], 4.3), ylim=(ymin[i % fps], y.max() + .3)) elif i < fps * 4: pass # pause elif i < fps * 5: ax.set(title='scale the x values') # scale x values lines.set_data(xx[i % fps], y) elif i < fps * 6: pass # pause elif i < fps * 7: ax.set(title='scale the y values') # scale y values lines.set_data(x2, yy[i % fps]) elif i < fps * 8: pass # pause elif i < fps * 9: ax.set(title='Same shape as the original data, but the scale has changed') # shrink x and y axis xmax = tween(4.3, 1.3, easeInCubic, fps) ymax = tween(y.max() + .3, 1.3, easeInCubic, fps) ax.set(xlim=(-.3, xmax[i % fps]), ylim=(-.3, ymax[i % fps]))
def transform(self, x1, x2, y1, y2, lines=None): if lines is None: lines = self._lines xx = tween(x1, x2, self._timing_fn, fps) yy = tween(y1, y2, self._timing_fn, fps) def fn(i): lines.set_data(xx[i], yy[i]) self._fns.append(fn)
def animate(i): if i < fps * 1: xmin = tween(x.min(), x_centered.min() - .5) ymin = tween(y.min(), y_centered.min() - .5) ax.set(xlim=(xmin[i%fps], ax.get_xlim()[1]), ylim=(ymin[i%fps], ax.get_ylim()[1])) elif i < fps * 2: pass elif i < fps * 3: ybar_i = tween(y.mean(), 0)[i % fps] ymin_i = tween(y.min(), -4)[i % fps] ymax_i = tween(y.max(), 4)[i % fps] xbar_i = tween(x.mean(), 0)[i % fps] xmin_i = tween(x.min(), -4)[i % fps] xmax_i = tween(x.max(), 4)[i % fps] ybarline.set_data([ybar_i, ybar_i], [xmin_i, xmax_i]) xbarline.set_data([ymin_i, ymax_i], [xbar_i, xbar_i]) elif i < fps * 4: pass elif i < fps * 5: lines.set_data(xx_centered[i % fps], yy_centered[i % fps]) elif i < fps * 6: pass elif i < fps * 7: lines.set_data(xx_scaled[i % fps], yy_scaled[i % fps]) elif i < fps * 8: pass
return baseImage.subsurface(((baseImage.get_width() - windowSize[0])*pos[0], (baseImage.get_height() - windowSize[1])*pos[1]), windowSize) base_image = pygame.image.load("res/sunflowers1.jpg") # Zoom in on a position within a larger image slowly # Zoom back out # Repeat with a new position old_image = Surface(display_size) while True: # Zoom in and out again pos = (random(), random()) steps = 100 for x in chain( tween(easeInOutCubic, 0, steps*0.6, steps, True, False), tween(easeInOutCubic, steps*0.6, 0, steps, True, False)): zoom = x / float(steps); frame = get_window_at_pos ( smoothscale(base_image, ( int(round((base_image.get_width()-display_size[0]) * zoom + display_size[0])), int(round((base_image.get_height()-display_size[1]) * zoom + display_size[1])) )), pos) cans.drawSurface(frame) cans.update() for event in pygame.event.get(): if event.type==QUIT:
import tween tween.tween(10, 1, easeInCubic, 24) # + fps = 24 plt.rc('axes.spines', top=False, right=False) plt.rc('font', size=16) plt.rc('axes', grid=False) x = np.random.uniform(2, 4, fps) y = x + np.random.normal(.5, .5, fps) x2 = sklearn.preprocessing.MinMaxScaler().fit_transform(x.reshape(-1, 1)).ravel() # xx = np.linspace(x, x2, fps) xx = tween(x, x2, easeInCubic, fps) y2 = sklearn.preprocessing.MinMaxScaler().fit_transform(y.reshape(-1, 1)).ravel() # yy = np.linspace(y, y2, fps) yy = tween(y, y2, easeInCubic, fps) fig, ax = plt.subplots(figsize=(16, 9)) lines, = ax.plot([], [], marker='o', ls='', color='firebrick') ax.set(xticks=range(-1, 5), yticks=range(-1, 6)) ax.set(ylim=(y.min() - .3, y.max() + .3), xlim=(1.7, 4.3)) def animate(i): if i < fps * 1: ax.set(title='Original Data') lines.set_data(x[:i], y[:i]) elif i < fps * 2:
# Show either gold or a random green rand_color = Color(0, 0, 0, 0) if (random() > 0.9): rand_color.hsla = (50, 100, 50, 100) else: # Green brightness = 10 if (random() > 0.4): brightness = 28 rand_color.hsla = (88 + (104 - 88) * random(), 100, brightness, 100) new_image.set_at((x, y), rand_color) # Fade onto old image steps = 30 for alpha in tween(easeInOutSine, 0,255,steps,True,False): intermediate_image = old_image.copy() new_image.set_alpha(alpha) intermediate_image.blit(new_image, (0, 0)) cans.drawSurface(smoothscale(intermediate_image, (display_size[0]*2, display_size[1]*2))) cans.update() for event in pygame.event.get(): if event.type==QUIT: sys.exit(0) time.sleep(0.9/steps) #time.sleep(0.12) new_image.set_alpha(255) old_image = new_image
def velocities(self, positions, t): return sum(tween(t) * field(positions) for field, tween in self.tweens)