Script displaying animated patterns based on Collatz Conjecture. You can choose between diffrent animations and coloring schemes. Script also allows you to change various properties via command line arguments (color, position, angle, size, etc.).
You start with single positive number n. Each number in the sequence is based on the previous one. If the term is even the next one is half of that term. If it's odd next one is 3 times that term +1. Sequence ends when n = 1.
n/2 if n is even 3n+1 if n is odd
- 5,16,8,4,2,1
- 12,6,3,10,5,16,8,4,2,1
Wikipedia
Numberphile
Coding Train
- PyGame
pip install pygame
Just do: python collatz.py
It will run with default settings.
-a Animation index. Int number from 0 to 4. Default is 0.
-s Color scheme index. Int number from 0 to 8. Default is 0.
-l Line length, size of pattern. Int number of pixels. Default is 6.
-d Initial angle. Int/Float number of degrees. Default is 1.
-c Colors used in some of schemes. Float from 0 to 1. Default is 1.
-f Creates an image with currently displayed pattern when you close the window using X button. True or False. Default is False.
-x x position of the pattern. Int number of pixels. Default is 100.
-y y position of the pattern. Int number of pixels. Default is 350.
python collatz.py -a 3 -d 90 -l 10 -x 350
python collatz.py -s 6
python collatz.py -a 1 -s 8
python collatz.py -a 3 -s 4 -c 0.95 -d 120 -l 15 -x 350
python collatz.py -a 3 -s 2 -d 10 -x 350 -y 450
python collatz.py -s 6
python collatz.py -a 3 -s 8 -d 45 -l 10 -x 350
python collatz.py -a 1 -s 6 -l 20 -x 250