def create_simple_red_gradient(x, t):
“”“Generate a simpler gradient effect using only the red color component.”“”
r = int((math.sin(t / 2 + x / (WIDTH/3)) + 1) * 127)
return graphics.create_pen(r, 0, 0) # Only red varies, green and blue are set to 0
def update_display(t):
“”“Update the display with a new, simpler gradient and vertical lines.”“”
for x in range(i75.width):
for y in range(0, i75.height, 2): # Update every other row
if x % 4 == 0: # Draw a vertical line every 4 pixels
pen = graphics.create_pen(255, 255, 255) # White color for the line
else:
pen = create_simple_red_gradient(x, t)
graphics.set_pen(pen)
graphics.pixel(x, y)
i75.update()
Screen dimensions
WIDTH = i75.width
HEIGHT = i75.height
Main loop
t = 0
while True:
update_display(t)
t += 1
time.sleep(0.05) # Adjust for different animation speeds
I’ve really simplified my code and I’m wondering if this hardare is actually not made at all to display animations?
It should be pretty capable of animations, I would take a wild guess that the problem here is MicroPython. Like Python, it isn’t the fastest language, and you’re calling the red generating function very frequently.
If you’re not a fan of C, then the only thing I can suggest is trying to simplify the red generation function, or if it is a linear gradient trying to draw all pixels of the same colour at the same time rather than generating the shade of red for every single pixel.
I have nothing against using C but can’t find any documentation about it.
Would you have any suggestions regarding where should I look to use C instead of Python?
It seems very unlikely that just using Python would reduce you to 1 frame per second; yes, it’s not as efficient as C but not that order of magnitude.
Your code is relatively inefficient though - you’re regenerating your red gradient pen every pixel, despite the fact that it only changes by column, so you’re calling expensive trig functions at least 32 times more often than you require.
(you’re also rebuilding the white pen every time you need a white pixel, but that probably doesn’t carry such a big cost)
I’ve got a 64x64 panel somewhere; if I can dust it off I’ll try your existing code because I’m surprised it’s that bad and makes me wonder if you’ve got an odd hardware issue or something…
ETA: Ok, the indenting has got lost in your code (enclose it in three backticks - ``` - will format it properly), but is it possible you’re calling the update inside the deepest loop? Because I did that by accident and the refresh rate was painful, but pulling it out so it’s only called once at the end of update_display made it perform much more as I expected.
(and yes, only setting the red pan when x changes also helps)