From 9251fcb222b674d0e96e5c73663350909079efcf Mon Sep 17 00:00:00 2001 From: Ehsan Kia Date: Sun, 27 Dec 2020 15:56:18 -0500 Subject: [PATCH] Simplify coordinate loading We can rely on JSON to load each coordinate line, since an array of ints is a valid JSON format. --- xmaslights-spin.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/xmaslights-spin.py b/xmaslights-spin.py index 3b77d79..27c5fca 100644 --- a/xmaslights-spin.py +++ b/xmaslights-spin.py @@ -9,6 +9,7 @@ def xmaslight(): import neopixel import re import math + import json # You are welcome to add any of these: # import random @@ -24,18 +25,8 @@ def xmaslight(): coordfilename = "Python/coords.txt" - fin = open(coordfilename,'r') - coords_raw = fin.readlines() - - coords_bits = [i.split(",") for i in coords_raw] - - coords = [] - - for slab in coords_bits: - new_coord = [] - for i in slab: - new_coord.append(int(re.sub(r'[^-\d]','', i))) - coords.append(new_coord) + with open(coordfilename,'r') as fin: + coords = list(map(json.loads, fin.readlines())) #set up the pixels (AKA 'LEDs') PIXEL_COUNT = len(coords) # this should be 500