forked from tink3rtanner/opc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvasTest.py
48 lines (39 loc) · 1.16 KB
/
canvasTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from luma.core.interface.serial import spi
from luma.core.render import canvas
from luma.oled.device import sh1106
import time,os,datetime
from subprocess import *
import RPi.GPIO as GPIO
from time import sleep
from PIL import Image, ImageDraw
from random import randint, random
serial = spi(device=0, port=0)
device = sh1106(serial,rotate=2)
def clip(n, minn, maxn):
return n
return max(min(maxn, n), minn)
def randCoords(xy, spread):
x = xy[0]
y = xy[1]
xlower = clip(x-spread, 0, 127)
xupper = clip(x+spread, 0, 127)
ylower = clip(y-spread, 0, 63)
yupper = clip(y+spread, 0, 63)
x = randint(xlower, xupper)
y = randint(ylower, yupper)
return (x, y)
def randomizeCoordList(coords):
coords = [randCoords(xy, 3) for xy in coords]
# coords = [(63,31)] * 20
# while True:
# with canvas(device) as draw:
# draw.polygon(coords, outline="white")
# coords = [randCoords(xy, 5) for xy in coords]
# sleep(0.01)
im = Image.new("RGBA", (128,64))
i = ImageDraw.Draw(im)
i.polygon([(1,1), (30,50), (125,63)], outline="white")
with canvas(device) as draw:
draw.bitmap((0,0), im, fill="white")
print("ayyy")
sleep(10)