A visualization tool for chaos game parameter adjustments
4000x4000 Example Output Images »
Inspired by this video uploaded by Numberphile
Adjust parameters to create unexpected output from seemingly random data points, with the option to save the output as a high resolution image.
Examples of line reduction method
Examples of points reduction method
Built with Python 3.7.8, Kivy, Datashader, Numba (Jit), and more
- We begin by constructing the vertices of a regular polygon with V sides.
- Start at any arbitrary initial point in the xy plane. (the final output will be the same regardless of the chosen point). Here, vertex 0 of the constructed polygon will always be chosen as the initial point for consistentcy).
- At each step a vertex is randomly chosen (further restrictions can be applied with rule sets and probabilites)
- A new point is added by moving halfway from the chosen vertex to the current point (further adjusted with compression).
- The newly plotted point becomes the current point and steps [3, 5] are repeated until N points are created
-
With such a large number of points, we'll run into some serious plotting issues just mapping each point to its (x,y) location, namely overplotting and oversaturation.
-
To better visualize our output, we are overlaying our (x,y) points on a canvas (our image) and binning the data points into groups based on which pixel of the canvas they would fall onto. The data is further categorized in these bins by the outer vertex that was chosen when they were initially created. The value of these bins determines the 'brightness' of each pixel in our final image.
-
From here the bins are flushed through a histogram equalization function which makes sure each 'brightness' level is equally represented throughout the image.
-
Finally based on the colormap chosen, each outer vertex is assigned a color, this color will then be applied to the subcategories of each bin. The color assigned to a pixel is a composition of the subcategory colors in that pixel's bin scaled relative to their size (i.e. a mostly blue bin will appear mostly blue, while a bin with an even mix of blue and yellow will appear green).
To get a local copy up and running follow these simple steps.
- Create a Python 3.7.8 virtual environment (this tool will not be able to run on the more recent versions of python)
$ virtualenv -p < path to Python 3.7.8 > venv_chaos_game
- Install the required packages within the created virtual environment after copying this repos' files to the virtual environment.
$ pip install -r requirements.txt
- Run the visualization tool with the following from within the virtual environment:
$ python main.py
The Datashader reduction method that will be used.
-
Line: Computes a reduction by pixel, mapping data to pixels as one or more lines.
-
Points: Computes a reduction by pixel, mapping data to pixels as points.
Sets restrictions on the outer vertex that will be selected next.
- Standard:
- The standard rule set. Any outer vertex can be chosen to draw the next point from.
- Not Prev (Not previous):
- Any out vertex can be chosen other than the one that was chosen in the last step. (i.e cannot choose any outer vertex consectutively)
- Not CCW (Not counter-clockwise):
- Can be any of the outer vertices other than the one directly CCW to the previously chosen one.
- Not CW (Not clockwise):
- Can be any of the outer vertices other than the one directly CW to the previously chosen one.
- Not Opposite:
- Can not be the point directly opposite of the previously chosen vertex. Has no effect when V is odd.
- Not Adj (Not adjacent):
- The chosen vertex cannot be a vertex adjacent to the previously chosen vertex.
- Not Adj Prev2 (Not adjacent to either of the previous 2 vertices chosen):
- The chosen vertex cannot be a vertex adjacent to either of the previously chosen vertices.
- Not Adj Prev2 Same (Not adjacent to the previous vertex if the previous 2 chosen vertices were the same):
- The chosen vertex cannot be a vertex adjacent to the previous vertex, if the previous two vertices were the same.
Can be uniquely applied to each outer vertex. Defaults to 2 if left empty or input is invalid
How much of the distance to the new point from the randomly chosen vertex is traveled. A value of 3 would result in the point being drawn 1/3 of the distance to the lastly created point from the chosen vertex.
Example of Compression with a value of 3
Can be uniquely applied to each outer vertex. Defaults to 0 if left empty or input is invalid
Expressed in degrees. Rotation is applied counter clockwise about the chosen outer vertex.
Example of a 45 degree rotation about V1
Can be uniquely applied to each outer vertex. Defaults to 1/V if left empty or input is invalid.
Values will be scaled and adjusted to sum to 1 with proportion kept the same. For example, if V=4 and Probability = [1, 2, 1, 1], Probability will be adjusted to [0.2, 0.4, 0.2, 0.2].
Two options for output. Both will create an image in the directory of that main is ran from that will be overwritten on subsequent button presses. You will need to navigate to this directory and rename or move the .png file to save a copy of the image.
- Update Image with Current Parameters:
- will create a new 1000x1000 image named image1000.png with N points using the parameters chosen and update the image on the right of the display.
- Output a High Quality Version of This Image:
- will create a new 4000x4000 named image4000.png with 250,000,000 (points reduction) or 15,000,000 (line reduction) points in the data set.
- This can take quite a long time, and may cause the application to crash if attempted on a poorly specced pc.
For more examples, please refer to the Examples shown on Imgur
Distributed under the MIT License. See MIT License for more information.