File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,17 @@ Which brings us to another topic entirely: restricted chaos games.
173
173
Discussing restricted chaos games in more detail is a chapter in its own right, so I will forego the discussion here.
174
174
If you are interested, please let me know and I will be more than willing to add the chapter in the future!
175
175
176
+ ## Video Explanation
177
+
178
+ Here is a video describing iterated function systems:
179
+
180
+
181
+ <div style =" text-align :center " >
182
+ <iframe width="560" height="315" src="https://www.youtube.com/embed/nIIp-vo8rHg"
183
+ frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; pic
184
+ ture-in-picture" allowfullscreen></iframe >
185
+ </div >
186
+
176
187
## Example Code
177
188
178
189
For the code in this chapter, we have decided to write it specifically for the Chaos game, not the hutchinson animations shown at the start of the chapter.
Original file line number Diff line number Diff line change 1
1
using DelimitedFiles
2
2
3
3
# This is a function to simulate a "chaos game"
4
- function chaos_game (n:: Int , shape_points; output_file = " out.dat " )
4
+ function chaos_game (n:: Int , shape_points)
5
5
6
6
# Initializing the output array and the initial point
7
- out = zeros (n,2 )
7
+ output_points = zeros (n,2 )
8
8
point = [rand (), rand ()]
9
9
10
10
for i = 1 : n
11
- out [i,:] .= point
11
+ output_points [i,:] .= point
12
12
point = 0.5 * (rand (shape_points) .+ point)
13
13
end
14
14
15
- writedlm (output_file, out)
16
-
15
+ return output_points
16
+
17
17
end
18
18
19
19
# This will generate a Sierpinski triangle with a chaos game of n points for an
25
25
shape_points = [[0.0 , 0.0 ],
26
26
[0.5 , sqrt (0.75 )],
27
27
[1.0 , 0.0 ]]
28
- chaos_game (10000 , shape_points)
28
+ output_points = chaos_game (10000 , shape_points)
29
+ writedlm (" out.dat" , output_points)
You can’t perform that action at this time.
0 commit comments