Skip to content

Instantly share code, notes, and snippets.

@nicoguaro
Last active October 11, 2021 23:16
Show Gist options
  • Save nicoguaro/e2ace1a3cffa21d16fa4066b89bba4c4 to your computer and use it in GitHub Desktop.
Save nicoguaro/e2ace1a3cffa21d16fa4066b89bba4c4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Effect of waves moving.
Inspired by Juan Carlos Ponce
https://mobile.twitter.com/jcponcemath/status/1447388869033283591?t=UJAyYdVEGm3DYvp-ESCByA&s=09
Alt-text: 5 waves propagating from left to right. They are depicted
as discrete lines in a purple color scale.
@author: Nicolás Guarín-Zapata
@date: October 2021
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
plt.rcParams["lines.solid_capstyle"] = "round"
plt.rcParams["lines.linewidth"] = 3
plt.rcParams["axes.facecolor"] = "#3c3c3c"
plt.rcParams["figure.facecolor"] = "#3c3c3c"
fpath = "texgyreadventor-regular.otf"
prop = fm.FontProperties(fname=fpath)
npts = 50
T = 3*np.pi
phase = np.pi/4
neg_width = 0.4
colors = ["#edf8fb", "#bfd3e6", "#9ebcda", "#8c96c6", "#8c6bb1", "#88419d",
"#6e016b"]
colors.reverse()
x = np.linspace(0, T, npts)
y1 = np.zeros_like(x)
y6 = np.zeros_like(x) + 10
plt.figure(figsize=(8, 3))
for cont in range(npts):
plt.gca().cla()
y2 = np.sin(x + 0*phase - 2*cont*T/npts) + 2
y3 = np.sin(x + 1*phase - 2*cont*T/npts) + 4
y4 = np.sin(x + 2*phase - 2*cont*T/npts) + 6
y5 = np.sin(x + 3*phase - 2*cont*T/npts) + 8
plt.vlines(x, y1, y2 - neg_width, colors=colors[0])
plt.vlines(x, y2, y3 - neg_width, colors=colors[1])
plt.vlines(x, y3, y4 - neg_width, colors=colors[2])
plt.vlines(x, y4, y5 - neg_width, colors=colors[3])
plt.vlines(x, y5, y6, colors=colors[4])
plt.axis("off")
plt.text(10, -1.5, "@nicoguaro", fontsize=16, color="#D9D9D9",
horizontalalignment='right',
fontproperties=prop, alpha=0.7)
plt.tight_layout()
plt.savefig("wave_%s.png" % str(cont).zfill(2), dpi=300)
plt.show()
#!/bin/bash
#
# Generate an animation (.avi, .gif) from a sequence of image with
# the same name and a sequence of numbers.
#
# The usage is
# $ vid_gen <file_name> <output_file>
IMG_FILE=$1
VID_OUTPUT=$2
mencoder "mf://*.png" -mf type=png:fps=5 -ovc lavc -o $VID_OUTPUT.avi
convert $IMG_FILE*.png -delay 40 -loop 1 -channel Alpha $VID_OUTPUT.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment