X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=05-display-board%2Fdisplay-board-animation.ipynb;h=38a8c523657a03a158956f629a82f1cafe7b9b64;hb=0d5419df577af1f1f0bdfdaae5974a62c3c453b0;hp=b004b96a096e6dd9f9de815f1d3c00b38a2bda8f;hpb=0d872921c8bfd3f68dbce5eeda4a4548814151ab;p=ou-summer-of-code-2017.git 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",