Skip to content

Commit 31574fc

Browse files
showing the GIF
1 parent 5ec7060 commit 31574fc

3 files changed

Lines changed: 28 additions & 11 deletions

File tree

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ Caustics ([wikipedia](https://en.wikipedia.org/wiki/Caustic_(optics))) are lumin
44

55
In [this post](https://laurentperrinet.github.io/sciblog/posts/2020-06-19-caustic-optics.html), I will develop a simple formalism to generate such patterns, with the paradoxical result that it is *very* simple to code yet generates patterns with great complexity, such as:
66

7-
![sciblog](https://laurentperrinet.github.io/sciblog/files/2020-06-19_caustique/2020-06-19_caustique.gif)
7+
<BR>
8+
<center>
9+
<img src="caustique.gif" width=61.8%/>
10+
</center>
11+
<BR>
812

913
This is joint work with artist [Etienne Rey](https://laurentperrinet.github.io/authors/etienne-rey/), in which I especially follow the ideas put forward in the series [Turbulence](http://ondesparalleles.org/projets/turbulences/).
1014

@@ -18,4 +22,17 @@ python3 -m pip install -e .
1822
```
1923
## running it
2024

21-
Launch [jupyter](https://jupyter.org/).
25+
```
26+
from caustique import init
27+
opt = init()
28+
opt.bin_dens = 8
29+
30+
from caustique import Caustique
31+
c = Caustique(opt)
32+
z = c.wave()
33+
gifname = c.plot(z)
34+
```
35+
36+
## exploring more
37+
38+
Launch [jupyter](https://jupyter.org/) and open the notebook.

caustique.gif

3.07 MB
Loading

caustique.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def init(args=[], ds=1):
1010

1111
parser = argparse.ArgumentParser()
1212
parser.add_argument("--tag", type=str, default='caustique', help="Tag")
13-
parser.add_argument("--figpath", type=str, default='2020-06-19_caustique', help="Folder to store images")
13+
parser.add_argument("--figpath", type=str, default='.', help="Folder to store images")
1414
parser.add_argument("--nx", type=int, default=5*2**8, help="number of pixels (vertical)")
1515
parser.add_argument("--ny", type=int, default=8*2**8, help="number of pixels (horizontal)")
1616
parser.add_argument("--bin_dens", type=int, default=4, help="relative bin density")
@@ -48,11 +48,11 @@ def make_gif(gifname, fnames, fps):
4848
class Caustique:
4949
def __init__(self, opt):
5050
"""
51-
Image coordinates follow 'ij' indexing, that is,
52-
* their origin at the top left,
51+
Image coordinates follow 'ij' indexing, that is,
52+
* their origin at the top left,
5353
* the X axis is vertical and goes "down",
5454
* the Y axis is horizontal and goes "right".
55-
55+
5656
"""
5757
self.ratio = opt.ny/opt.nx # ratio between height and width (>1 for portrait, <1 for landscape)
5858
X = np.linspace(0, 1, opt.nx, endpoint=False) # vertical
@@ -67,14 +67,14 @@ def wave(self):
6767
import MotionClouds as mc
6868
fx, fy, ft = mc.get_grids(self.opt.nx, self.opt.ny, self.opt.nframe)
6969
env = mc.envelope_gabor(fx, fy, ft, V_X=self.opt.V_Y, V_Y=self.opt.V_X, B_V=self.opt.B_V,
70-
sf_0=self.opt.sf_0, B_sf=self.opt.B_sf,
70+
sf_0=self.opt.sf_0, B_sf=self.opt.B_sf,
7171
theta=self.opt.theta, B_theta=self.opt.B_theta)
7272
z = mc.rectif(mc.random_cloud(env, seed=self.opt.seed))
7373
return z
7474

7575
def transform(self, z_):
7676
xv, yv = self.xv.copy(), self.yv.copy()
77-
77+
7878
dzdx = z_ - np.roll(z_, 1, axis=0)
7979
dzdy = z_ - np.roll(z_, 1, axis=1)
8080
xv = xv + self.opt.H * dzdx
@@ -94,9 +94,9 @@ def plot(self, z, gifname=None, dpi=150):
9494
hist = np.zeros((binsx, binsy, self.opt.nframe))
9595
for i_frame in range(self.opt.nframe):
9696
xv, yv = self.transform(z[:, :, i_frame])
97-
hist[:, :, i_frame], edge_x, edge_y = np.histogram2d(xv.ravel(), yv.ravel(),
98-
bins=[binsx, binsy],
99-
range=[[0, 1], [0, self.ratio]],
97+
hist[:, :, i_frame], edge_x, edge_y = np.histogram2d(xv.ravel(), yv.ravel(),
98+
bins=[binsx, binsy],
99+
range=[[0, 1], [0, self.ratio]],
100100
density=True)
101101

102102
hist /= hist.max()

0 commit comments

Comments
 (0)