示例#1
0
class Pascal(threading.Thread):
    def run(self):
        """Run the thang"""
        global addr
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=addr)
        self.reset()
        while True:
            if self.terminate:
                return
            for i in range(self.holiday.NUM_GLOBES):
                col = self.wheel[self.values[i] % self.mod]
                self.holiday.setglobe(i, *col)
                if i == 0:
                    self.values[i] = 1
                else:
                    self.values[i] = self.values[i] + self.values[i - 1]
            self.holiday.render()  # Send the colours out
            time.sleep(SLEEP)
            self.tick += 1
            if self.tick > ITERS:
                self.reset()

    def reset(self):
        self.values = [1 for i in range(self.holiday.NUM_GLOBES)]
        self.mod = random.randint(2, 36)
        s = float(self.mod) / 36.0
        self.wheel = colourwheel(self.mod, s)
        self.tick = 0
        print "Pascal mod " + str(self.mod)
示例#2
0
    def run(self):
        """Run the thing"""
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=self.ip)
        self.pulses = []
        while True:
            if self.terminate:
                return
            for p in self.pulses:
                p.move()            
            self.pulses = [p for p in self.pulses if p.active]

            for i in range(self.holiday.NUM_GLOBES):
                r = 0
                b = 0
                g = 0
                for p in self.pulses:
                    ( r1, g1, b1 ) = p.colours(i)
                    r += r1
                    g += g1
                    b += b1
                self.holiday.setglobe(i, toholiday(r), toholiday(g), toholiday(b))
            self.holiday.render() 

            if not self.queue.empty():
                p = self.queue.get()
                self.pulses.append(p)

            time.sleep(self.wait)
示例#3
0
class Sineapp(threading.Thread):

    def run(self):
        """Run the """
        global addr
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=addr)
        self.init()
        self.tick = 0
        while True:
            if self.terminate:
                return
            roff = int(self.tick * RV)
            goff = int(self.tick * GV)
            boff = int(self.tick * BV)
            for i in range(self.holiday.NUM_GLOBES):
                ri = (roff + RMULT * i * self.atog) % SINELENGTH
                gi = (goff + GMULT * i * self.atog) % SINELENGTH
                bi = (boff + BMULT * i * self.atog) % SINELENGTH
                self.holiday.setglobe(i, self.sine[ri], self.sine[gi], self.sine[bi])
            self.holiday.render()       # Send the colours out
            time.sleep(SLEEP)
            self.tick += 1
        
        

    def init(self):
        """Builds a shape based on a sinewave"""
        self.sine = []
        for i in range(SINELENGTH):
            theta = 2.0 * math.pi * i / SINELENGTH
            self.sine.append(int(32 + 31 * math.sin(theta)))
        self.atog = SINELENGTH / self.holiday.NUM_GLOBES
示例#4
0
class CARunner(threading.Thread):

    def setup(self, ca):
        self.ca = ca
        
    def run(self):
        """Run an CellularAutomaton"""
        global addr
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=addr)
        self.ca.start(self.holiday.NUM_GLOBES)
        while True:
            if self.terminate:
                return
            self.ca.step()
            for i in range(self.holiday.NUM_GLOBES):
                self.holiday.setglobe(i, *self.ca.cell(i))
            self.holiday.render()       
            time.sleep(SLEEP)
            

    def reset(self):
        self.values = [1 for i in range(self.holiday.NUM_GLOBES)]
        self.mod = random.randint(2, 36)
        s = float(self.mod) / 36.0
        self.wheel = colourwheel(self.mod, s)
        self.tick = 0
        print "Pascal mod " + str(self.mod)
示例#5
0
class Timecolourapp(threading.Thread):

    def run(self):
        """Go"""
        global addr
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=addr)
        self.values = []
        for i in range(self.holiday.NUM_GLOBES):
            self.values.append((0, 0, 0))
        self.render()
        while True:
            if self.terminate:
                return
            nt = datetime.datetime.now()
            col = timecolour(nt)
            self.values.append(col)
            del(self.values[0])
            self.render()       # Send the colours out
            time.sleep(1)       # And finally, wait.

    def render(self):
        for i, (r, g, b) in enumerate(self.values):
            self.holiday.setglobe(i, r, g, b)
        self.holiday.render()
示例#6
0
class CARunner(threading.Thread):
    def setup(self, ca):
        self.ca = ca

    def run(self):
        """Run an CellularAutomaton"""
        global addr
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=addr)
        self.ca.start(self.holiday.NUM_GLOBES)
        while True:
            if self.terminate:
                return
            self.ca.step()
            for i in range(self.holiday.NUM_GLOBES):
                self.holiday.setglobe(i, *self.ca.cell(i))
            self.holiday.render()
            time.sleep(SLEEP)

    def reset(self):
        self.values = [1 for i in range(self.holiday.NUM_GLOBES)]
        self.mod = random.randint(2, 36)
        s = float(self.mod) / 36.0
        self.wheel = colourwheel(self.mod, s)
        self.tick = 0
        print "Pascal mod " + str(self.mod)
示例#7
0
class Dropsapp(threading.Thread):

    def run(self):
        """Go"""
        global addr
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=addr)
        self.n = 8
        self.setup(self.n)
        while True:
            if self.terminate:
                return
            for j in range(self.n):
                self.drops[j].move()
            for i in range(self.holiday.NUM_GLOBES):
                r = 0.0
                b = 0.0
                g = 0.0
                for j in range(self.n):
                    ( r1, g1, b1 ) = self.drops[j].brightness(i)
                    r += r1
                    g += g1
                    b += b1
                self.holiday.setglobe(i, toholiday(r), toholiday(g), toholiday(b))
            self.holiday.render()       # Send the colours out
            time.sleep(.01)       # And finally, wait.


    def setup(self, n):
        """Make some things"""
        self.drops = []
        for i in range(n):
            d = Drop()
            d.show()
            self.drops.append(d)
示例#8
0
    def __init__(self, addr, config, grad):
        self.DECAY = config['decay']
        self.WAVELET = 10
        self.WAVEMULT = 100 // self.WAVELET
        self.holiday = HolidaySecretAPI(addr=addr)
        self.levels = [0.0] * 50
        self.buffer = [(0, 0, 0)] * 50
        self.mode = config['mode']
        self.gradient = grad
        self.ngrad = len(self.gradient)

        maps = config['maps']
        if 'map' not in config:
            self.map = range(50)
        else:
            self.makemap(maps[config['map']])

        if self.mode == 'wave':
            self.render = self.render_wave
        else:
            self.render = self.render_spectrum
            if self.mode == 'levels':
                self.f_col = self.f_col_levels
            else:
                self.f_col = self.f_col_spectrum
示例#9
0
class Sineapp(threading.Thread):
    def run(self):
        """Run the """
        global addr
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=addr)
        self.init()
        self.tick = 0
        while True:
            if self.terminate:
                return
            roff = int(self.tick * RV)
            goff = int(self.tick * GV)
            boff = int(self.tick * BV)
            for i in range(self.holiday.NUM_GLOBES):
                ri = (roff + RMULT * i * self.atog) % SINELENGTH
                gi = (goff + GMULT * i * self.atog) % SINELENGTH
                bi = (boff + BMULT * i * self.atog) % SINELENGTH
                self.holiday.setglobe(i, self.sine[ri], self.sine[gi],
                                      self.sine[bi])
            self.holiday.render()  # Send the colours out
            time.sleep(SLEEP)
            self.tick += 1

    def init(self):
        """Builds a shape based on a sinewave"""
        self.sine = []
        for i in range(SINELENGTH):
            theta = 2.0 * math.pi * i / SINELENGTH
            self.sine.append(int(32 + 31 * math.sin(theta)))
        self.atog = SINELENGTH / self.holiday.NUM_GLOBES
示例#10
0
class Pascal(threading.Thread):

    def run(self):
        """Run the thang"""
        global addr
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=addr)
        self.reset()
        while True:
            if self.terminate:
                return
            for i in range(self.holiday.NUM_GLOBES):
                col = self.wheel[self.values[i] % self.mod]
                self.holiday.setglobe(i, *col)
                if i == 0:
                    self.values[i] = 1
                else:
                    self.values[i] = self.values[i] + self.values[i - 1]
            self.holiday.render()       # Send the colours out
            time.sleep(SLEEP)
            self.tick += 1
            if self.tick > ITERS:
                self.reset()
            

    def reset(self):
        self.values = [1 for i in range(self.holiday.NUM_GLOBES)]
        self.mod = random.randint(2, 36)
        s = float(self.mod) / 36.0
        self.wheel = colourwheel(self.mod, s)
        self.tick = 0
        print "Pascal mod " + str(self.mod)
示例#11
0
class Blinkyapp(threading.Thread):

    def run(self):
        """Gonna make some pretty pretty colours here"""
        global addr
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=addr)
        while True:
            if self.terminate:
                return
            ln = 0
            while (ln < self.holiday.NUM_GLOBES):
                r = random.randint(0, 63)
                g = random.randint(0, 63)
                b = random.randint(0, 63)
                # Now based on another random value, squash one of these values
                cn = random.randint(0,2)
                if (cn == 0):
                    r = 0
                elif (cn == 1):
                    g = 0
                else:
                    b = 0
                self.holiday.setglobe(ln, r, g, b)
                ln = ln+1            

            self.holiday.render()       # Send the colours out
            time.sleep(0.2)       # And finally, wait.
示例#12
0
 def run(self):
     """Go"""
     global addr
     self.terminate = False
     self.holiday = HolidaySecretAPI(addr=addr)
     self.s = 0
     self.sorters = [Bubblesorter, Insertsorter, Mergesorter, Quicksorter]
     while True:
         if self.terminate:
             return
         self.runsort()
         time.sleep(SLEEP_BETWEEN)
示例#13
0
 def run(self):
     """Run an CellularAutomaton"""
     global addr
     self.terminate = False
     self.holiday = HolidaySecretAPI(addr=addr)
     self.ca.start(self.holiday.NUM_GLOBES)
     while True:
         if self.terminate:
             return
         self.ca.step()
         for i in range(self.holiday.NUM_GLOBES):
             self.holiday.setglobe(i, *self.ca.cell(i))
         self.holiday.render()
         time.sleep(SLEEP)
示例#14
0
 def run(self):
     """Go"""
     global addr
     self.terminate = False
     self.holiday = HolidaySecretAPI(addr=addr)
     self.tick = 0
     self.n = len(pattern)
     while True:
         if self.terminate:
             return
         for i in range(self.holiday.NUM_GLOBES):
             k = (i + self.tick) % self.n
             ( r, g, b ) = pattern[k]
             self.holiday.setglobe(i, r, g, b)
         self.tick += 1
         self.holiday.render()  
         time.sleep(.3)       
示例#15
0
class Pulser(Thread):
    """
    A Thread which reads a Queue for things to turn into Pulses and
    renders them via the Holiday API.

    p = Pulser(holiday_ip, queue)
    p.run()

    """
    def __init__(self, ip, queue, wait):
        self.queue = queue
        self.ip = ip
        self.wait = wait
        Thread.__init__(self)


    def run(self):
        """Run the thing"""
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=self.ip)
        self.pulses = []
        while True:
            if self.terminate:
                return
            for p in self.pulses:
                p.move()            
            self.pulses = [p for p in self.pulses if p.active]

            for i in range(self.holiday.NUM_GLOBES):
                r = 0
                b = 0
                g = 0
                for p in self.pulses:
                    ( r1, g1, b1 ) = p.colours(i)
                    r += r1
                    g += g1
                    b += b1
                self.holiday.setglobe(i, toholiday(r), toholiday(g), toholiday(b))
            self.holiday.render() 

            if not self.queue.empty():
                p = self.queue.get()
                self.pulses.append(p)

            time.sleep(self.wait)
示例#16
0
 def run(self):
     """Go"""
     global addr
     self.terminate = False
     self.holiday = HolidaySecretAPI(addr=addr)
     self.values = []
     for i in range(self.holiday.NUM_GLOBES):
         self.values.append((0, 0, 0))
     self.render()
     while True:
         if self.terminate:
             return
         nt = datetime.datetime.now()
         col = timecolour(nt)
         self.values.append(col)
         del (self.values[0])
         self.render()  # Send the colours out
         time.sleep(1)  # And finally, wait.
示例#17
0
	def run(self):
		global holiday_address
		self.terminate = False
		self.hol = HolidaySecretAPI(addr=holiday_address)

		while True:
			if self.terminate:
				self.reset_globes()
				return
			cpus = self.fetch_cpu_vals()
			self.my_render(cpus)
示例#18
0
 def run(self):
     """Run the thang"""
     global addr
     self.terminate = False
     self.holiday = HolidaySecretAPI(addr=addr)
     self.reset()
     while True:
         if self.terminate:
             return
         for i in range(self.holiday.NUM_GLOBES):
             col = self.wheel[self.values[i] % self.mod]
             self.holiday.setglobe(i, *col)
             if i == 0:
                 self.values[i] = 1
             else:
                 self.values[i] = self.values[i] + self.values[i - 1]
         self.holiday.render()  # Send the colours out
         time.sleep(SLEEP)
         self.tick += 1
         if self.tick > ITERS:
             self.reset()
示例#19
0
 def run(self):
     """Go"""
     global addr
     self.terminate = False
     self.holiday = HolidaySecretAPI(addr=addr)
     self.s = 0
     self.sorters = [Bubblesorter, Insertsorter, Mergesorter, Quicksorter ]
     while True:
         if self.terminate:
             return
         self.runsort()
         time.sleep(SLEEP_BETWEEN)
示例#20
0
 def run(self):
     """Run the """
     global addr
     self.terminate = False
     self.holiday = HolidaySecretAPI(addr=addr)
     self.init()
     self.tick = 0
     while True:
         if self.terminate:
             return
         roff = int(self.tick * RV)
         goff = int(self.tick * GV)
         boff = int(self.tick * BV)
         for i in range(self.holiday.NUM_GLOBES):
             ri = (roff + RMULT * i * self.atog) % SINELENGTH
             gi = (goff + GMULT * i * self.atog) % SINELENGTH
             bi = (boff + BMULT * i * self.atog) % SINELENGTH
             self.holiday.setglobe(i, self.sine[ri], self.sine[gi],
                                   self.sine[bi])
         self.holiday.render()  # Send the colours out
         time.sleep(SLEEP)
         self.tick += 1
示例#21
0
 def run(self):
     """Run an CellularAutomaton"""
     global addr
     self.terminate = False
     self.holiday = HolidaySecretAPI(addr=addr)
     self.ca.start(self.holiday.NUM_GLOBES)
     while True:
         if self.terminate:
             return
         self.ca.step()
         for i in range(self.holiday.NUM_GLOBES):
             self.holiday.setglobe(i, *self.ca.cell(i))
         self.holiday.render()       
         time.sleep(SLEEP)
示例#22
0
class Timecolourapp(threading.Thread):
    def run(self):
        """Go"""
        global addr
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=addr)
        self.values = []
        for i in range(self.holiday.NUM_GLOBES):
            self.values.append((0, 0, 0))
        self.render()
        while True:
            if self.terminate:
                return
            nt = datetime.datetime.now()
            col = timecolour(nt)
            self.values.append(col)
            del (self.values[0])
            self.render()  # Send the colours out
            time.sleep(1)  # And finally, wait.

    def render(self):
        for i, (r, g, b) in enumerate(self.values):
            self.holiday.setglobe(i, r, g, b)
        self.holiday.render()
示例#23
0
 def run(self):
     """Go"""
     global addr
     self.terminate = False
     self.holiday = HolidaySecretAPI(addr=addr)
     self.n = 8
     self.setup(self.n)
     while True:
         if self.terminate:
             return
         for j in range(self.n):
             self.drops[j].move()
         for i in range(self.holiday.NUM_GLOBES):
             r = 0.0
             b = 0.0
             g = 0.0
             for j in range(self.n):
                 ( r1, g1, b1 ) = self.drops[j].brightness(i)
                 r += r1
                 g += g1
                 b += b1
             self.holiday.setglobe(i, toholiday(r), toholiday(g), toholiday(b))
         self.holiday.render()       # Send the colours out
         time.sleep(.01)       # And finally, wait.
示例#24
0
 def run(self):
     """Go"""
     global addr
     self.terminate = False
     self.holiday = HolidaySecretAPI(addr=addr)
     self.values = []
     for i in range(self.holiday.NUM_GLOBES):
         self.values.append((0, 0, 0))
     self.render()
     while True:
         if self.terminate:
             return
         nt = datetime.datetime.now()
         col = timecolour(nt)
         self.values.append(col)
         del(self.values[0])
         self.render()       # Send the colours out
         time.sleep(1)       # And finally, wait.
示例#25
0
 def run(self):
     """Run the thang"""
     global addr
     self.terminate = False
     self.holiday = HolidaySecretAPI(addr=addr)
     self.reset()
     while True:
         if self.terminate:
             return
         for i in range(self.holiday.NUM_GLOBES):
             col = self.wheel[self.values[i] % self.mod]
             self.holiday.setglobe(i, *col)
             if i == 0:
                 self.values[i] = 1
             else:
                 self.values[i] = self.values[i] + self.values[i - 1]
         self.holiday.render()       # Send the colours out
         time.sleep(SLEEP)
         self.tick += 1
         if self.tick > ITERS:
             self.reset()
示例#26
0
 def run(self):
     """Run the """
     global addr
     self.terminate = False
     self.holiday = HolidaySecretAPI(addr=addr)
     self.init()
     self.tick = 0
     while True:
         if self.terminate:
             return
         roff = int(self.tick * RV)
         goff = int(self.tick * GV)
         boff = int(self.tick * BV)
         for i in range(self.holiday.NUM_GLOBES):
             ri = (roff + RMULT * i * self.atog) % SINELENGTH
             gi = (goff + GMULT * i * self.atog) % SINELENGTH
             bi = (boff + BMULT * i * self.atog) % SINELENGTH
             self.holiday.setglobe(i, self.sine[ri], self.sine[gi], self.sine[bi])
         self.holiday.render()       # Send the colours out
         time.sleep(SLEEP)
         self.tick += 1
示例#27
0
class HCMapp(threading.Thread):

	def run(self):
		global holiday_address
		self.terminate = False
		self.hol = HolidaySecretAPI(addr=holiday_address)

		while True:
			if self.terminate:
				self.reset_globes()
				return
			cpus = self.fetch_cpu_vals()
			self.my_render(cpus)

	def reset_globes(self):
		for globeindex in range(self.hol.NUM_GLOBES):
			self.hol.setglobe(globeindex, 0x00, 0x00, 0x00)
		self.hol.render()

	def my_render(self, cpus):
		""" Renders a list of CPU usage values to the Holiday """
		led_on = 0xFF
		led_off = 0x00

		globes = self.hol.NUM_GLOBES
		
		green = []
		blue = []
		red = []
		
		cpu_count = len(cpus)
		globes_per_fragment_base = globes // cpu_count
		remainder = globes % cpu_count
		stride = cpu_count // remainder
		fragment_counts = []

		for cpu in range(cpu_count):
			if (cpu % stride == 0):
				fragment_counts.append(globes_per_fragment_base + 1)
			else:
				fragment_counts.append(globes_per_fragment_base)
			
		for cpu in range(cpu_count):
			fragment_count = fragment_counts[cpu]
			greencount = (cpus[cpu] * fragment_count) / 100
			
			# Fill the arrays of colours
			for globe in range(fragment_count):
				if globe < greencount:
					if globe >= fragment_count - ((fragment_count * 25) / 100):
						red.append(led_on)
						green.append(led_off)
					else:
						red.append(led_off)
						green.append(led_on)
					blue.append(led_off)
				else:
					green.append(led_off)
					blue.append(led_off)
					red.append(led_off)

		# Set the globe values and render
		for globeindex in range(globes):
			self.hol.setglobe(globeindex, red[globeindex], green[globeindex], blue[globeindex])
		self.hol.render()

	def fetch_cpu_vals(self):
		""" Get the CPU use values from psutil """
		return psutil.cpu_percent(interval=0.075, percpu=True)
示例#28
0
class Sorterapp(threading.Thread):

    def run(self):
        """Go"""
        global addr
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=addr)
        self.s = 0
        self.sorters = [Bubblesorter, Insertsorter, Mergesorter, Quicksorter ]
        while True:
            if self.terminate:
                return
            self.runsort()
            time.sleep(SLEEP_BETWEEN)

    def runsort(self):
        list = range(self.holiday.NUM_GLOBES)
        shuffle(list)
        self.makegradient()
        sorter = self.makesorter(list)
        sorter.sort()
        self.render(list, -1)

    def makesorter(self, list):
        sorterc = self.sorters[self.s]
        self.s += 1
        if self.s == len(self.sorters):
            self.s = 0
        print "Algorithm: ", sorterc
        sorter = sorterc(list, lambda l, c: self.render(l, c))
        return sorter

    def render(self, list, cursor):
        i = 0
        for l in list:
            ( r, g, b ) = self.gradient(l)
            self.holiday.setglobe(i, r, g, b)
            i += 1
        if cursor > -1:
            self.holiday.setglobe(cursor, *CURSOR)
        self.holiday.render()
        time.sleep(WAIT)

    def makegradient(self):
        #c = random.sample(COLOURS, 2)
        self.grvalues = []
        h1 = random.random()
        h2 = h1 + .5 + random.uniform(-.25, .25)
        if h2 > 1:
            h2 -= 1
        s1 = random.uniform(.5, 1)
        s2 = random.uniform(.5, 1)
        n = self.holiday.NUM_GLOBES
        fn = float(n)
        
        for i in range(n):
            k = i / fn
            h = lerp(h1, h2, k)
            s = lerp(s1, s2, k)
            ( r, g, b ) = colorsys.hsv_to_rgb(h, s, 1)
            self.grvalues.append(rgbtoholiday(r, g, b))
        
        self.gradient = lambda i: self.grvalues[i]
示例#29
0
 def __init__(self, ip):
     self.ip = ip
     self.holiday = HolidaySecretAPI(addr=ip)
