Home About Random
import numpy as np
from moviepy.editor import *
from moviepy.video.tools.segmenting import findObjects

# WE CREATE THE TEXT THAT IS GOING TO MOVE, WE CENTER IT.

screensize = (720,460)
txtClip = TextClip('Cool effect',color='white', font="Amiri-Bold",
                   kerning = 5, fontsize=100)
cvc = CompositeVideoClip( [txtClip.set_pos('center')],
                        size=screensize)

# THE NEXT FOUR FUNCTIONS DEFINE FOUR WAYS OF MOVING THE LETTERS


# helper function
rotMatrix = lambda a: np.array( [[np.cos(a),np.sin(a)], 
                                 [-np.sin(a),np.cos(a)]] )

def vortex(screenpos,i,nletters):
    d = lambda t : 1.0/(0.3+t**8) #damping
    a = i*np.pi/ nletters # angle of the movement
    v = rotMatrix(a).dot([-1,0])
    if i%2 : v[1] = -v[1]
    return lambda t: screenpos+400*d(t)*rotMatrix(0.5*d(t)*a).dot(v)
    
def cascade(screenpos,i,nletters):
    v = np.array([0,-1])
    d = lambda t : 1 if t<0 else abs(np.sinc(t)/(1+t**4))
    return lambda t: screenpos+v*400*d(t-0.15*i)

def arrive(screenpos,i,nletters):
    v = np.array([-1,0])
    d = lambda t : max(0, 3-3*t)
    return lambda t: screenpos-400*v*d(t-0.2*i)
    
def vortexout(screenpos,i,nletters):
    d = lambda t : max(0,t) #damping
    a = i*np.pi/ nletters # angle of the movement
    v = rotMatrix(a).dot([-1,0])
    if i%2 : v[1] = -v[1]
    return lambda t: screenpos+400*d(t-0.1*i)*rotMatrix(-0.2*d(t)*a).dot(v)



# WE USE THE PLUGIN findObjects TO LOCATE AND SEPARATE EACH LETTER

letters = findObjects(cvc) # a list of ImageClips


# WE ANIMATE THE LETTERS

def moveLetters(letters, funcpos):
    return [ letter.set_pos(funcpos(letter.screenpos,i,len(letters)))
              for i,letter in enumerate(letters)]

clips = [ CompositeVideoClip( moveLetters(letters,funcpos),
                              size = screensize).subclip(0,5)
          for funcpos in [vortex, cascade, arrive, vortexout] ]

# WE CONCATENATE EVERYTHING AND WRITE TO A FILE

final_clip = concatenate_videoclips(clips)
final_clip.write_videofile('../../coolTextEffects.avi',fps=25,codec='mpeg4')
import numpy as np
from moviepy.editor import *
from moviepy.video.tools.segmenting import findObjects

# WE CREATE THE TEXT THAT IS GOING TO MOVE, WE CENTER IT.

screensize = (720,460)
txtClip = TextClip('Cool effect',color='white', font="Amiri-Bold",
                   kerning = 5, fontsize=100)
cvc = CompositeVideoClip( [txtClip.set_pos('center')],
                        size=screensize)

# # THE NEXT FOUR FUNCTIONS DEFINE FOUR WAYS OF MOVING THE LETTERS


# # helper function
# rotMatrix = lambda a: np.array( [[np.cos(a),np.sin(a)], 
#                                  [-np.sin(a),np.cos(a)]] )

# def vortex(screenpos,i,nletters):
#     d = lambda t : 1.0/(0.3+t**8) #damping
#     a = i*np.pi/ nletters # angle of the movement
#     v = rotMatrix(a).dot([-1,0])
#     if i%2 : v[1] = -v[1]
#     return lambda t: screenpos+400*d(t)*rotMatrix(0.5*d(t)*a).dot(v)
    
# def cascade(screenpos,i,nletters):
#     v = np.array([0,-1])
#     d = lambda t : 1 if t<0 else abs(np.sinc(t)/(1+t**4))
#     return lambda t: screenpos+v*400*d(t-0.15*i)

# def arrive(screenpos,i,nletters):
#     v = np.array([-1,0])
#     d = lambda t : max(0, 3-3*t)
#     return lambda t: screenpos-400*v*d(t-0.2*i)
    
# def vortexout(screenpos,i,nletters):
#     d = lambda t : max(0,t) #damping
#     a = i*np.pi/ nletters # angle of the movement
#     v = rotMatrix(a).dot([-1,0])
#     if i%2 : v[1] = -v[1]
#     return lambda t: screenpos+400*d(t-0.1*i)*rotMatrix(-0.2*d(t)*a).dot(v)



# # WE USE THE PLUGIN findObjects TO LOCATE AND SEPARATE EACH LETTER

# letters = findObjects(cvc) # a list of ImageClips


# # WE ANIMATE THE LETTERS

# def moveLetters(letters, funcpos):
#     return [ letter.set_pos(funcpos(letter.screenpos,i,len(letters)))
#               for i,letter in enumerate(letters)]

# clips = [ CompositeVideoClip( moveLetters(letters,funcpos),
#                               size = screensize).subclip(0,5)
#           for funcpos in [vortex, cascade, arrive, vortexout] ]

# # WE CONCATENATE EVERYTHING AND WRITE TO A FILE

# final_clip = concatenate_videoclips(clips)
# final_clip.write_videofile('../../coolTextEffects.avi',fps=25,codec='mpeg4')
get_ipython().system('pip install ipythonblocks')
from ipythonblocks import BlockGrid
grid
grid[0:4, 0:3]
for block in grid:
    if block.row % 2 == 0 and block.col % 3 == 0:
        block.red = 0
        block.green = 0
        block.blue = 0
grid
get_ipython().system('pip install ipythonblocks')
from ipythonblocks import BlockGrid
grid
grid[0:4, 0:3]
for block in grid:
    if block.row % 2 == 0 and block.col % 3 == 0:
        block.red = 0
        block.green = 0
        block.blue = 0
grid
from ipythonblocks import BlockGrid, colors
grid = BlockGrid.from_web('LcpBcb')
grid
from ipythonblocks import BlockGrid
hoshis = [3,9,15]
color = {'b': (0,0,0), 'w': (255,255,255), 't': (220,200,0), 'h': (255,100,0)}
game = 'b16,4 w4,17 b16,16 w4,3 b16,11 w14,3'

grid= BlockGrid(19,19, fill=color['t'], block_size=17)

for y in hoshis:
    for x in hoshis:
        grid[y,x] = color['h']

for m in game.split(' '):
    x,y = m[1:].split(',')
    grid[int(y)-1, int(x)-1] = color[m[0:1]]
grid
grid.post_to_web('1:8')