Koch Snowflake

In my collection of programs generating fractals this famous one cannot miss.
The Koch snowflake is generated by starting with an equilateral triangle. Every side of the triangle then gets cut into three equal pieces and the center one gets replaced with yet another equilateral triangle.
To get the perfect fractal, you would need to repeat this process infinitely many times.
More information on the snowflake can be found in this Wikipedia entry.

Controls

  • F1 iterates the fractal
  • F2 zooms in
  • F3 zooms out
  • F4 resets zoom
  • F5 takes a screenshot
  • Arrow keys move the camera around

Koch Snowflake


# Python 2.7.7 Code
# Pygame 1.9.1 (for Python 2.7.7)
# Jonathan Frech 25th of April, 2016
#         edited 26th of April, 2016
#         edited 29th of April, 2016

Continue reading

Pascal’s Triangle

Pascal’s triangle is an interesting mathematical sequence. It is often written as a triangle, starting with \{1\}, then \{1, 1\}. To generate the next row, you add the two numbers above to form another one. So the next row in the sequence is \{1, 2, 1\} then \{1, 3, 3, 1\}, \{1, 4, 6, 4, 1\} and so on (sequence A007318 in OEIS).

One interesting property of Pascal’s triangle is the generation of binomials.
To calculate (a + b)^4, you can look at the 4th row (listed above and when starting to count at 0) and determine
(a + b)^4 = (1 \cdot a^4 \cdot b^0) + (4 \cdot a^3 \cdot b^1) + (6 \cdot a^2 \cdot b^2) + (4 \cdot a^1 \cdot b^3) + (1 \cdot a^0 \cdot b^4)
(a + b)^4 = a^4 + 4a^3b + 6a^2b^2 + 4ab^3 + b^4.

This program generates Pascal’s sequence in a rather unusual shape, looking a bit like a crown.

To get more information about Pascal’s triangle, check out this Wikipedia entry.

Controls

  • F1 advances the sequence
  • Space takes a screenshot

Fontsize 50 Fontsize 10 Fontsize 1


# Python 2.7.7 Code
# Pygame 1.9.1 (for Python 2.7.7)
# Jonathan Frech 25th of March, 2016

Continue reading

Spinning Shapes

Drawing lines according to length and angle, which change over time, this program creates pretty shapes. The changing values for both length and angle are saved in the image’s name.

Inwards star Spinning square Doubled Origin logo


# Python 2.7.7 Code
# Pygame 1.9.1 (for Python 2.7.7)
# Jonathan Frech  4th of December, 2015
#         edited  6th of December, 2015
#         edited 25th of December, 2015

Continue reading