2019-10-07 Neurostories: videos of my talk

page in construction, please do not look if you are not adventureous !!



Let's first initialize the notebook:

In [1]:
from __future__ import division, print_function
import numpy as np
np.set_printoptions(precision=6, suppress=True)
import os
%matplotlib inline
#%config InlineBackend.figure_format='retina'
%config InlineBackend.figure_format = 'svg'
import matplotlib.pyplot as plt
phi = (np.sqrt(5)+1)/2
fig_width = 10
figsize = (fig_width, fig_width/phi)
from IPython.display import display, HTML
def show_video(filename): 
    return HTML(data='<video src="{}" loop autoplay width="600" height="600"></video>'.format(filename))
%load_ext autoreload
%autoreload 2
In [ ]:
 
In [2]:
import gizeh as gz
W, H = 500, 300
r, gray, t = 25., .3, 1.

surface = gz.Surface(W,H, bg_color=(1, 1, 1)) # white background
gradient = gz.ColorGradient(type="radial", stops_colors=[(0,(gray, gray, gray)), (1, (1, 1, 1))],
                            xy1=[0, 0], xy2=[0, 0], xy3=[0, r])
rf = gz.circle(r=r, xy=(W/2., H/2.), fill=gradient)
#rect = gz.rectangle(lx=.3*H, ly=.02*H, xy=(W*t/duration, H/2.), fill=(0,1,0), angle=np.pi/2)

rf.draw(surface)
surface.ipython_display()
Out[2]:

The flash-lag clock

And now the animation for the straight trajectory of a segment with perpendicular orientation:

In [3]:
import numpy as np
import gizeh as gz
import moviepy.editor as mpy

W, H = 1000, 600
duration = 1

figpath = '../files/2019-09-30_'
fps = 60

fix = gz.circle(r=5, xy=(W/2., H/2.), fill=(1, 0, 0))

def make_frame(t):

    surface = gz.Surface(W, H, bg_color=(0, 0, 0))
    
    # rect = gz.rectangle(lx=.3*H, ly=.02*H, xy=(W*t/duration, H/2.), fill=(0,1,0), angle=np.pi/2)
    # modul = 1 - .2*np.sin(2*np.pi*t/duration)
    # ymodul = 1 + .2*(np.cos(2*np.pi*t/duration)+1)
    lx = .4*H
    for theta in np.linspace(0, 2*np.pi, 50, endpoint=False):
        gray = .1
        rect = gz.rectangle(lx=lx, ly=2, xy=(W/2.+lx/2*np.cos(theta), H/2.+lx/2*np.sin(theta)), fill=(gray, gray, gray), angle=theta)
        rect.draw(surface)

    pastille = gz.circle(r=25, xy=(W/2., H/2.), fill=(0, 0, 0))
        
    theta = 2*np.pi*t/duration + np.pi
    rect = gz.rectangle(lx=lx, ly=2, xy=(W/2.+lx/2*np.cos(theta), H/2.+lx/2*np.sin(theta)), fill=(0,1,0), angle=theta)
    rect.draw(surface)
    if np.abs(np.sin(.5*(theta+np.pi/2))) < np.sin(np.pi/64):
        # print (theta, np.abs(np.tan(theta)), np.tan(np.pi/32), np.abs(np.tan(theta)) < np.tan(np.pi/32))
        print ('flash for ', theta)
        flash = gz.circle(r=5, xy=(W/2., H/2. - .48*H), fill=(1, 0, 0))
        flash.draw(surface)
    pastille.draw(surface)
    fix.draw(surface)
    return surface.get_npimage()

clip = mpy.VideoClip(make_frame, duration=duration)
#clip.write_videofile(figpath + 'clock.mp4', fps=fps) # Many options...

clip.ipython_display(fps=fps, width=W, autoplay=True, loop=True)
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
t:   8%|▊         | 5/60 [00:00<00:01, 40.59it/s, now=None]
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4

t:  38%|███▊      | 23/60 [00:00<00:00, 40.07it/s, now=None]
flash for  4.71238898038469
                                                            
Moviepy - Done !
Moviepy - video ready __temp__.mp4

Out[3]:

avec un flash trait

In [4]:
def make_frame(t):

    surface = gz.Surface(W, H, bg_color=(0, 0, 0))

    lx = .4*H
    for theta in np.linspace(0, 2*np.pi, 50, endpoint=False):
        gray = .1
        rect = gz.rectangle(lx=lx, ly=2, xy=(W/2.+lx/2*np.cos(theta), H/2.+lx/2*np.sin(theta)), fill=(gray, gray, gray), angle=theta)
        rect.draw(surface)

    pastille = gz.circle(r=25, xy=(W/2., H/2.), fill=(0, 0, 0))
        
    theta = 2*np.pi*t/duration + np.pi
    rect = gz.rectangle(lx=lx, ly=2, xy=(W/2.+lx/2*np.cos(theta), H/2.+lx/2*np.sin(theta)), fill=(0,1,0), angle=theta)
    rect.draw(surface)
    if np.abs(np.sin(.5*(theta+np.pi/2))) < np.sin(np.pi/64):
        print ('flash for theta=', theta, ', t=', t)
        flash = gz.rectangle(lx=.06*H, ly=2, xy=(W/2., H/2. - .47*H), fill=(1, 0, 0), angle=np.pi/2)
        flash.draw(surface)
    pastille.draw(surface)
    fix.draw(surface)
    return surface.get_npimage()

clip = mpy.VideoClip(make_frame, duration=duration)
#clip.write_videofile(figpath + 'clock.mp4', fps=fps) # Many options...

clip.ipython_display(fps=fps, width=W, autoplay=True, loop=True)
t:   0%|          | 0/60 [00:00<?, ?it/s, now=None]
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4

t:  37%|███▋      | 22/60 [00:00<00:00, 39.18it/s, now=None]
flash for theta= 4.71238898038469 , t= 0.25
                                                            
Moviepy - Done !
Moviepy - video ready __temp__.mp4

Out[4]:

avec plusieurs flash trait

In [5]:
duration = 3

def make_frame(t):

    surface = gz.Surface(W, H, bg_color=(0, 0, 0))
    lx = .4*H
    
    for theta in np.linspace(0, 2*np.pi, 50, endpoint=False):
        gray = .1
        rect = gz.rectangle(lx=lx, ly=2, xy=(W/2.+lx/2*np.cos(theta), H/2.+lx/2*np.sin(theta)), fill=(gray, gray, gray), angle=theta)
        rect.draw(surface)

    pastille = gz.circle(r=25, xy=(W/2., H/2.), fill=(0, 0, 0))
    N_spikes = 5
    for theta_ in np.linspace(0, 2*np.pi, N_spikes, endpoint=False):
        theta = 2*np.pi*t/duration + np.pi + theta_
        rect = gz.rectangle(lx=lx, ly=2, xy=(W/2.+lx/2*np.cos(theta), H/2.+lx/2*np.sin(theta)), fill=(0,1,0), angle=theta)
        rect.draw(surface)
        
        #if np.abs(np.cos(np.pi*(t/duration-.5)*N_spikes)) > np.cos(np.pi/32):
        if np.abs(np.sin(N_spikes*(theta_-theta)/2)) < np.sin(np.pi/64):
            print ('flash for theta=', theta, ', t=', t)
            flash = gz.rectangle(lx=.06*H, ly=5, xy=(W/2. + .47*H*np.cos(theta_), H/2. - .47*H*np.sin(theta_)), fill=(1, 0, 0), 
                                 angle=-theta_)
            flash.draw(surface)
        
    pastille.draw(surface)
    fix.draw(surface)
    return surface.get_npimage()

clip = mpy.VideoClip(make_frame, duration=duration)
#clip.write_videofile(figpath + 'clock.mp4', fps=fps)
clip.ipython_display(fps=fps, width=W, autoplay=True, loop=True)
t:   0%|          | 0/180 [00:00<?, ?it/s, now=None]
Moviepy - Building video ../files/2019-09-30_clock.mp4.
Moviepy - Writing video ../files/2019-09-30_clock.mp4

t:  14%|█▍        | 26/180 [00:00<00:03, 38.93it/s, now=None]
flash for theta= 3.7699111843077517 , t= 0.3
flash for theta= 5.026548245743669 , t= 0.3
flash for theta= 6.283185307179586 , t= 0.3
flash for theta= 7.5398223686155035 , t= 0.3
flash for theta= 8.79645943005142 , t= 0.3
t:  34%|███▍      | 62/180 [00:01<00:03, 38.54it/s, now=None]
flash for theta= 5.026548245743669 , t= 0.9
flash for theta= 6.283185307179586 , t= 0.9
flash for theta= 7.5398223686155035 , t= 0.9
flash for theta= 8.79645943005142 , t= 0.9
flash for theta= 10.053096491487338 , t= 0.9
t:  54%|█████▍    | 98/180 [00:02<00:02, 37.98it/s, now=None]
flash for theta= 6.283185307179586 , t= 1.5
flash for theta= 7.5398223686155035 , t= 1.5
flash for theta= 8.79645943005142 , t= 1.5
flash for theta= 10.053096491487338 , t= 1.5
flash for theta= 11.309733552923255 , t= 1.5
t:  74%|███████▍  | 134/180 [00:03<00:01, 37.58it/s, now=None]
flash for theta= 7.5398223686155035 , t= 2.1
flash for theta= 8.79645943005142 , t= 2.1
flash for theta= 10.053096491487338 , t= 2.1
flash for theta= 11.309733552923255 , t= 2.1
flash for theta= 12.566370614359172 , t= 2.1
t:  94%|█████████▍| 170/180 [00:04<00:00, 37.17it/s, now=None]
flash for theta= 8.79645943005142 , t= 2.7
flash for theta= 10.053096491487338 , t= 2.7
flash for theta= 11.309733552923255 , t= 2.7
flash for theta= 12.566370614359172 , t= 2.7
flash for theta= 13.82300767579509 , t= 2.7
t:   3%|▎         | 5/180 [00:00<00:03, 44.78it/s, now=None]  
Moviepy - Done !
Moviepy - video ready ../files/2019-09-30_clock.mp4
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4

t:  14%|█▍        | 25/180 [00:00<00:04, 37.15it/s, now=None]
flash for theta= 3.7699111843077517 , t= 0.3
flash for theta= 5.026548245743669 , t= 0.3
flash for theta= 6.283185307179586 , t= 0.3
flash for theta= 7.5398223686155035 , t= 0.3
flash for theta= 8.79645943005142 , t= 0.3
t:  35%|███▌      | 63/180 [00:01<00:02, 39.16it/s, now=None]
flash for theta= 5.026548245743669 , t= 0.9
flash for theta= 6.283185307179586 , t= 0.9
flash for theta= 7.5398223686155035 , t= 0.9
flash for theta= 8.79645943005142 , t= 0.9
flash for theta= 10.053096491487338 , t= 0.9
t:  53%|█████▎    | 96/180 [00:02<00:02, 38.64it/s, now=None]
flash for theta= 6.283185307179586 , t= 1.5
flash for theta= 7.5398223686155035 , t= 1.5
flash for theta= 8.79645943005142 , t= 1.5
flash for theta= 10.053096491487338 , t= 1.5
flash for theta= 11.309733552923255 , t= 1.5
t:  73%|███████▎  | 131/180 [00:03<00:01, 38.94it/s, now=None]
flash for theta= 7.5398223686155035 , t= 2.1
flash for theta= 8.79645943005142 , t= 2.1
flash for theta= 10.053096491487338 , t= 2.1
flash for theta= 11.309733552923255 , t= 2.1
flash for theta= 12.566370614359172 , t= 2.1
t:  93%|█████████▎| 168/180 [00:04<00:00, 37.93it/s, now=None]
flash for theta= 8.79645943005142 , t= 2.7
flash for theta= 10.053096491487338 , t= 2.7
flash for theta= 11.309733552923255 , t= 2.7
flash for theta= 12.566370614359172 , t= 2.7
flash for theta= 13.82300767579509 , t= 2.7
                                                              
Moviepy - Done !
Moviepy - video ready __temp__.mp4
Out[5]: