Skip to content

Commit

Permalink
14
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Oct 15, 2023
1 parent 3bfa9e1 commit 147eb15
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
Binary file added 2023/sketch_2023_10_14/a.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2023/sketch_2023_10_14/sketch_2023_10_14.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions 2023/sketch_2023_10_14/sketch_2023_10_14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from itertools import count
from PIL import Image
import py5

def setup():
global gif
py5.size(500, 500)
gif = Py5Gif('a.gif')

def draw():
gif.draw(50, 50, 400, 400)

class Py5Gif():
def __init__(self, pil_img):
if isinstance(pil_img, (py5.Path, str)):
im = Image.open(pil_img)
self.loc = 0
self.frames = []
self.previous = None

try:
for i in count(1):
self.frames.append(py5.convert_image(im.copy()))
im.seek(i)
except EOFError:
pass

try:
self.delay = im.info['duration']
except:
self.delay = 100

def draw(self, x, y, w=None, h=None):
if not self.previous or py5.millis() - self.previous > self.delay:
self.loc = (self.loc + 1) % len(self.frames)
self.previous = py5.millis()
py5.image(self.frames[self.loc], x, y, w, h)

py5.run_sketch(block=False)
10 changes: 10 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ Here are listed some of the tools I have been using:

---

### sketch_2023_10_14

![sketch_2023_10_14](https://raw.githubusercontent.com/villares/sketch-a-day/main/2023/sketch_2023_10_14/sketch_2023_10_14.gif)

[sketch_2023_10_14](https://github.com/villares/sketch-a-day/tree/main/2023/sketch_2023_10_14) [[py5](https://py5coding.org/)]

first attempt at showing a GIF animation with py5...

---

### sketch_2023_10_13

![sketch_2023_10_13](https://raw.githubusercontent.com/villares/sketch-a-day/main/2023/sketch_2023_10_13/sketch_2023_10_13.png)
Expand Down

0 comments on commit 147eb15

Please sign in to comment.