Skip to content
Snippets Groups Projects
Commit 8ee0b002 authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Move software sim stuff over to looper repo

parent 73744d33
Branches
Tags
No related merge requests found
%% Cell type:code id:6ad68c73-abea-4199-a610-f9c06edd405b tags:
``` python
from matplotlib import pyplot as plt
%matplotlib inline
import math
def draw(r, data):
l = len(r)
x = [x for x in range(l)]
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([0, 0, 1, 1])
ax.axhline(y=0.5, color='black', linestyle='--')
ax.set_xticks(range(0, l, 64))
ax.set_yticks(range(-l*2, l*2+1, 128))
ax.grid()
ax.plot(x, r)
ax.plot(x, data)
pulse_delay = 100
pulse_duration = 100
total_duration = 2000
data = [0.0]*pulse_delay
data += [-1.0]*pulse_duration
data += [0.0]*pulse_delay
data += [1.0]*pulse_duration
data += [0.0]*(total_duration-pulse_delay-pulse_duration)
def process(data):
attack = pow(0.01, 1.0 / (20.1 * 48000 * 0.001))
decay = pow(0.01, 1.0 / (100.0 * 48000 * 0.001))
value = 0.0
output = []
for in_ in data:
abs_value = abs(in_)
if abs_value > value:
value = attack * (value - abs_value) + abs_value
else:
value = decay * (value - abs_value) + abs_value
output.append(value)
return output
env = process(data)
draw(env, data)
```
%% Output
%% Cell type:code id:50316437-021e-49b4-bda9-7663854444da tags:
``` python
from matplotlib import pyplot as plt
%matplotlib inline
import math
def draw(r):
l = len(r)
x = [x for x in range(l)]
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([0, 0, 1, 1])
ax.axhline(y=0.5, color='black', linestyle='--')
ax.set_xticks(range(0, l, 64))
ax.set_yticks(range(-l*2, l*2+1, 128))
ax.grid()
ax.plot(x, r)
data = [(3.0 + math.log10(x/1000))/3.0 for x in range(1,1001)]
draw(data)
print(f'Min: {min(data)}')
print(f'Max: {max(data)}')
```
%% Output
Min: 0.0
Max: 1.0
%% Cell type:code id:d3bbb0dd-b8c3-4563-aec0-f39f1d0766b1 tags:
``` python
import math
import numpy as np
table = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
def lerp(a, b, f=0.5) -> float:
f = min(1.0, max(0.0, f))
if f == 0.0:
return a
elif f == 1.0:
return b
else:
return a * (1.0-f) + b * f
def get(table, f):
f = min(1.0, max(0.0, f))
pos = (len(table)-1) * f
pos_frac = pos%1.0
if pos_frac == 0.0:
val = table[int(round(pos))]
print(f"{f} direct access {int(pos)}: {val}")
return val
a = table[int(math.floor(pos))]
b = table[int(math.ceil(pos))]
val = lerp(a, b, pos_frac)
print(f"{f} interpolating [{a}] -> [{b}] with f {pos_frac}: {val}")
return val
for i in range(0, 33):
get(table, i/32.0)
```
%% Output
0.0 direct access 0: 0.0
0.03125 interpolating [0.0] -> [1.0] with f 0.125: 0.125
0.0625 interpolating [0.0] -> [1.0] with f 0.25: 0.25
0.09375 interpolating [0.0] -> [1.0] with f 0.375: 0.375
0.125 interpolating [0.0] -> [1.0] with f 0.5: 0.5
0.15625 interpolating [0.0] -> [1.0] with f 0.625: 0.625
0.1875 interpolating [0.0] -> [1.0] with f 0.75: 0.75
0.21875 interpolating [0.0] -> [1.0] with f 0.875: 0.875
0.25 direct access 1: 1.0
0.28125 interpolating [1.0] -> [2.0] with f 0.125: 1.125
0.3125 interpolating [1.0] -> [2.0] with f 0.25: 1.25
0.34375 interpolating [1.0] -> [2.0] with f 0.375: 1.375
0.375 interpolating [1.0] -> [2.0] with f 0.5: 1.5
0.40625 interpolating [1.0] -> [2.0] with f 0.625: 1.625
0.4375 interpolating [1.0] -> [2.0] with f 0.75: 1.75
0.46875 interpolating [1.0] -> [2.0] with f 0.875: 1.875
0.5 direct access 2: 2.0
0.53125 interpolating [2.0] -> [3.0] with f 0.125: 2.125
0.5625 interpolating [2.0] -> [3.0] with f 0.25: 2.25
0.59375 interpolating [2.0] -> [3.0] with f 0.375: 2.375
0.625 interpolating [2.0] -> [3.0] with f 0.5: 2.5
0.65625 interpolating [2.0] -> [3.0] with f 0.625: 2.625
0.6875 interpolating [2.0] -> [3.0] with f 0.75: 2.75
0.71875 interpolating [2.0] -> [3.0] with f 0.875: 2.875
0.75 direct access 3: 3.0
0.78125 interpolating [3.0] -> [4.0] with f 0.125: 3.125
0.8125 interpolating [3.0] -> [4.0] with f 0.25: 3.25
0.84375 interpolating [3.0] -> [4.0] with f 0.375: 3.375
0.875 interpolating [3.0] -> [4.0] with f 0.5: 3.5
0.90625 interpolating [3.0] -> [4.0] with f 0.625: 3.625
0.9375 interpolating [3.0] -> [4.0] with f 0.75: 3.75
0.96875 interpolating [3.0] -> [4.0] with f 0.875: 3.875
1.0 direct access 4: 4.0
%% Cell type:code id:cc0b4852-eccb-4bae-859a-bbbf92458ab2 tags:
``` python
from matplotlib import pyplot as plt
%matplotlib inline
import math
def draw(r):
l = len(r)
x = [x for x in range(l)]
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([0, 0, 1, 1])
ax.axhline(y=0.5, color='black', linestyle='--')
ax.set_xticks(range(0, l, 64))
ax.set_yticks(range(-l*2, l*2+1, 128))
ax.grid()
ax.plot(x, r)
def deadband(x, deadband = 200):
span = 4096
half = span/2
half_span = half-deadband
scaler = half/half_span
if x < half:
x += deadband
x = (min(half, x)-half) * -scaler
x = int(x * -1) + half
else:
x -= deadband
x = (max(half, x)-half)*scaler
x = int(x)+half
return x
data = [deadband(x) for x in range(0,4096)]
draw(data)
print(f'Min: {min(data)}')
print(f'Max: {max(data)}')
```
%% Output
Min: 0.0
Max: 4094.0
%% Cell type:code id:2e2c2c7f-4bc6-4a1f-b6bd-bf5558b8f03f tags:
``` python
```
%% Output
<function __main__.draw(f)>
%% Cell type:code id:6112aebb-dc20-45e3-9ca6-280c76523469 tags:
``` python
```
%% Cell type:code id:52c8bec3-db2d-4522-b692-b035a71410de tags:
``` python
from matplotlib import pyplot as plt
%matplotlib inline
import math
!{sys.executable} -m pip install clipboard
%matplotlib inline
import clipboard
def draw(r, g, b):
x = [x for x in range(256)]
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([0, 0, 1, 1])
ax.axhline(y=0.5, color='black', linestyle='--')
ax.set_xticks(range(0, 256, 64))
ax.set_yticks(range(-256*2, 256*2+1, 128))
ax.grid()
ax.plot(x, r, 'r')
ax.plot(x, g, 'g')
ax.plot(x, b, 'b')
def r():
start = 100
start2 = 220
last_a = 0
for i in range(256):
if i < start:
yield 0
elif i < start2:
span = 255-start
d = (i-start)/span
last_a = int(d*30.0)
yield min(255, last_a)
else:
span = 255-start2
d = (i-start2)/span
d = d*d*d
yield min(255, last_a + int(d*350.0))
def g():
start = 0
end = 180-80
scale = 0.25
for i in range(256):
if i < start:
yield 0
elif i > end:
d = 1.0 - ((i-end)/(295-end))
# d = (d*d)/4 + d/2
yield max(0, min(255, int(d*175*scale)))
else:
d = ((i-start)/(255-start))
d = (d*d*d)
yield min(255, int(d*2800*scale))
def b():
start = 4
end = 40
scale = 0.2
for i in range(256):
if i < start:
yield 0
elif i > end:
d = (i-end)/(60)
d = d*d
d = 1.0 - d
# d = math.sqrt(d)
yield max(0, min(255, int(d*32*scale)))
else:
d = (i-start)/(255-start)
d = math.sqrt(d)/2 + d/2
yield max(0, min(255, int(d*107*scale)))
r, g, b = list(r()), list(g()), list(b())
draw(r, g, b)
text = ""
text += "// Lookup Table for Red LED Channel\n"
text += f"int red_lookup[] = {{{', '.join(str(v) for v in r)}}};\n\n"
text += "// Lookup Table for Green LED Channel\n"
text += f"int green_lookup[] = {{{', '.join(str(v) for v in g)}}};\n\n"
text += "// Lookup Table for Blue LED Channel\n"
text += f"int blue_lookup[] = {{{', '.join(str(v) for v in b)}}};\n\n"
import ipywidgets as widgets
from IPython.display import display, HTML, Javascript
mybtn = widgets.Button(description='copy C++ to clipboard', button_style='success')
def mybtn_event_handler(b):
print("copied")
clipboard.copy(text)
mybtn.on_click(mybtn_event_handler)
display(mybtn)
```
%% Output
zsh:1: parse error near `-m'
%% Cell type:code id:41562cc6-9911-4fb1-87ec-f2b3c8bfb3c2 tags:
``` python
from matplotlib import pyplot as plt
%matplotlib inline
import math
def draw(r):
l = len(r)
x = [x for x in range(l)]
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([0, 0, 1, 1])
ax.axhline(y=0.5, color='black', linestyle='--')
ax.axvline(x=l/2, color='black', linestyle='--')
ax.set_xticks(range(0, l, 64))
ax.set_yticks(range(-l*2, l*2+1, 128))
ax.grid()
ax.plot(x, r)
def deadband(length, deadband=0.04):
readings = []
for i in range(length):
current_reading = i/(length-1)
scaler = (1.0) / (1.0 - deadband)
scaler += 0.1
if current_reading < 0.5:
current_reading += deadband
current_reading = min(0.5, current_reading)
current_reading = 0.5 - current_reading
current_reading *= scaler
current_reading = 0.5 - current_reading
# current_reading =
else:
current_reading -= deadband
current_reading = max(0.5, current_reading)
current_reading = 0.5 - current_reading
current_reading *= scaler
current_reading = 0.5 - current_reading
val = min(length, max(0, current_reading))
readings.append(val)
return readings
bip = deadband(16, deadband = 0.08)
draw(bip)
text = ""
text += "// Lookup Table for Bipolar Curve with deadband\n"
text += f"float bip_lookup[] = {{{', '.join(str(v) for v in bip)}}};\n\n"
import ipywidgets as widgets
from IPython.display import display, HTML, Javascript
mybtn = widgets.Button(description='copy C++ to clipboard', button_style='success')
def mybtn_event_handler(b):
print("copied")
clipboard.copy(text)
mybtn.on_click(mybtn_event_handler)
display(mybtn)
len(bip)
```
%% Output
16
%% Cell type:code id:ecc666b0-8195-4276-a576-39d41753b540 tags:
``` python
from matplotlib import pyplot as plt
%matplotlib inline
import math
import sys
def draw(r):
l = len(r)
x = [x for x in range(l)]
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([0, 0, 1, 1])
ax.axhline(y=0.5, color='black', linestyle='--')
ax.set_xticks(range(0, l, 64))
ax.set_yticks(range(-l*2, l*2+1, 128))
ax.grid()
ax.plot(x, r)
def lin_to_log(length, strength=1.0):
# Limit to range 0.0 and 1.0
strength = min(1.0, max(0.0, strength))
readings = []
linear_readings = []
for i in range(length):
current_reading = i/length
linear_readings.append(current_reading)
# Log of 0 is error, so handle it explicitly
if i == 0:
current_reading = 0.0
else:
current_reading = math.log10(i)
readings.append(current_reading)
# Normalize to scale 0.1 to one
maxima = max(readings)
scaler = 1.0 / maxima
readings = [r*scaler for r in readings]
output = []
for i, r in enumerate(readings):
val = r*strength + linear_readings[i] * (1.0 - strength)
output.append(val)
# Convert to integer value range
output = [o for o in output]
return output
# lilo = lin_to_log(4096, strength=1.0)
lilo = lin_to_log(32, strength=1.0)
# lilo = [l/256.0 for l in lilo]
draw(lilo)
text = ""
text += "// Lookup Table for Logarithmic Curve\n"
text += f"float log_lookup[] = {{{', '.join(str(v) for v in lilo)}}};\n\n"
# print(text)
import ipywidgets as widgets
from IPython.display import display, HTML, Javascript
mybtn = widgets.Button(description='copy C++ to clipboard', button_style='success')
def mybtn_event_handler(b):
print("copied")
clipboard.copy(text)
mybtn.on_click(mybtn_event_handler)
display(mybtn)
min(lilo)
```
%% Output
0.0
%% Cell type:code id:2ecfda42-4a3c-489a-bc90-8576648c339c tags:
``` python
from matplotlib import pyplot as plt
%matplotlib inline
import math
import sys
def draw(r):
l = len(r)
x = [x for x in range(l)]
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([0, 0, 1, 1])
ax.axhline(y=0.5, color='black', linestyle='--')
ax.set_xticks(range(0, l, 64))
ax.set_yticks(range(-l*2, l*2+1, 128))
ax.grid()
ax.plot(x, r)
def exp_lookup(length, strength=1.0):
# Limit to range 0.0 and 1.0
strength = min(1.0, max(0.0, strength))
readings = []
linear_readings = []
for i in range(length):
current_reading = i/length
linear_readings.append(current_reading)
# Log of 0 is error, so handle it explicitly
if i == 0:
current_reading = 0.0
else:
current_reading = i*i
readings.append(current_reading)
# Normalize to scale 0.1 to one
maxima = max(readings)
scaler = 1.0 / maxima
readings = [r*scaler for r in readings]
output = []
for i, r in enumerate(readings):
val = r*strength + linear_readings[i] * (1.0 - strength)
output.append(val)
# Convert to integer value range
output = [o for o in output]
return output
# lilo = lin_to_log(4096, strength=1.0)
lilo = exp_lookup(8, strength=1.0)
draw(lilo)
text = ""
text += "// Lookup Table for Exponential Curve\n"
text += f"float exp_lookup[] = {{{', '.join(str(v) for v in lilo)}}};\n\n"
# print(text)
import ipywidgets as widgets
from IPython.display import display, HTML, Javascript
mybtn = widgets.Button(description='copy C++ to clipboard', button_style='success')
def mybtn_event_handler(b):
print("copied")
clipboard.copy(text)
mybtn.on_click(mybtn_event_handler)
display(mybtn)
max(lilo)
```
%% Output
0.9999999999999999
%% Cell type:code id:e51416f3-f34d-4513-9f0c-fa52c468274e tags:
``` python
from matplotlib import pyplot as plt
%matplotlib inline
from ipywidgets import interact, FloatSlider
import matplotlib.transforms as transforms
import math
import clipboard
def draw(f):
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([0, 0, 1, 1])
b = scan2d(x, y, f)
ax.axhline(y=b, color='red', linestyle='--')
ax.axvline(x=f, color='red', linestyle='--')
trans = transforms.blended_transform_factory(
ax.get_yticklabels()[0].get_transform(), ax.transData)
ax.text(0.95, b, "{:.02f}".format(b), color="red", transform=trans, ha="right", va="bottom")
ax.grid()
ax.plot(x, y)
def lerp(a, b, f=0.5) -> float:
f = min(1.0, max(0.0, f))
if f == 0.0:
return a
elif f == 1.0:
return b
else:
return a * (1.0-f) + b * f
def lerp2d(x1, y1, x2, y2, f=0.5):
if f == 0.0:
return [x1, x2]
elif f == 1.0:
return [x1, x2]
else:
x = lerp(x1, x2, f)
y = lerp(y1, y2, f)
return [x, y]
# A function that scans through two lists representing x/y values using a
# third value called f and returns the linear interpolation between those points
def scan2d(x, y, f):
# f = min(1.0, max(0.0, f))
assert len(x) == len(y)
# Find ax and bx for given factor
xa = None
last_value = None
idx = None
for i, v in enumerate(x):
# this = abs(f-v)
this = f-v
if xa is None or this > 0:
xa = this
idx = i
idx2 = min(idx+1, len(x)-1)
if idx == idx2:
return y[idx]
xa = x[idx]
xb = x[idx2]
ya = y[idx]
yb = y[idx2]
xspan = xb-xa
xscaler = 1/xspan
new_f = (f-xa)*xscaler
return lerp(ya, yb, new_f)
# lines_orig = [
# [0.0, 0.0, -0.5],
# [0.45, 0.5, 0.0],
# [0.55, 0.5, 1.0],
# [1.0, 1.0, 0.0],
# ]
# half_deadband = 0.005
# lines_orig = [
# [0.0, -1.0, 0.0],
# [0.0+half_deadband, -1.0, 0.0],
# ]
# steps = list(range(-9, 11))
# for i in steps:
# f = float(i)
# print(f/10)
# lines_orig.append([0.5+f/20-half_deadband, f/10, 0.0])
# lines_orig.append([0.5+f/20+half_deadband, f/10, 0.0])
db = 0.005
hb = db/2.0
lines_orig = [
[0.0, -1.0, 0.0], # -1000%
[0.0+hb, -1.0, 0.0], # -1000%
[0.02-hb, -0.9, 0.0], # -900%
[0.02+hb, -0.9, 0.0], # -900%
[0.04-hb, -0.8, 0.0], # -800%
[0.04+hb, -0.8, 0.0], # -800%
[0.06-hb, -0.7, 0.0], # -700%
[0.06+hb, -0.7, 0.0], # -700%
[0.08-hb, -0.6, 0.0], # -600%
[0.08+hb, -0.6, 0.0], # -600%
[0.1-hb, -0.5, 0.0], # -500%
[0.1+hb, -0.5, 0.0], # -500%
[0.12-hb, -0.4, 0.0], # -400%
[0.12+hb, -0.4, 0.0], # -400%
[0.14-hb, -0.3, 0.0], # -300%
[0.14+hb, -0.3, 0.0], # -300%
[0.16-hb, -0.2, 0.0], # -200%
[0.16+hb, -0.2, 0.0], # -200%
[0.2-hb, -0.1, 0.0], # -100%
[0.2+hb, -0.1, 0.0], # -100%
[0.25-hb, -0.05, 0.0], # -50%
[0.25+hb, -0.05, 0.0], # -50%
[0.3-hb, -0.025, 0.0], # -25%
[0.3+hb, -0.025, 0.0], # -25%
[0.38-hb, -0.0125, 0.0], # -12.5%
[0.38+hb, -0.0125, 0.0], # -12.5%
[0.42-hb, -0.00625, 0.0], # -6.25%
[0.42+hb, -0.00625, 0.0], # -6.25%
[0.46-hb, -0.003125, 0.0], # -3.125%
[0.46+hb, -0.003125, 0.0], # -3.125%
[0.5-hb, 0.0, 0.0], # 0%
[0.5+hb, 0.0, 0.0], # 0%
[1.0-0.46-hb, 0.003125, 0.0], # 3.125%
[1.0-0.46+hb, 0.003125, 0.0], # 3.125%
[1.0-0.42-hb, 0.00625, 0.0], # 6.25%
[1.0-0.42+hb, 0.00625, 0.0], # 6.25%
[1.0-0.38-hb, 0.0125, 0.0], # 12.5%
[1.0-0.38+hb, 0.0125, 0.0], # 12.5%
[1.0-0.3-hb, 0.025, 0.0], # 25%
[1.0-0.3+hb, 0.025, 0.0], # 25%
[1.0-0.25-hb, 0.05, 0.0], # 50%
[1.0-0.25+hb, 0.05, 0.0], # 50%
[1.0-0.2-hb, 0.1, 0.0], # 100%
[1.0-0.2+hb, 0.1, 0.0], # 100%
[1.0-0.16-hb, 0.2, 0.0], # 200%
[1.0-0.16+hb, 0.2, 0.0], # 200%
[1.0-0.14-hb, 0.3, 0.0], # 300%
[1.0-0.14+hb, 0.3, 0.0], # 300%
[1.0-0.12-hb, 0.4, 0.0], # 400%
[1.0-0.12+hb, 0.4, 0.0], # 400%
[1.0-0.1-hb, 0.5, 0.0], # 500%
[1.0-0.1+hb, 0.5, 0.0], # 500%
[1.0-0.08-hb, 0.6, 0.0], # 600%
[1.0-0.08+hb, 0.6, 0.0], # 600%
[1.0-0.06-hb, 0.7, 0.0], # 700%
[1.0-0.06+hb, 0.7, 0.0], # 700%
[1.0-0.04-hb, 0.8, 0.0], # 800%
[1.0-0.04+hb, 0.8, 0.0], # 800%
[1.0-0.02-hb, 0.9, 0.0], # 900%
[1.0-0.02+hb, 0.9, 0.0], # 900%
[1.0-0.0-hb, 1.0, 0.0], # 1000%
[1.0-0.0, 1.0, 0.0], # 1000%
]
# Calculate curves for points of curvature
def make_lines(lines_orig, resolution=20):
lines = []
for i, l in enumerate(lines_orig):
i2 = min(len(lines_orig)-1, i+1)
if l[2] == 0.0:
lines.append(l)
else:
xa = lines_orig[i][0]
xb = lines_orig[i2][0]
ya = lines_orig[i][1]
yb = lines_orig[i2][1]
x_span = xb-xa
y_span = yb-ya
x_step = 1/20
y_step = 1/20
for j in range(resolution):
x = x_step * j
y = y_step * j
y_curve = 0
if l[2] > 0.0:
y_curve = y*y*y
else:
y_curve = y*y
y = (1.0-l[2]) * y + l[2] * y_curve
lines.append([xa+x*x_span, ya+y*y_span, 0.0])
return lines
lines = make_lines(lines_orig, 20)
x = [a[0] for a in lines]
y = [a[1] for a in lines]
c = [a[2] for a in lines]
# draw(x, y, 0.45/2)
interact(draw, f=FloatSlider(min=min(x), max=max(x), step=0.001, value=0.2))
length = len(x)
text = ""
text += "// Lookup Table for Pitch Knob\n"
text += f"float pitch_knob_lookup_x[] = {{{', '.join(str(xv) for xv in x)}}};\n"
text += f"float pitch_knob_lookup_y[] = {{{', '.join(str(yv) for yv in y)}}};\n"
text += f"size_t pitch_knob_lookup_length = {length};\n"
import ipywidgets as widgets
from IPython.display import display, HTML, Javascript
mybtn = widgets.Button(description='copy C++ to clipboard', button_style='success')
def mybtn_event_handler(b):
print("copied")
clipboard.copy(text)
mybtn.on_click(mybtn_event_handler)
display(mybtn)
```
%% Output
%% Cell type:code id:f35f1609-3a10-4dce-b7dd-201d79f2c39c tags:
``` python
# Saturation curve
# X / Y / Curvature
lines_orig = [
[-1.5, -1.0, 1.0],
[-0.9, -0.8, 0.0],
[0.0, 0.0, 0.0],
[0.9, 0.8, -1.1],
[1.5, 1.0, 0.0],
]
lines = make_lines(lines_orig, 8)
x = [a[0] for a in lines]
y = [min(1.0, a[1]) for a in lines]
c = [a[2] for a in lines]
# draw(x, y, 0.45/2)
interact(draw, f=FloatSlider(min=min(x), max=max(x), step=0.001, value=0.2))
length = len(x)
text = ""
text += "// Lookup Curves for Saturation b\n"
text += f"float saturation_lookup_x[] = {{{', '.join(str(xv) for xv in x)}}};\n"
text += f"float saturation_lookup_y[] = {{{', '.join(str(yv) for yv in y)}}};\n"
text += f"size_t saturation_lookup_length = {length};\n"
import ipywidgets as widgets
from IPython.display import display, HTML, Javascript
mybtn = widgets.Button(description='copy C++ to clipboard', button_style='success')
def mybtn_event_handler(b):
print("copied")
clipboard.copy(text)
mybtn.on_click(mybtn_event_handler)
display(mybtn)
print(len(x))
```
%% Output
19
%% Cell type:code id:f0cd9d06-a15a-46b4-a3ef-4aee3d4f7cd0 tags:
``` python
# X / Y / Curvature
def draw_rgb(xr, yr, xg, yg, xb, yb):
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([0, 0, 1, 1])
ax.grid()
ax.plot(xr, yr, 'r')
ax.plot(xg, yg, 'g')
ax.plot(xb, yb, 'b')
# BLUE
lines_b = [
[0, 0, 0.8],
[40, 10, -1.0],
[170, 0, 1.0],
]
lines_b = make_lines(lines_b, 16)
xb = [a[0] for a in lines_b]
yb = [a[1] for a in lines_b]
# Green
lines_g = [
[10, 0, 1.0],
[180, 60, -0.2],
[250, 0, 0.0],
]
lines_g = make_lines(lines_g, 16)
xg = [a[0] for a in lines_g]
yg = [a[1] for a in lines_g]
# RED
lines_r = [
[170, 0, 1.0],
[240, 30, 0.9],
[255, 255, 0.0],
]
lines_r = make_lines(lines_r, 16)
xr = [a[0] for a in lines_r]
yr = [a[1] for a in lines_r]
draw_rgb(xr, yr, xg, yg, xb, yb)
length = len(xr)
text = ""
text += "// Lookup Curves LED Red b\n"
text += f"float red_lut_x[] = {{{', '.join(str(xv) for xv in xr)}}};\n"
text += f"float red_lut_y[] = {{{', '.join(str(yv) for yv in yr)}}};\n"
text += f"size_t red_lut_len = {length};\n\n"
length = len(xg)
text += "// Lookup Curves LED Green b\n"
text += f"float green_lut_x[] = {{{', '.join(str(xv) for xv in xg)}}};\n"
text += f"float green_lut_y[] = {{{', '.join(str(yv) for yv in yg)}}};\n"
text += f"size_t green_lut_len = {length};\n\n"
length = len(xb)
text += "// Lookup Curves LED Blue b\n"
text += f"float blue_lut_x[] = {{{', '.join(str(xv) for xv in xb)}}};\n"
text += f"float blue_lut_y[] = {{{', '.join(str(yv) for yv in yb)}}};\n"
text += f"size_t blue_lut_len = {length};\n\n"
import ipywidgets as widgets
from IPython.display import display, HTML, Javascript
mybtn = widgets.Button(description='copy C++ to clipboard', button_style='success')
def mybtn_event_handler(b):
print("copied")
clipboard.copy(text)
mybtn.on_click(mybtn_event_handler)
display(mybtn)
```
%% Output
%% Cell type:code id:59b56dbc-6852-4989-bc19-3525ee7caf8b tags:
``` python
```
%% Output
1.0
%% Cell type:code id:5a511d24-cc91-450f-83e4-8295647d9391 tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment