Skip to content

Commit

Permalink
rainbow2d: nicer distance function !!
Browse files Browse the repository at this point in the history
  • Loading branch information
pborky committed Dec 23, 2012
1 parent a6e28d7 commit 04d3f07
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions host_python/rainbow2d.py
Expand Up @@ -35,13 +35,23 @@ def lint(x, points, values):
def set_pixel_2d(bar, x, y, 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):
dist = math.sqrt(reduce(
lambda a,b: a+b,
map(lambda (x,y): (x-y)**2, zip(center,point))
))
dist = dist*scale
return dist
from operator import add,sub
from math import sqrt
from functools import partial
return scale*sqrt(reduce(add, map(combine(partial(flip(pow),2),sub),center,point)))

l = Ledbar(PIXELS)

Expand Down

0 comments on commit 04d3f07

Please sign in to comment.