Skip to content

Instantly share code, notes, and snippets.

@Zulko
Zulko / ddeint.py
Created October 22, 2013 06:24
A simple Delay Differential Equation solver written in Python, using the solving capabilities of the Scipy package.
# REQUIRES PACKAGES Numpy AND Scipy INSTALLED
import numpy as np
import scipy.integrate
import scipy.interpolate
class ddeVar:
""" special function-like variables for the integration of DDEs """
def __init__(self,g,tc=0):
""" g(t) = expression of Y(t) for t<tc """
@Zulko
Zulko / nx_merge_nodes.py
Last active June 9, 2023 03:23
This is a function to merge several nodes into one in a Networkx graph
# This is a function to merge several nodes into one in a Networkx graph
def merge_nodes(G,nodes, new_node, attr_dict=None, **attr):
"""
Merges the selected `nodes` of the graph G into one `new_node`,
meaning that all the edges that pointed to or from one of these
`nodes` will point to or from the `new_node`.
attr_dict and **attr are defined as in `G.add_node`.
"""
@Zulko
Zulko / graph_editor.py
Last active April 27, 2021 19:15
This function enables to manually draw a graph (nodes and edges) that can then be used in Python (with Networkx for instance)It's extremely simple: >>> nodes, edges, nodes_positions = graph_editor()
import matplotlib.pyplot as plt
import numpy as np
def graph_editor(grid=True, grid_N = 12):
"""
This function enables to draw a graph manually using
Matplotlib's interactive plotting capabilites.
In a first phase you are asked to place the nodes
(left-click to place a node, right-click to remove
@Zulko
Zulko / limehouse_nights_moviepy.py
Last active September 14, 2017 20:37
Source for my music video on Gershwin's Limehouse Nights
"""
Code for a music video where sheet music is
scrolled transparently on my hands playing the
piano. See that effect here:
https://www.youtube.com/watch?v=V2XCJNZjm4w
"""
from moviepy.editor import *
@Zulko
Zulko / testelm.elm
Last active August 29, 2015 14:01
Tests for elm
type Coord = (Float, Float)
type Node = { label : String
, coord : Coord
}
type Edge = { color : Int
, n1 : Node
, n2 : Node
}
@Zulko
Zulko / turkish_march_video.py
Created June 9, 2014 06:07
The Turkish March on a computer keyboard - source code of the video editing
# coding: utf-8
#
# This is the Python/MoviePy code used to generate
# this video of me playing the Turkish March on my
# computer's keyboard. Enjoy !
#
# https://www.youtube.com/watch?v=z410eauCnHc
#
@Zulko
Zulko / soccer_cuts.py
Last active December 22, 2023 05:59
A python script to automatically summarize soccer videos based on the crowd's reactions
#
# This Python script makes a summary of a football game by cutting
# the video around the 10 % loudest moments, which generally
# include the goals and other important events.
# For more details, see this blog post:
# http://zulko.github.io/blog/2014/07/04/automatic-soccer-highlights-compilations-with-python/
#
# LICENCE: Creative Commons 0 - Public Domain
# I, the author of this script, wave any rights and place this work in the public domain.
#
@Zulko
Zulko / analyze.py
Last active August 29, 2015 14:05 — forked from seanmckaybeck/analyze.py
'''
Rewrite with Twittcher ;)
Result (every 20 seconds):
>>> Most common words: [('ferguson', 41), ('http', 28), ('protests', 9),
('missouri', 9), ('leave', 8), ('continue', 8),...]
'''
import re
from collections import Counter
from twittcher import SearchWatcher
@Zulko
Zulko / moviepy_motion_blur.py
Last active December 10, 2022 07:03
Motion blur in MoviePy.
import numpy as np
def supersample(clip, d, nframes):
""" Replaces each frame at time t by the mean of `nframes` equally spaced frames
taken in the interval [t-d, t+d]. This results in motion blur."""
def fl(gf, t):
tt = np.linspace(t-d, t+d, nframes)
avg = np.mean(1.0*np.array([gf(t_) for t_ in tt]),axis=0)
return avg.astype("uint8")
return clip.fl(fl)
@Zulko
Zulko / moviepy_cat_in_a_box.py
Last active December 15, 2020 15:03
Gif with a cat jumping in a box
# Result: http://i.imgur.com/Lmj21mR.gif
import moviepy.editor as mpy
from moviepy.video.tools.drawing import color_split
# LOAD THE GIF SEVERAL TIMES
clip = VideoFileClip("./source.gif")
W,H = SIZE = clip.size
duration = clip.duration