Skip to content

Instantly share code, notes, and snippets.

@grischard
Last active April 9, 2023 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grischard/c293632b1a6dd264dc30aefdaf63eefb to your computer and use it in GitHub Desktop.
Save grischard/c293632b1a6dd264dc30aefdaf63eefb to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# This script generates a wled mapping for the Hackbow LED sculpture at NYC Resistor.
import json
import pandas as pd
number_bars = 18
number_leds = 60
height = 100
# Relative offsets from left to right, in centimeters. 0.0 is highest.
# Max is 32.9, min is 9.1, diff is 23.8 = 39.6666 LEDs.
offsets = [
21.2, 13.8, 12.2, 9.1, 11.3, 19.7, 22.8, 29.8, 32.9, 28.1,
25.2, 22.2, 16.2, 14.3, 18, 21.7, 24.5, 25.8,
]
max_virtual_leds = int(max(offsets) / (height / number_leds))
# Create an empty DataFrame
led_df = pd.DataFrame()
for bar in range(0, number_bars):
distance_above_bottom = max(offsets) - offsets[bar]
bottom_virtual_leds = round(distance_above_bottom / (height / number_leds))
distance_below_top = offsets[bar] - min(offsets)
top_virtual_leds = round(distance_below_top / (height / number_leds))
led_column = []
for bottom_virtual_led in range(0, bottom_virtual_leds):
led_column.append(-1)
if bar % 2 == 1:
for led in range(bar * number_leds, (bar + 1) * number_leds):
led_column.append(led)
else:
for led in range((bar + 1) * number_leds - 1, bar * number_leds - 1, -1):
led_column.append(led)
for top_virtual_led in range(0, top_virtual_leds):
led_column.append(-1)
# Add the column to the DataFrame, reversed
led_df[f'Bar_{bar}'] = pd.Series(led_column[::-1])
# Get the height and width of the DataFrame
df_height, df_width = led_df.shape
# Flatten the DataFrame values into a 1D list
flat_list = led_df.values.flatten().tolist()
# Define a variable for the n parameter
n = "Hackbow with virtual LEDs"
# Create a JSON object with the required format
output_json = {
"n": n,
"width": df_width,
"height": df_height,
"map": flat_list
}
# Print the JSON object
print(json.dumps(output_json))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment