Mar-17-2023, 01:05 PM
I am developing a relatively simple program in Python to allow students to explore recurrence relations of the form x(n+1) = (1+b)F(xn) – bx(n-1). The results are ‘dust’ type fractals based on work by Gumowski and Mira. Each iteration of the function generates a single (x,y) point
The code generating iterations is relatively trivial. However, as a newcomer to Python I am looking for the most efficient method that enables students to see how the iterations (orbits) evolve on screen, iteration by iteration, pixel by pixel.
I have already looked at Pillow and matplotlib but neither option provides the dynamic display I am looking for. The code extract below (without additional user interface details) shows an example using matplotlib. A friend has suggested using Pygame but commented that it can be quite slow to update for large numbers of pixels.
Does anyone have any better suggestions for a non-expert before I investigate using Pygame gfx?
The code generating iterations is relatively trivial. However, as a newcomer to Python I am looking for the most efficient method that enables students to see how the iterations (orbits) evolve on screen, iteration by iteration, pixel by pixel.
I have already looked at Pillow and matplotlib but neither option provides the dynamic display I am looking for. The code extract below (without additional user interface details) shows an example using matplotlib. A friend has suggested using Pygame but commented that it can be quite slow to update for large numbers of pixels.
Does anyone have any better suggestions for a non-expert before I investigate using Pygame gfx?
#mira exmple using matplotlib to visualise static result
import matplotlib.pyplot as plt
#initialise base parameters
a = 0.5
b = 0.998
#set starting point
x = 0
y = 12.1
#set level of iterations
p = 10000
#initialise arrays for holding x , y results
x_plot = [0]
y_plot = [12.1]
#define f(x) and generate starting value
f = (a*x + ((2-2*a)*x**2))/(1+x**2)
for n in range(0,p):
z = x
x = b*y + f
f = (a*x + ((2-2*a)*x**2))/(1+x**2)
y = f - z
x_plot.append(x)
y_plot.append(y)
plt.style.use('classic')
fig, ax = plt.subplots()
ax.scatter(x_plot, y_plot, s = 1)
plt.show()
