Last active
July 10, 2019 19:32
-
-
Save klarh/86a9b3ae71cd9d894a50f730db2ee1ea to your computer and use it in GitHub Desktop.
Generate a quasicrystal animation using plato-draw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
povray | |
xvfb | |
libglu1-mesa | |
libgl1-mesa-dri |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# specify dependencies for myblender.org operation (see also apt.txt | |
# for the full set) | |
channels: | |
- conda-forge | |
dependencies: | |
- cython | |
- fresnel | |
- freud | |
- hoomd | |
- pyglet | |
- pip | |
- pip: | |
- matplotlib | |
- pythreejs | |
- git+https://github.com/vispy/vispy | |
- plato-draw | |
- gtar | |
- git+https://github.com/klarh/flowws | |
- git+https://github.com/klarh/hoomd_flowws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# set to True to use vispy webGL backend (but disable saving video frames)\n", | |
"live = False" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"if not live:\n", | |
" import vispy.app; vispy.app.use_app('pyglet')\n", | |
"import plato, plato.draw.vispy as draw\n", | |
"import ipywidgets" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"L = 50\n", | |
"w = .25\n", | |
"N = int(L/w)\n", | |
"\n", | |
"xs = np.linspace(-L/2, L/2, N, endpoint=False)\n", | |
"thetas = np.linspace(0, 2*np.pi, 7, endpoint=False)\n", | |
"\n", | |
"starts = np.array([xs, np.zeros_like(xs) + L]).T\n", | |
"ends = np.array([xs, np.zeros_like(xs) - L]).T\n", | |
"\n", | |
"prim_starts = []\n", | |
"prim_ends = []\n", | |
"for theta in thetas:\n", | |
" rotmat = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]])\n", | |
" prim_starts.append(np.dot(starts, rotmat))\n", | |
" prim_ends.append(np.dot(ends, rotmat))\n", | |
" \n", | |
"def get_colors(t=0):\n", | |
" result = np.ones((len(thetas), N, 4))\n", | |
" lengthscale = 6 + .5*np.sin(t/6 + 3)\n", | |
" for (target, theta) in zip(result, thetas):\n", | |
" target[:, :3] = plato.cmap.cubeellipse(theta, h=1.8)\n", | |
" target[:, :3] *= .5 + .5*np.cos(t + xs*lengthscale)[:, np.newaxis]\n", | |
" result = result.reshape((-1, 4))\n", | |
" return result\n", | |
"\n", | |
"prim_starts = np.concatenate(prim_starts, axis=0)\n", | |
"prim_starts = np.hstack([prim_starts, prim_starts[:, :1]*0])\n", | |
"prim_ends = np.concatenate(prim_ends, axis=0)\n", | |
"prim_ends = np.hstack([prim_ends, prim_ends[:, :1]*0])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"prim = draw.Lines(\n", | |
" start_points=prim_starts, end_points=prim_ends,\n", | |
" widths=np.ones(len(prim_starts))*w)\n", | |
"\n", | |
"features = dict(ambient_light=.25, directional_light=[(0, 0, 0)], \n", | |
" additive_rendering=True)\n", | |
"scene = draw.Scene(prim, features=features, zoom=60/L)\n", | |
"\n", | |
"def update(t=0):\n", | |
" prim.colors = get_colors(t)\n", | |
" \n", | |
" theta = 2*np.pi/80*np.cos(t/9)\n", | |
" quat = (np.cos(theta/2), 0, 0, np.sin(theta/2))\n", | |
" scene.rotation = quat\n", | |
" \n", | |
" scene.render()\n", | |
"\n", | |
"tmax = 48*np.pi\n", | |
"\n", | |
"if live:\n", | |
" update()\n", | |
" scene.show()\n", | |
" ipywidgets.interact(update, t=(0., tmax))\n", | |
"else:\n", | |
" for (i, t) in enumerate(np.linspace(0, tmax, 60*30)):\n", | |
" fname = 'frame.{:05d}.png'.format(i)\n", | |
" update(t)\n", | |
" scene.save(fname)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"!ffmpeg -y -framerate 30 -i frame.%05d.png -filter:v \"crop=(trunc(iw/16)*16):(trunc(ih/16)*16)\" -c:v libx264 -preset slow -crf 20 -threads 4 -pix_fmt yuv420p 7fold.mp4" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"!rm frame.*.png" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
xvfb-run -a -s "-screen 0 1600x1200x24 +extension GLX +render +iglx" "${@}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment