Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

rainbow2d: Simplify

  • Loading branch information...
commit 27f2540dcc1b9ff4783f9cf2a6fa530fe9121583 1 parent da77b81
Petr Baudis pasky authored

Showing 1 changed file with 6 additions and 16 deletions. Show diff stats Hide diff stats

  1. +6 16 host_python/rainbow2d.py
22 host_python/rainbow2d.py
@@ -35,23 +35,13 @@ def lint(x, points, values):
35 35 def set_pixel_2d(bar, x, y, r, g, b):
36 36 bar.set_pixel(WIDTH - x - 1 + y*WIDTH, r, g, b)
37 37
38   -def combine(*fncs):
39   - return lambda *args: reduce(
40   - id,
41   - reduce(
42   - lambda acc,fnc:(fnc(*acc),),
43   - reversed(fncs),
44   - args)
45   - )
46   -
47   -def flip(f):
48   - return lambda *a: f(*reversed(a))
49   -
50 38 def cdist(center, point, scale):
51   - from operator import add,sub
52   - from math import sqrt
53   - from functools import partial
54   - return scale*sqrt(reduce(add, map(combine(partial(flip(pow),2),sub),center,point)))
  39 + dist = math.sqrt(reduce(
  40 + lambda a,b: a+b,
  41 + map(lambda (x,y): (x-y)**2, zip(center,point))
  42 + ))
  43 + dist = dist*scale
  44 + return dist
55 45
56 46 l = Ledbar(PIXELS)
57 47

0 comments on commit 27f2540

Please sign in to comment.
Something went wrong with that request. Please try again.