Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# coding: utf-8
import scene
import ui
from PIL import Image as PILImage
class MyScene (scene.Scene):
def setup(self): ='tunnelswirl.gif')
self.mypalette =
self.savefile = 'tmp.png'
self.toggle_state = False
self.sprite = scene.SpriteNode(scene.Texture(ui.Image.named('Snake')),
def update(self):
if self.toggle_state:
new_im ="RGBA",
self.sprite.texture = scene.Texture(ui.Image.named(self.savefile))
except EOFError: ='tunnelswirl.gif')
#self.mypalette =
def touch_began(self, touch):
self.toggle_state = not self.toggle_state
if not self.toggle_state:
self.sprite.texture = scene.Texture(ui.Image.named('Snake')), show_fps=True)
Copy link

cclauss commented Jun 24, 2016

On EOFError couldn't you just instead of closing, reopening the image and resetting the palette?

An even slicker way to go might be to try to leverage ImageSequence.

In any case reducing "disk" IO from the animation process should speed things up a bit. I would have submitted a pull request but this code is in a gist, not in a repo.

Copy link

use seek(0) instead of opening and closing again as suggested by @ccc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment