Please share your favorite algorithms to generate your own fractal structure. 10,000 sats for the best-looking final figure as decided by the most upvotes. Please show both the code and figure.
I went for a Levy Curve.
import numpy as np import matplotlib.pyplot as plt A = np.array([[0.5, 0.5], [-0.5, 0.5]]) B = np.array([[0.5, -0.5], [0.5, 0.5]]) def blueFun(x): y = A @ x # Matrix multiplication return y def redFun(x): y = B @ x - np.array([[0.5], [0.5]]) # Matrix multiplication return y # Initialize x = np.array([[0.0], [0.0]]) yVecR = [] # Red points yVecB = [] # Blue points # Iteration with random selection for _ in range(25000): if np.random.rand() < 0.5: # Randomly choose blue or red function x = blueFun(x) yVecB.append(x) # Append to blue points else: x = redFun(x) yVecR.append(x) # Append to red points # Convert lists to arrays for plotting yVecR = np.hstack(yVecR).T if yVecR else np.empty((0, 2)) yVecB = np.hstack(yVecB).T if yVecB else np.empty((0, 2)) # Plotting the results plt.scatter(yVecR[:, 0], yVecR[:, 1], s=0.1, color='red', label='Red Function') plt.scatter(yVecB[:, 0], yVecB[:, 1], s=0.1, color='red', label='Blue Function') plt.xlabel('x') plt.ylabel('y') plt.legend() plt.title("Levy C Curve with Red and Blue Points") plt.show()
(I used ChatGPT to clean up my code)
You can easily run this code using Google Colab in case you don't have Jupyter installed on your own computer.
Here a visual representation of what the algorithm is doing.
If you need inspiration, you can try your hand at coding any of the fractals presented in this MathVisualProofs Youtube Channel.
reply
And here the resulting image...
reply
I love fractals so much :')
My favourite one as always been the aureal fractals, the spiral and the fibonacci series, because it's not only a repetitive rule but a self-defined rule. Plus, it's found in nature!
reply
It's a Facebook link. No good.
reply
I found another source with the same video, but on Youtube. Different channel names, so I guess one was ripped off from the other one.
reply