@@ -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
0 commit comments