#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
from waveshare_epd import epd2in13b_V3
import time
from PIL import Image,ImageDraw,ImageFont

try:
    epd = epd2in13b_V3.EPD()
    epd.init()
    #epd.Clear()
    time.sleep(1)
    # Drawing on the image
    font20 = ImageFont.truetype('Font.ttc', 20)
    font18 = ImageFont.truetype('Font.ttc', 18)
    # Drawing on the Horizontal image
    HBlackimage = Image.new('1', (epd.height, epd.width), 255)  # 298*126
    HRedimage = Image.new('1', (epd.height, epd.width), 255)  # 298*126  ryimage: red or yellow image  
    drawblack = ImageDraw.Draw(HBlackimage)
    drawred = ImageDraw.Draw(HRedimage)
    drawblack.text((10, 0), 'hello world', font = font20, fill = 0)
    drawred.text((10, 20), '2.13inch e-Paper bc', font = font20, fill = 0)
    drawblack.line((20, 50, 70, 100), fill = 0)
    drawblack.line((70, 50, 20, 100), fill = 0)
    drawblack.rectangle((20, 50, 70, 100), outline = 0)    
    drawred.line((165, 50, 165, 100), fill = 0)
    drawred.line((140, 75, 190, 75), fill = 0)
    drawred.arc((140, 50, 190, 100), 0, 360, fill = 0)
    drawred.rectangle((80, 50, 130, 100), fill = 0)
    drawred.chord((85, 55, 125, 95), 0, 360, fill =1)
    epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage))
    epd.sleep()
        
except IOError as e:
    print(e)
    
except KeyboardInterrupt:    
    epd2in13b_V3.epdconfig.module_exit()
    exit()
