mirror of
https://github.com/brmlab/ledbar.git
synced 2025-06-09 05:14:03 +02:00
rainbow2d: Simplify
This commit is contained in:
parent
da77b81f52
commit
27f2540dcc
1 changed files with 6 additions and 16 deletions
|
@ -35,23 +35,13 @@ corr_b_v = [0.0, 0.13, 0.18, 1.0]
|
||||||
def set_pixel_2d(bar, x, y, r, g, b):
|
def set_pixel_2d(bar, x, y, r, g, b):
|
||||||
bar.set_pixel(WIDTH - x - 1 + y*WIDTH, r, g, b)
|
bar.set_pixel(WIDTH - x - 1 + y*WIDTH, r, g, b)
|
||||||
|
|
||||||
def combine(*fncs):
|
|
||||||
return lambda *args: reduce(
|
|
||||||
id,
|
|
||||||
reduce(
|
|
||||||
lambda acc,fnc:(fnc(*acc),),
|
|
||||||
reversed(fncs),
|
|
||||||
args)
|
|
||||||
)
|
|
||||||
|
|
||||||
def flip(f):
|
|
||||||
return lambda *a: f(*reversed(a))
|
|
||||||
|
|
||||||
def cdist(center, point, scale):
|
def cdist(center, point, scale):
|
||||||
from operator import add,sub
|
dist = math.sqrt(reduce(
|
||||||
from math import sqrt
|
lambda a,b: a+b,
|
||||||
from functools import partial
|
map(lambda (x,y): (x-y)**2, zip(center,point))
|
||||||
return scale*sqrt(reduce(add, map(combine(partial(flip(pow),2),sub),center,point)))
|
))
|
||||||
|
dist = dist*scale
|
||||||
|
return dist
|
||||||
|
|
||||||
l = Ledbar(PIXELS)
|
l = Ledbar(PIXELS)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue