<jupyter_start><jupyter_text>DescriptionThis notebook documents allows the following on a group four LIFX Tilechain with 5 Tileslaid out horizontaly as followingT1 [0]  [1]  [2] [3] [4]T2 [0]  [1]  [2] [3] [4]T3 [0]  [1]  [2] [3] [4]T4 [0]  [1]  [2] [3] [4]Care should be taken to ensure that the LIFX Tiles are all facing up to ensure that the 0,0 position is in the expected place. Program will perform the following- take a jpg or png located in the same folder as the notebook and create a image to display across all 4 tilechains or 20 tiles.  Image will be reduced from original size to a 32x40 matrix so resolution will not be great. You've been warned.<jupyter_code>#Main Program for Convert Single Image to Tiles

# Full running function with all dependencies
#imports RGB to HSBK conversion function from LIFX LAN library
from lifxlan import LifxLAN
from lifxlan.utils import RGBtoHSBK
from pylifxtiles import tiles
from pylifxtiles import actions
from matplotlib import image
from PIL import Image

# modify this variable to the name of the specific LIFX Tilechain as shown in the LIFX app

source_image = './images/babyyoda.jpg'


def main():
    lan = LifxLAN()
    tilechain_lights = lan.get_tilechain_lights()
    print(len(tilechain_lights))
    if len(tilechain_lights) != 0:
        for tile in tilechain_lights:
            if tile.get_label()  ==  'T1':
                print(tile.get_label())
                T1 = tile
            if tile.get_label()  =='T2':
                print(tile.get_label())
                T2 = tile
            if tile.get_label()  == 'T3':
                print(tile.get_label())
                T3 = tile
            if tile.get_label()  == 'T4':
                print(tile.get_label())
                T4 = tile
    tc_list = [T1, T2, T3, T4]
    try:
        display_image(source_image, tc_list)
    except KeyboardInterrupt:
        print("Done.")




#combined function

# resize image and force a new shape and save to disk
def display_image(image_to_display, tilechain_list):
    # load the image
    my_image = Image.open(image_to_display)
    # report the size of the image
    #print(my_image.size)
    # resize image and ignore original aspect ratio
    img_resized = my_image.resize((40,32))
    #changing the file extension from jpg to png changes output brightness. You might need to play with this. 
    img_resized.save('./images/resized_image.jpg')
    data = image.imread('./images/resized_image.jpg')
    target_tcs = []
    for row in data:
        temp_row = []
        for pixel in row:
            temp_row.append(RGBtoHSBK(pixel))
        target_tcs.append(temp_row)
    tcsplit = tiles.split_tilechains(target_tcs)
    tilechain_list[0].set_tilechain_colors(tiles.split_combined_matrix(tcsplit[0]),rapid=True)
    tilechain_list[1].set_tilechain_colors(tiles.split_combined_matrix(tcsplit[1]),rapid=True)
    tilechain_list[2].set_tilechain_colors(tiles.split_combined_matrix(tcsplit[2]),rapid=True)
    tilechain_list[3].set_tilechain_colors(tiles.split_combined_matrix(tcsplit[3]),rapid=True)
        
if __name__ == "__main__":
    main()
#imports RGB to HSBK conversion function from LIFX LAN library
#from lifxlan.utils import RGBtoHSBK
#from pylifxtiles import tiles
#from PIL import Image

#import LIFxLAN object and get all LIFX lights and assign to lifx object
#from lifxlan import LifxLAN
lifx = LifxLAN(30)

tilechain_lights = lifx.get_tilechain_lights()
print (len(tilechain_lights))
len(tilechain_lights)
#Print out the list of LIFX Tile lights to find the one we're looking for
#TODO Should write a helper function that finds the right light and automatically assigns it to a variable
canvas = ['T1', 'T2', 'T3', 'T4']
for tile in tilechain_lights:
    if tile.get_label()  ==  'T1':
    #if tile.get_label() == 'TEST':
        T1 = tile
    if tile.get_label()  =='T2':
    #if tile.get_label() == 'TEST':
        T2 = tile
    if tile.get_label()  == 'T3':
    #if tile.get_label() == 'TEST':
        T3 = tile
    if tile.get_label()  == 'T4':
    #if tile.get_label() == 'TEST':
        T4 = tile
    if tile.get_label()  == 'LR1':
    #if tile.get_label() == 'TEST':
        LR = tile
baby_yoda = './images/babyyoda.jpg'
monkeylizard = './images/monkeylizard.jpg'
jeff = './images/jeff_icon.jpg'
avatar = './images/avatarstate.jpg'
avatar2 = './images/avatarstate2.jpg'
avatar3 = './images/avatarstate3.jpg'
hkgpng = './images/HKG_icon_red.png'
hkgjpg = './images/HKG_icon_red_logo.jpg'

image_to_display =avatar3
# load and display an image with Matplotlib
from matplotlib import image
from matplotlib import pyplot
# load image as pixel array
data = image.imread(image_to_display)
# summarize shape of the pixel array
print(data.dtype)
print(data.shape)
# display the array of pixels as an image
pyplot.imshow(data)
pyplot.show()
# resize image and force a new shape and save to disk
from PIL import Image
# load the image
my_image = Image.open(image_to_display)
# report the size of the image
print(my_image.size)
# resize image and ignore original aspect ratio
img_resized = my_image.resize((40,32))
img_resized.save('./images/resized_image.png')
# report the size of the thumbnail
print(img_resized.size)
img_resized.show()
## load and display target image with Matplotlib
data = image.imread('./images/resized_image.png')
# summarize shape of the pixel array
print(data.dtype)
print(data.shape)
# display the array of pixels as an image
pyplot.imshow(data)
pyplot.show()
#convert all values in the matplotlib data object from RGB to HSBK and create new tcs.
target_tcs = []
for row in data:
    temp_row = []
    for pixel in row:
        temp_row.append(RGBtoHSBK(pixel))
    target_tcs.append(temp_row)
        
#split 2D target_tcs into a list of 4 x 2D (8x40) Tilechains
tcsplit = tiles.split_tilechains(target_tcs)
T1.set_tilechain_colors(tiles.split_combined_matrix(tcsplit[0]))
T2.set_tilechain_colors(tiles.split_combined_matrix(tcsplit[1]))
T3.set_tilechain_colors(tiles.split_combined_matrix(tcsplit[2]))
T4.set_tilechain_colors(tiles.split_combined_matrix(tcsplit[3]))
#combined function

# resize image and force a new shape and save to disk
def display_image(image_to_display):
    # load the image
    my_image = Image.open(image_to_display)
    # report the size of the image
    #print(my_image.size)
    # resize image and ignore original aspect ratio
    img_resized = my_image.resize((40,32))
    img_resized.save('./images/resized_image.png')
    data = image.imread('./images/resized_image.png')
    target_tcs = []
    for row in data:
        temp_row = []
        for pixel in row:
            temp_row.append(RGBtoHSBK(pixel))
        target_tcs.append(temp_row)
    tcsplit = tiles.split_tilechains(target_tcs)
    T1.set_tilechain_colors(tiles.split_combined_matrix(tcsplit[0]),rapid=True)
    T2.set_tilechain_colors(tiles.split_combined_matrix(tcsplit[1]),rapid=True)
    T3.set_tilechain_colors(tiles.split_combined_matrix(tcsplit[2]),rapid=True)
    T4.set_tilechain_colors(tiles.split_combined_matrix(tcsplit[3]),rapid=True)
display_image(monkeylizard)
display_image('./images/NeedMoreTiles.png')

os.listdir('./images/walkingman/')
my_images = os.listdir('./images/walkingman/')
my_images.sort()
for walk in range(4):
    for i in my_images:
        display_image(('./images/walkingman/'+i))
my_images = os.listdir('./images/bashful//')
my_images.sort()
for walk in range(1):
    for i in my_images:
        display_image(('./images/bashful/'+i))
my_images = os.listdir('./images/blackhole/')
my_images.sort()
for walk in range(1):
    for i in my_images:
        display_image(('./images/blackhole/'+i))
my_images = os.listdir('./images/supernova/')
my_images.sort()
for walk in range(1):
    for i in my_images:
        display_image(('./images/supernova/'+i))
display_image('./images/applerainbow.png')
display_image('./images/imore-logo.png')
display_image('./images/imore-logo-mona_330x300.png')
display_image('./images/imore-logo-white.png')
display_image('./images/mona_lisa_face.jpg')

my_images = os.listdir('./images/bashful/')
my_images = os.listdir('./images/AYL/')
my_images.sort()
for walk in range(1):
    for i in my_images:
        display_image(('./images/AYL/'+i))
        time.sleep(10)
import time
message = 'automate your life'
m1= message[:5]
m2= message[6:11]
m3= message[11:16]
m4 = message[16:]
len(m3)

from pylifxtiles.actions import write_word, blank_tile, reset_tiles
from pylifxtiles.colors import *
from pylifxtiles.alphanum import *
original_colors = reset_tiles(T1)
write_word(m1, orange, T1)
write_word(m2,orange, T2)
write_word(m3,orange, T3)
def write_word(word, color, tilechain):
    """
    Function to automatically
    :param word:
    :param tilechain:
    :return:
    """
    for letter in word.lower():
        for led in alpha[letter]:
            original_colors[0][led] = (dblue, 65535, twenty, 4900)
    tilechain.set_tilechain_colors(original_colors, )
help(write_word)
my_word = m4
target_tile = T4
original_colors = actions.reset_tiles(target_tile)
target_color_map = original_colors
tile = 0
for letter in my_word.lower():
                #blank_tile= actions.blank_tile()
                #print (len(blank_tile))
                if letter == ' ':
                    tile += 1
                    continue
                else:
                    for led in alpha[letter]:
                        target_color_map[tile][led] = (dblue, 65535, fourty, 4900)
                    target_tile.set_tile_colors(tile, target_color_map[tile], rapid=True)
                tile += 1
from pylifxtiles.colors import *
original_colors = actions.reset_tiles(T2)
original_colors[0][0]
my_word = m4
target_tile = T4
original_colors = actions.reset_tiles(target_tile)
target_color_map = original_colors
tile = 0
message = 'automate your life'
for i in message:
    my_message = message[0:5]
    message = my_message[1:]
    for letter in my_message.lower():
                #blank_tile= actions.blank_tile()
                #print (len(blank_tile))
                if letter == ' ':
                    tile += 1
                    continue
                else:
                    for led in alpha[letter]:
                        target_color_map[tile][led] = (dblue, 65535, fourty, 4900)
                    target_tile.set_tile_colors(tile, target_color_map[tile], rapid=True)
                tile += 1
                print(letter)
                time.sleep(2)
my_message = message[0:5]

import time
my_list =[1,2,3,4,5]
for y in my_list:
    if y == 2:
        continue
    else:
        print(y)<jupyter_output>1
3
4
5
{'fraction_non_alphanumeric': 0.10907718437441026, 'fraction_numerical': 0.01896584261181355, 'mean_word_length': 3.333197056418643, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '303945', 'license': 'Apache-2.0', 'n_tokens_mistral': 3677, 'n_tokens_neox': 3531, 'n_words': 919, 'path': '.ipynb_checkpoints/Convert Image to Four Tileschains-checkpoint.ipynb', 'repo_name': 'netmanchris/pylifxtiles', 'size': '10598'}