},
"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",
" 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",
" # 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",