From e973b88fbdd797f2b33d00105523c59d05fdea6a Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sat, 22 Jul 2017 19:03:36 +0100 Subject: [PATCH] Clarified animation generation code --- 05-display-board/display-board-animation.ipynb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/05-display-board/display-board-animation.ipynb b/05-display-board/display-board-animation.ipynb index b004b96..38a8c52 100644 --- a/05-display-board/display-board-animation.ipynb +++ b/05-display-board/display-board-animation.ipynb @@ -265,12 +265,14 @@ }, "outputs": [], "source": [ - "def draw_frame(grid, command, frame_number):\n", + "def draw_frame(grid, command, frame_number, gif=True):\n", " im = Image.new('RGBA', (WIDTH * 10, HEIGHT * 10 + 21))\n", "\n", " # make a blank image for the text, initialized to transparent text color\n", - " txt = Image.new('RGBA', im.size, (255,255,255,0))\n", - "# txt = Image.new('RGBA', im.size, (0, 0, 0, 0)) # use this line rather than line above for animated png\n", + " if gif:\n", + " txt = Image.new('RGBA', im.size, (255,255,255,0))\n", + " else:\n", + " txt = Image.new('RGBA', im.size, (0, 0, 0, 0)) # use this line rather than line above for animated png\n", "\n", " # get a font\n", " fnt = ImageFont.truetype('Pillow/Tests/fonts/FreeMono.ttf', 18)\n", @@ -278,8 +280,10 @@ " d = ImageDraw.Draw(txt)\n", "\n", " # draw text, full opacity\n", - " d.text((1,1), command, font=fnt, fill='white')\n", - "# d.text((1,1), command, font=fnt, fill='black') # use this line rather than line above for animated png\n", + " if gif:\n", + " d.text((1,1), command, font=fnt, fill='white')\n", + " else:\n", + " d.text((1,1), command, font=fnt, fill='black') # use this line rather than line above for animated png\n", "\n", " draw = ImageDraw.Draw(im)\n", " for (r, row) in enumerate(grid):\n", @@ -296,7 +300,8 @@ " # draw.line((0, im.size[1], im.size[0], 0), fill=128)\n", "\n", " out = Image.alpha_composite(im, txt)\n", - "# out.save('frame{:04}.png'.format(frame_number), 'PNG') # uncomment here to save animated png frames\n", + " if not gif:\n", + " out.save('frame{:04}.png'.format(frame_number), 'PNG') # uncomment here to save animated png frames\n", "\n", " del draw\n", " \n", -- 2.34.1