Skip to content

Commit 1f113d2

Browse files
authored
Chaos game example in readme
1 parent fbc9c88 commit 1f113d2

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,46 @@ plot(data, layout)
244244
```
245245
![TPMS](img/TPMS.png)
246246

247+
Chaos game
248+
249+
```jl
250+
# # Chaos game
251+
#. Configure to use Arrays
252+
config({matrix:"Array"});
253+
254+
#. Define tetrahedron vertices
255+
x = [cos(pi/6), 0, -cos(pi/6), 0];
256+
y = [-sin(pi/6), 1, -sin(pi/6), 0];
257+
z = [0, 0, 0, 1 + sin(pi/6)];
258+
259+
#. Initial point (could be random)
260+
x.push(0); y.push(0); z.push(sin(pi/6));
261+
262+
#. Generate random sequence
263+
randomPoints = randomInt([2000], 1, 5);
264+
265+
#. Midpoint between current point and random
266+
rule(id) = [
267+
x.push((x[end] + x[id]) / 2),
268+
y.push((y[end] + y[id]) / 2),
269+
z.push((z[end] + z[id]) / 2),
270+
];
271+
272+
#. Chaos game iterations
273+
forEach(randomPoints, rule)
274+
275+
#. Plot
276+
trace = {
277+
x: x, y: y, z: z,
278+
type: "scatter3d",
279+
mode: "markers",
280+
marker: { size: 1, color: z, colorscale: "Viridis" }
281+
};
282+
283+
plot([trace])
284+
```
285+
![Chaos game](img/chaos.png)
286+
247287
# Warnings
248288

249289
- All calculations are done locally

img/chaos.png

43.4 KB
Loading

0 commit comments

Comments
 (0)