Now with weather showing capabilities
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
P1
|
||||
# Cloud - non-standard p1!
|
||||
16 8
|
||||
0000000000000000
|
||||
0000001111001000
|
||||
0000001001000000
|
||||
0000010000100000
|
||||
0000010000100000
|
||||
0000001001000000
|
||||
0000001111001000
|
||||
0000000000000000
|
@@ -63,30 +63,25 @@ def date_converter():
|
||||
pixels += lrow
|
||||
return pixels
|
||||
|
||||
|
||||
def weather_converter(name):
|
||||
result = np.zeros((16,16))
|
||||
return result
|
||||
equiv = {
|
||||
"clouds" : "clouds.pbm",
|
||||
"sun" : "sun.pbm",
|
||||
"mix" : "mix.pbm",
|
||||
"rain" : "rain.pbm",
|
||||
"snow" : "snow.pbm",
|
||||
}
|
||||
if name in equiv:
|
||||
fname = equiv[name]
|
||||
else:
|
||||
return np.zeros((8,16))
|
||||
cwd = __file__.replace("\\","/") # for windows
|
||||
cwd = cwd.rsplit("/", 1)[0] # the current working directory (where this file is)
|
||||
if len(cwd) == 0:
|
||||
cwd = "."
|
||||
icon_spritesheet = cwd + "/weather-icons.bmp"
|
||||
|
||||
f = open(fname,"r")
|
||||
f.readline()
|
||||
f.readline()
|
||||
f.readline()
|
||||
icons = Image.open(icon_spritesheet)
|
||||
icons_full = np.array(icons)
|
||||
print(name)
|
||||
icon_loc = ["sun","moon","sun and clouds", "moon and clouds", "cloud","fog and clouds","2 clouds", "3 clouds", "rain and cloud", "rain and clouds", "thunder and cloud", "thunder and cloud and moon", "snow and cloud", "snow and cloud and moon", "fog","fog night"]
|
||||
#ordered 1 2 \n 3 4 \ 5 5 ...
|
||||
try:
|
||||
iy, ix = int(icon_loc.index(name)/2), icon_loc.index(name)%2
|
||||
# x and y coords
|
||||
except:
|
||||
return np.zeros((16,16,3))
|
||||
|
||||
result = np.zeros((16,16))#should be 8x16
|
||||
for i in range(8):
|
||||
l = f.readline()[:-1]
|
||||
for ind,bit in enumerate(l):
|
||||
result[i][ind] = bit
|
||||
|
||||
return result
|
||||
icon_single = icons_full[16*iy:16*(iy + 1),16*ix:16*(ix + 1),...]
|
||||
return icon_single
|
||||
|
@@ -61,6 +61,7 @@ class UnicornHat(object):
|
||||
self.clear()
|
||||
self.draw()
|
||||
pygame.display.flip()
|
||||
pygame.event.pump()
|
||||
#time.sleep(5)
|
||||
|
||||
|
||||
|
@@ -19,11 +19,10 @@ class OutputHandler():
|
||||
self.primary = [230, 230, 230]
|
||||
self.secondary = [10, 200, 10]
|
||||
self.red = [200, 10, 10]
|
||||
self.weather_string = ""
|
||||
self.weather_matrix = []
|
||||
|
||||
|
||||
def set_matrix(self, matrix, quadrant, colors = []):
|
||||
|
||||
def set_matrix(self, matrix, quadrant = 1, colors = []):
|
||||
"""assumes 1 for primary, 2 for secondary color (everything beyond is treated as an error)
|
||||
quadrant: 1,2,3,4 : 4|1
|
||||
___
|
||||
@@ -32,6 +31,15 @@ class OutputHandler():
|
||||
|
||||
# reshape to the main size: (eg 32x16) (always aligns the given matrix on top left.)
|
||||
|
||||
|
||||
# add depth (rgb values)
|
||||
r3 = self.matrix_add_depth(matrix,colors)
|
||||
self.set_matrix_rgb(r3,quadrant)
|
||||
|
||||
|
||||
def matrix_add_depth(self, matrix, colors = []):
|
||||
"""transforms a 2d-array with 0,1,2 to a 3d-array with the rgb values for primary and secondary color"""
|
||||
|
||||
c1 = self.primary
|
||||
c2 = self.secondary
|
||||
c3 = self.red
|
||||
@@ -44,21 +52,11 @@ class OutputHandler():
|
||||
if len(colors) > 3:
|
||||
print("Too many colors")
|
||||
|
||||
result = np.zeros((self.height, self.width))
|
||||
if quadrant == 1:
|
||||
result[:matrix.shape[0], self.width-matrix.shape[1]:] = matrix
|
||||
elif quadrant == 2:
|
||||
result[self.height-matrix.shape[0]:, self.width-matrix.shape[1]:] = matrix
|
||||
elif quadrant == 3:
|
||||
result[self.height-matrix.shape[0]:, :matrix.shape[1]] = matrix
|
||||
else: # 4 or more
|
||||
result[:matrix.shape[0], :matrix.shape[1]] = matrix
|
||||
|
||||
# add depth (rgb values)
|
||||
r3 = np.zeros((self.height,self.width,3),dtype=int)
|
||||
for i in range(self.height):
|
||||
for j in range(self.width):
|
||||
t = int(result[i, j])
|
||||
r3 = np.zeros((matrix.shape[0],matrix.shape[1],3),dtype=int)
|
||||
for i in range(matrix.shape[0]):
|
||||
for j in range(matrix.shape[1]):
|
||||
t = int(matrix[i, j])
|
||||
if t == 0:
|
||||
r3[i, j, :] = [0,0,0]
|
||||
elif t == 1:
|
||||
@@ -67,24 +65,38 @@ class OutputHandler():
|
||||
r3[i, j, :] = c2
|
||||
else:
|
||||
r3[i, j, :] = c3
|
||||
self.output.set_matrix(r3)
|
||||
return r3
|
||||
|
||||
|
||||
|
||||
def set_matrix_rgb(self, matrix, quadrant=1):
|
||||
result = np.zeros((self.height, self.width,3))
|
||||
if quadrant == 1:
|
||||
result[:matrix.shape[0], self.width-matrix.shape[1]:,...] = matrix
|
||||
elif quadrant == 2:
|
||||
result[self.height-matrix.shape[0]:, self.width-matrix.shape[1]:,...] = matrix
|
||||
elif quadrant == 3:
|
||||
result[self.height-matrix.shape[0]:, :matrix.shape[1],...] = matrix
|
||||
else: # 4 or more
|
||||
result[:matrix.shape[0], :matrix.shape[1],...] = matrix
|
||||
|
||||
self.output.set_matrix(result)
|
||||
|
||||
|
||||
def clock_face(self,weather):
|
||||
hour = converter.time_converter()
|
||||
day = converter.date_converter()
|
||||
face1 = hour + day
|
||||
face1_3d = self.matrix_add_depth(face1)
|
||||
|
||||
if self.weather_matrix == [] or weather != self.weather_string:
|
||||
self.weather_matrix = converter.weather_converter("clouds")
|
||||
self.weather_string = weather
|
||||
|
||||
face2 = self.weather_matrix
|
||||
face2_3d = converter.weather_converter(weather)
|
||||
print("WEATHER",face2_3d.shape)
|
||||
face = np.zeros((max(face1_3d.shape[0],face2_3d.shape[0]),face1_3d.shape[1]+face2_3d.shape[1],3))
|
||||
|
||||
face = np.zeros((max(face1.shape[0],face2.shape[0]),face1.shape[1]+face2.shape[1]))
|
||||
face[:face1.shape[0],:face1.shape[1]] = face1
|
||||
face[:face2.shape[0],face1.shape[1]:] = face2
|
||||
self.set_matrix(face, 4)
|
||||
face[:face1_3d.shape[0],:face1_3d.shape[1],...] = face1_3d
|
||||
face[:face2_3d.shape[0],face1_3d.shape[1]:,...] = face2_3d
|
||||
self.set_matrix_rgb(face)
|
||||
|
||||
|
||||
def text_scroll(self, text, speed, color):
|
BIN
clock/api/weather-icons.bmp
Normal file
BIN
clock/api/weather-icons.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.1 KiB |
Reference in New Issue
Block a user