-
Notifications
You must be signed in to change notification settings - Fork 43
/
tools.py
42 lines (30 loc) · 1.06 KB
/
tools.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
import os
from time import time, sleep
from more_itertools import unique_everseen
from PIL import Image
from random import randint
from threading import Timer
from time import gmtime, strftime
#WORKING DIRECTORY
CWD = os.path.dirname(os.path.realpath(__file__))
def remove_dups(seq):
return list(unique_everseen(seq))
def draw_points(points, width = 2000, height = 2000):
'''
Draws yellow crosses to a (default 2000x2000px) image for all coordinates in
"points" argument
saves to CWD as out-0000.png
'''
img = Image.new("RGB", (width, height))
pix = img.load()
try:
for coords in points:
pix[coords[0], coords[1]] = (255, 255, 0)
pix[coords[0] + 1, coords[1] + 1] = (255, 255, 0)
pix[coords[0] + 1, coords[1] - 1] = (255, 255, 0)
pix[coords[0] - 1, coords[1] + 1] = (255, 255, 0)
pix[coords[0] - 1, coords[1] - 1] = (255, 255, 0)
img.save(CWD + '/tmp/out-' + strftime("%Y-%m-%d %H:%M:%S", gmtime())
+ '.png')
except:
pass