Skip to content

Instantly share code, notes, and snippets.

@Zulko
Zulko / dna_chisel_animation.py
Created May 9, 2018 10:48
Makes a GIF showing DNA Chisel's algorithm in action
# Warning: quick and dirty code.
import dnachisel as dc
import proglog
proglog.notebook()
import matplotlib.pyplot as plt
from dna_features_viewer import BiopythonTranslator, GraphicFeature
counter = [0]
@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 / awkward.py
Last active August 16, 2022 02:32
Awkward date gif code
# Code for this GIF:
# http://imgur.com/gallery/pTypr1Y
# This demonstrates how to freeze a region with MoviePy
from moviepy.editor import *
clip = (VideoFileClip("the_fault_in_our_stars.mp4")
.subclip("00:59:48.4","00:59:49.6")
.resize(width=600)
@Zulko
Zulko / zombie_france.py
Last active October 23, 2021 19:05
Zombie pandemic simulation in France
"""
Model of a Zombie outbreak in France, starting in Grenoble
This is a rewrite from this blog post by Max Berrgren:
http://maxberggren.github.io/2014/11/27/model-of-a-zombie-outbreak/
with a different country, a slightly different model, and different
libraries. The map of population density is taken from Wikimedia Commons
@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 / entwin.py
Last active April 10, 2021 01:32
Naive solution for a twin riddle
"""
Provides a naive solution to the following problem:
Given a couple (a,b), use the transformations
L: (a,b)->( 2a, b+1 )
R: (a,b)->( a+1, 2b )
to come to two equal integers.
@Zulko
Zulko / cube_solver.py
Created December 26, 2019 20:12
A cube puzzle resolution script
import numpy as np
segments_lengths = [3, 2, 2, 2, 1, 1, 1, 2, 2, 1, 1, 2, 1, 2, 1, 1, 2]
assert sum(segments_lengths) == 27
def solve(cube, position, direction, segment_number):
if segment_number == len(segments_lengths):
return cube
x, y, z = direction
a1, a2 = np.array([y, z, x]), np.array([z, x, y])
@Zulko
Zulko / bacterial_growth_animation.py
Last active December 15, 2020 17:36
Growing bacteria with population size analysis (Matplotlib/MoviePy)
"""
This script produces a video analysis proving for the first time in history
that bacterial populations grow exponentially. See the result here:
http://i.imgur.com/uoITKiA.gif
We proceed as follows:
- Download a video of bacteria growing under a microscope.
- Cut the video to keep only the first 7 seconds.
- Threshold each frame to find where the bacteria are, and compute the
@Zulko
Zulko / Eugene_hey.py
Created February 9, 2015 20:23
Eugene saying hey!
# Result: http://i.imgur.com/thrh1TU.gif
from moviepy.editor import *
# We start with a looping gif, and we will add some text
clip = VideoFileClip("eugene.gif").speedx(0.7) # slow down a little
txt = (TextClip("Hey", fontsize=78, font='Impact-Normal',
color='yellow', stroke_color='black',
stroke_width=3, kerning=1.5)
@Zulko
Zulko / param_curves.py
Last active December 15, 2020 17:33
Parametric curve animation with Python/Matplotlib/MoviePy
# IMPORTS: THIS SCRIPT REQUIRES THE PACKAGES PYLAB AND MOVIEPY
# It produces this gif: http://i.imgur.com/LbU55oK.gif
from pylab import *
import moviepy.editor as mp
from moviepy.video.io.bindings import mplfig_to_npimage
# PARAMETERS OF THE CURVE AND THE GIF