Ejemplo n.º 1
0
def main():
    pm = PixelMatrix(pin, rows, cols)
    pm.clear()
    elapsed = 0

    while True:
        row = randrange(rows)
        col = randrange(cols)
        pm[(row, col)] = random_color(brightness=brightness)
        pm.write()
        time.sleep(wait_time)
        elapsed += wait_time

        if elapsed >= reset_time:
            elapsed = 0
            pm.clear()
Ejemplo n.º 2
0
	def muc_msg(self, msg, nick, **keywords):
		r = r'^dice ([0-9]+)?d([0-9]+)?$'
		match = re.match(r, msg)
		if match:
			dice = int(match.group(1)) if \
					not match.group(1) is None else 1
			eyes = int(match.group(2)) if \
					not match.group(2) is None else 6
			result = sum([ randrange(1, eyes + 1) \
					for x in range(dice)])
			self.send_muc(str(result))
Ejemplo n.º 3
0
 def muc_msg(self, msg, nick, **keywords):
     r = r'^dice ([0-9]+)?d([0-9]+)?$'
     match = re.match(r, msg)
     if match:
         dice = int(match.group(1)) if \
           not match.group(1) is None else 1
         eyes = int(match.group(2)) if \
           not match.group(2) is None else 6
         result = sum([ randrange(1, eyes + 1) \
           for x in range(dice)])
         self.send_muc(str(result))
    def main(self):
        """Main working loop."""

        new = ()
        while True:
            payload = (yield new)

            # pick a random node to sync with but not me
            c = tuple(self.network.keys() - {self.pk})[randrange(self.n - 1)]
            new = self.sync(c, payload)
            self.divide_rounds(new)

            new_c = self.decide_fame()
            self.find_order(new_c)
def test(n_nodes, n_turns):
    kps = [crypto_sign_keypair() for _ in range(n_nodes)]
    network = {}
    stake = {kp[0]: 1 for kp in kps}
    nodes = [Node(kp, network, n_nodes, stake) for kp in kps]
    for n in nodes:
        network[n.pk] = n.ask_sync
    mains = [n.main() for n in nodes]
    for m in mains:
        next(m)
    for i in range(n_turns):
        r = randrange(n_nodes)
        print('working node: %i, event number: %i' % (r, i))
        next(mains[r])
    return nodes
Ejemplo n.º 6
0
def main():
    np = neopixel.NeoPixel(machine.Pin(pin), rows * cols)
    clear(np)
    elapsed = 0

    while True:
        index = randrange(len(files))
        art = files[index]
        read_file_and_display(art, np, brightness)
        time.sleep(wait_time)
        elapsed += wait_time

        if elapsed >= reset_time:
            elapsed = 0
            clear(np)
Ejemplo n.º 7
0
 def animate(self):
     r = randrange(len(self.main_its))
     print('working node: %i, event number: %i' % (r, self.i))
     self.i += 1
     new = next(self.main_its[r])
     if r == self.active:
         tr, links = self.extract_data(self.nodes[r], new, len(self.tr_src.data['x']))
         self.tr_src.stream(tr)
         self.links_src.stream(links)
         for u, j in tuple(self.tbd.items()):
             self.tr_src.data['line_alpha'][j] = 1 if self.nodes[r].famous.get(u) else 0
             if u in self.nodes[r].idx:
                 self.tr_src.data['round_color'][j] = idx_color(self.nodes[r].idx[u])
             self.tr_src.data['idx'][j] = self.nodes[r].idx.get(u)
             if u in self.nodes[r].idx and u in self.nodes[r].famous:
                 del self.tbd[u]
                 print('updated')
         self.tr_src.trigger('data', None, self.tr_src.data)
Ejemplo n.º 8
0
 def animate(self):
     r = randrange(len(self.main_its))
     print('working node: %i, event number: %i' % (r, self.i))
     self.i += 1
     new = next(self.main_its[r])
     if r == self.active:
         tr, links = self.extract_data(self.nodes[r], new, len(self.tr_src.data['x']))
         self.tr_src.stream(tr)
         self.links_src.stream(links)
         for u, j in tuple(self.tbd.items()):
             self.tr_src.data['line_alpha'][j] = 1 if self.nodes[r].famous.get(u) else 0
             if u in self.nodes[r].idx:
                 self.tr_src.data['round_color'][j] = idx_color(self.nodes[r].idx[u])
             self.tr_src.data['idx'][j] = self.nodes[r].idx.get(u)
             if u in self.nodes[r].idx and u in self.nodes[r].famous:
                 del self.tbd[u]
                 print('updated')
         self.tr_src.trigger('data', None, self.tr_src.data)
Ejemplo n.º 9
0
def task(arg1, arg2):
    r = randrange(n_nodes)
    print('working node: %i, event number: %i' % (r, 0))
    next(mains[r])