36
36
# create the array of colors
37
37
COLORS = [(int (c .red * 255 ), int (c .green * 255 ), int (c .blue * 255 )) for c in COLORS ]
38
38
CONSOLE_COLORS = [
39
- 17 , 18 , 19 , 20 , 21 , 57 , 93 , 129 , 165 , 201 , 200 ,
40
- 199 , 198 , 197 , 196 , 202 , 208 , 214 , 220 ]
39
+ 17 ,
40
+ 18 ,
41
+ 19 ,
42
+ 20 ,
43
+ 21 ,
44
+ 57 ,
45
+ 93 ,
46
+ 129 ,
47
+ 165 ,
48
+ 201 ,
49
+ 200 ,
50
+ 199 ,
51
+ 198 ,
52
+ 197 ,
53
+ 196 ,
54
+ 202 ,
55
+ 208 ,
56
+ 214 ,
57
+ 220 ,
58
+ ]
59
+
41
60
42
61
def map_value (x_value , in_min , in_max , out_min , out_max ):
43
62
"""Maps value of the temperature to color"""
44
63
return (x_value - in_min ) * (out_max - out_min ) / (in_max - in_min ) + out_min
45
64
65
+
46
66
def print_there (console_x , console_y , text , color ):
47
67
""" Outputs a colored text to console at coordinates """
48
68
sys .stdout .write ("\x1b 7\x1b [48;5;%dm" % (color ))
49
69
sys .stdout .write ("\x1b 7\x1b [%d;%df%s\x1b 8" % (console_x , console_y , text ))
50
70
71
+
51
72
# let the sensor initialize
52
73
time .sleep (0.1 )
53
74
@@ -73,12 +94,12 @@ def print_there(console_x, console_y, text, color):
73
94
for jx , pixel in enumerate (row ):
74
95
color_index = 0
75
96
if COLOR_RANGE != 0 :
76
- color_index = int (round ((pixel - MINPIXEL )/ COLOR_RANGE ))
97
+ color_index = int (round ((pixel - MINPIXEL ) / COLOR_RANGE ))
77
98
if color_index < 0 :
78
99
color_index = 0
79
- if color_index > len (CONSOLE_COLORS )- 1 :
80
- color_index = len (CONSOLE_COLORS )- 1
81
- print_there (x_console , Y_CONSOLE * 2 - 2 , ' ' , CONSOLE_COLORS [color_index ])
100
+ if color_index > len (CONSOLE_COLORS ) - 1 :
101
+ color_index = len (CONSOLE_COLORS ) - 1
102
+ print_there (x_console , Y_CONSOLE * 2 - 2 , " " , CONSOLE_COLORS [color_index ])
82
103
if pixel > MAXPIXEL :
83
104
MAXPIXEL = pixel
84
105
if pixel < MINPIXEL :
0 commit comments