MATH3062 S12023 Lab 1 New
MATH3062 S12023 Lab 1 New
The purpose of this lab is to get practice with Python and to implement a simple
Python program to produce iterates converging to the Sierpinski Triangle.
Python is an open source programming language and there are various different
ways to run it. Most computers now have Python interpreters in-built, but they
may be older versions, so make sure you have version 3.6 or above to avoid strange
problems.
The ANU computers have various environments and versions of Python installed
but the one we recommend is called Spyder. You can download a version on your
own computer here: https://www.spyder-ide.org/.
Instructions:
(1) Download and install a Python environment on your computer. Spyder /
Anaconda is recommended. If you need assistance with this please ask your
demonstrator. Paste lab1_partial.py, into your Python environment (see
page 3 of the lab in edX).
(2) Follow the outline and and tips below to complete the code to render your
first fractal!
Goals: To modify the original program so that it can produce a sequence of iterates
converging to the Sierpinski triangle. Please note that the program will require
substantial editing.
Understanding the code. The best way to understand some code is to do some
experiments. Consider this “experimental mathematics” through code.
You will see in the code that the variables image and next_image are 512 × 512
arrays. They represent grayscale images, where a value of 0 gives a black pixel, and
the value 255 gives a white pixel. Any integer between 0 and 255 gives a gray pixel
in between black and white.
As we are plotting the image of a set A under repeated applications of the Hutchin-
son operator F , we only want to plot a black and white image. So the values of our
array will be either 0 for black (the background) or 255 for white (which means that
the pixel is in F ◦n (A)).
1
2 LAB 1 MATH 3062 / 6116, SEMESTER 1 2023
To submit:
(1) (7 points)
a) Submit your final code (preferably in pdf format).
b) Submit 3 output images, corresponding to 3, 4 and 5 iterations of the
IFS F = (f1 , f2 , f3 ).
(2) (7 points) Write down the three affine contraction mappings f1 , f2 , f3 you
use in your code in projective notation
x a b e x
f( y ) = c d g
y
1 0 0 1 1
Most programming languages including python use non standard coordinate sys-
tem, where x is the vertical axis and y is the horizontal axis, and the origin is in
the top left corner. Trying to use standard Sierpinski triangle coefficients in your
program will result in triangle, that is lying on its side (see image on the next page).
However your output should be standard oriented Sierpinski triangle.