示例#30
0
class HolidaySpectrum:
    def __init__(self, addr, config, grad):
        self.DECAY = config['decay']
        self.WAVELET = 10
        self.WAVEMULT = 100 // self.WAVELET
        self.holiday = HolidaySecretAPI(addr=addr)
        self.levels = [0.0] * 50
        self.buffer = [(0, 0, 0)] * 50
        self.mode = config['mode']
        self.gradient = grad
        self.ngrad = len(self.gradient)

        maps = config['maps']
        if 'map' not in config:
            self.map = range(50)
        else:
            self.makemap(maps[config['map']])

        if self.mode == 'wave':
            self.render = self.render_wave
        else:
            self.render = self.render_spectrum
            if self.mode == 'levels':
                self.f_col = self.f_col_levels
            else:
                self.f_col = self.f_col_spectrum

    def makemap(self, map):
        m = []
        for s in map:
            if type(s) == list:
                a = s[0]
                b = s[1]
                if a < b:
                    m += range(a, b + 1)
                else:
                    m += range(a, b - 1, -1)
            else:
                m.append(s)
        complete = True
        if len(m) != 50:
            print("Map has wrong number of elements: {}".format(len(m)))
            complete = False
        for i in range(50):
            if i not in m:
                print("Globe {} not found in map".format(i))
                complete = False
        if not complete:
            print("Map isn't complete")
            sys.exit(-1)
        self.map = m

    def f_col_levels(self, i, level):
        k = int(level * self.ngrad)
        if k > self.ngrad - 1:
            k = self.ngrad - 1
        return self.gradient[k]

    def f_col_spectrum(self, i, level):
        k = level
        if k > 1.0:
            k = 1.0
        (r, g, b) = self.gradient[i]
        return (int(r * k), int(g * k), int(b * k))

    def decay(self, i, level):
        if not self.DECAY:
            return level
        else:
            dl = self.levels[i] * self.DECAY
            if level > dl:
                self.levels[i] = level
            else:
                self.levels[i] = dl
            return self.levels[i]

    def render_spectrum(self, analyzer):
        """Render a frequency spectrum"""
        for i in range(50):
            l = self.decay(i, analyzer.spectrum[i])
            (r, g, b) = self.f_col(i, l)
            self.setglobe(i, r, g, b)
        self.holiday.render()

    def render_wave(self, analyzer):
        """Render the raw waveform"""
        self.buffer = self.buffer[self.WAVELET:]
        for i in range(self.WAVELET):
            v = int(self.ngrad * abs(analyzer.left[self.WAVEMULT * i] +
                                     analyzer.right[self.WAVEMULT * i]))
            if v > self.ngrad - 1:
                v = self.ngrad - 1
            (r, g, b) = self.gradient[v]
            self.buffer.append((r, g, b))
        for i in range(50):
            self.setglobe(i, *self.buffer[i])
        self.holiday.render()

    def setglobe(self, i, r, g, b):
        self.holiday.setglobe(self.map[i], r, g, b)

    def demo(self):
        for i in range(50):
            (r, g, b) = self.gradient[i]
            self.setglobe(i, r, g, b)
        self.holiday.render()
示例#31
0
class Sorterapp(threading.Thread):
    def run(self):
        """Go"""
        global addr
        self.terminate = False
        self.holiday = HolidaySecretAPI(addr=addr)
        self.s = 0
        self.sorters = [Bubblesorter, Insertsorter, Mergesorter, Quicksorter]
        while True:
            if self.terminate:
                return
            self.runsort()
            time.sleep(SLEEP_BETWEEN)

    def runsort(self):
        list = range(self.holiday.NUM_GLOBES)
        shuffle(list)
        self.makegradient()
        sorter = self.makesorter(list)
        sorter.sort()
        self.render(list, -1)

    def makesorter(self, list):
        sorterc = self.sorters[self.s]
        self.s += 1
        if self.s == len(self.sorters):
            self.s = 0
        print "Algorithm: ", sorterc
        sorter = sorterc(list, lambda l, c: self.render(l, c))
        return sorter

    def render(self, list, cursor):
        i = 0
        for l in list:
            (r, g, b) = self.gradient(l)
            self.holiday.setglobe(i, r, g, b)
            i += 1
        if cursor > -1:
            self.holiday.setglobe(cursor, *CURSOR)
        self.holiday.render()
        time.sleep(WAIT)

    def makegradient(self):
        #c = random.sample(COLOURS, 2)
        self.grvalues = []
        h1 = random.random()
        h2 = h1 + .5 + random.uniform(-.25, .25)
        if h2 > 1:
            h2 -= 1
        s1 = random.uniform(.5, 1)
        s2 = random.uniform(.5, 1)
        n = self.holiday.NUM_GLOBES
        fn = float(n)

        for i in range(n):
            k = i / fn
            h = lerp(h1, h2, k)
            s = lerp(s1, s2, k)
            (r, g, b) = colorsys.hsv_to_rgb(h, s, 1)
            self.grvalues.append(rgbtoholiday(r, g, b))

        self.gradient = lambda i: self.grvalues[i]