Advertisement
tckoppang

e-paper image display

Nov 22nd, 2020
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding:utf-8 -*-
  3.  
  4. import epd2in13
  5. from PIL import Image,ImageDraw,ImageFont
  6. import traceback
  7. import random
  8. import os
  9.  
  10. try:
  11.     epd = epd2in13.EPD()
  12.     epd.init(epd.FULL_UPDATE)
  13.     epd.Clear(0xFF)
  14.    
  15.     # Assign image
  16.     image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255)  # 255: clear the frame
  17.    
  18.     pics = ['donald.bmp','finn.bmp','spirited.bmp','homer.bmp','link.bmp','justice.bmp','carter.bmp','miles.bmp','mario.bmp','major.bmp']
  19.     choice = random.randint(0,len(pics)-1)
  20.     choiceMaking = 0
  21.  
  22.     save_state = open("pic_choices.tmp", "a+")
  23.     lines = save_state.readlines()
  24.     lines = [int(i) for i in lines]
  25.    
  26.     if len(lines) == len(pics):
  27.         print("full")
  28.         save_state.close()
  29.         os.remove("pic_choices.tmp")
  30.         save_state = open("pic_choices.tmp", "a+")
  31.         save_state.write(str(choice) + "/n")
  32.         choiceMaking = 1
  33.         lines = save_state.readlines()
  34.     elif len(lines) == 0:
  35.         save_state.write(str(choice) + "/n")
  36.         choiceMaking = 1
  37.         lines = save_state.readlines()
  38.        
  39.     while choiceMaking == 0:
  40.         if choice in lines:
  41.             print("duplicate found; choosing another...")
  42.             choice = random.randint(0,len(pics)-1)
  43.         else:
  44.             choiceMaking = 1                
  45.    
  46.     save_state.write(str(choice) + "\n")
  47.    
  48.     save_state.close()
  49.    
  50.     image = Image.open(pics[choice])
  51.     epd.display(epd.getbuffer(image))
  52.  
  53. except:
  54.     print('traceback.format_exc():\n%s',traceback.format_exc())
  55.     exit()
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement