-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalibrate.py
executable file
·57 lines (44 loc) · 1.37 KB
/
calibrate.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
48
49
50
51
52
53
54
55
56
57
import sys, pygame, math
pygame.init()
# print pygame.KMOD_NONE
# mods = pygame.key.get_mods()
# print bin(mods)
# sys.exit()
# if mods & pygame.KMOD_NUM:
# sys.exit('Please turn off the NUM LOCK and try again.')
# if mods & pygame.KMOD_CAPS:
# sys.exit('Please turn off the CAPS LOCK and try again.')
size = width, height = pygame.display.list_modes()[0]
black = 0, 0, 0
screen = pygame.display.set_mode(size)
myfont = pygame.font.SysFont('Times New Roman', 30)
points = []
running = True
while running:
#clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
elif event.type == pygame.MOUSEBUTTONUP:
mousex,mousey = event.pos
points.append((mousex,mousey))
if len(points)==2:
running = False
screen.fill(black)
# draw here
msg_list = ['Please click two points separated by 3 inches,',
'the width of a standard post-it note.']
for idx,msg in enumerate(msg_list):
textsurface = myfont.render(msg, False, (255, 255, 255))
screen.blit(textsurface,(0,0+idx*30))
pygame.display.flip()
x1,y1 = points[0]
x2,y2 = points[1]
x1 = float(x1)
y1 = float(y1)
x2 = float(x2)
y2 = float(y2)
d = math.sqrt((y1-y2)**2+(x1-x2)**2)
dpi = d/3.0
f = open('./dpi.txt','wb')
f.write('%0.1f'%dpi)
f.close()