-
Notifications
You must be signed in to change notification settings - Fork 10
/
drawing.py
99 lines (70 loc) · 1.96 KB
/
drawing.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# -*- coding: utf-8 -*-
import os
from PIL import Image, ImageDraw, ImageFont
import icons
def draw_temp( center_x, y, temp, temp_size, deg_size, deg_offset, draw ):
font = ImageFont.truetype('./font/AkzidenzGrotesk-Cond.otf', temp_size)
sz = font.getsize( temp )
draw.text(
(center_x-(sz[0]/2), y),
temp,
font=font,
fill=255
)
font = ImageFont.truetype('./font/AkzidenzGrotesk-Cond.otf', deg_size)
draw.text(
(center_x+(sz[0]/2), y+deg_offset),
u'°',
font=font,
fill=255
)
def draw_small_temp( center_x, y, caption, draw ):
draw_temp(
center_x,
y,
caption,
80,
40,
10,
draw
)
def draw_weather_icon( buf, fn_icon, pos ):
fn_icon = os.path.join(
"./icons",
fn_icon
)
img_icon = Image.open( fn_icon )
buf.paste( img_icon, pos )
def draw_weather( buf, weather ):
icon = icons.darksky[ weather.icon ]
draw_weather_icon(
buf,
icon,
[15,215]
)
draw = ImageDraw.Draw( buf )
caption = "%0.0f" % weather.temp
top_y = 194
draw_temp( 150, top_y, caption, 100, 60, 9, draw )
mid_y = top_y + 17
caption = "%0.0f" % weather.temp_min
draw_small_temp( 250, mid_y, caption, draw )
caption = "%0.0f" % weather.temp_max
draw_small_temp( 350, mid_y, caption, draw )
def draw_frame( width, height, formatted_time, weather ):
img_buf = Image.new('1', (width, height), 1) # 1: clear the frame
# constant shapes burnt into back.bmp
back = Image.open( 'images/back.bmp' )
img_buf.paste( back )
# draw weather into buffer
draw_weather( img_buf, weather )
im_width = 100
offs = 0
for n in formatted_time:
if n == " ":
n = "_SPACE"
fn = 'images/%s.bmp' % n
img_num = Image.open(fn)
img_buf.paste( img_num, (offs,0) )
offs += im_width
return img_buf