Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic pixel display
#1
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?

#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()
Reply
#2
In matplotlib you would use animation to have a dynamic display
Reply
#3
Thanks deanhystad

I hadn't considered animation in matplotlib as I was trying to avoid storing large data sets for plotting and also wasn't sure I could get the required individual pixel resolution.

However, as I am only just starting to use Python I will go and take another look.

Regards
Jerry
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Voxel to pixel graphics voicemail 3 587 Nov-19-2023, 09:45 AM
Last Post: paul18fr
  How to display <IPython.core.display.HTML object>? pythopen 3 46,008 May-06-2023, 08:14 AM
Last Post: pramod08728
  Pixel color and action Sartre 4 2,112 Apr-13-2023, 03:26 AM
Last Post: Sartre
Information Unable to display joystick's value from Python onto display box MelfoyGray 2 2,248 Nov-11-2020, 02:23 AM
Last Post: MelfoyGray
  Plotting Pixel Intensity Doev 0 1,734 Oct-21-2020, 10:56 PM
Last Post: Doev
  What is the best way to search for a pixel in a screenshot? TheZadok42 1 2,623 May-15-2020, 12:37 PM
Last Post: scidam
  Fast get pixel and oparate. storzo 7 7,098 Aug-26-2019, 07:36 PM
Last Post: Larz60+
  random change of color pixel with PIL louloudevinci 4 8,491 May-31-2018, 03:55 PM
Last Post: louloudevinci

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020