Example #1
0
    def next_frame(self):
        while True:

            if self.started_at == 0.0:
                self.started_at = time.time()

            elapsed_time = time.time() - self.started_at

            current_ix = int(math.floor(elapsed_time / self.dwell_time) % len(sheep.ALL))

            self.clear();

            focus = sheep.ALL[current_ix]
            self.both.set_cell(focus, RGB(255,0,0))

            edges = sheep.edge_neighbors(focus)
            print "edges = %s" % str(edges)
            if edges != None:
                for p in edges:
                    self.both.set_cell(p, RGB(0,255,0))

            vertices = sheep.vertex_neighbors(focus)
            if vertices != None:
                for p in vertices:
                    self.both.set_cell(p, RGB(0,0,255))

            yield 0.001
Example #2
0
	def share_edge(self, cell, cells):
		if cell in cells:
			return True
		for c in cells:
			if cell in sheep.edge_neighbors(c):
				return True
		return False
Example #3
0
    def next_frame(self):
        """
        Draw the next step of the animation.  This is the main loop
        of the show.  Set some pixels and then 'yield' a number to
        indicate how long you'd like to wait before drawing the next
        frame.  Delay numbers are in seconds.
        """
        while True:
            # clear whatever was drawn last frame
            self.cells.clear()

            # choose a random panel on the sheep
            panel_id = random.choice(sheep.ALL)

            # set the chosen panel to the current color
            self.cells.set_cell(panel_id, self.color)

            # make the neighboring panels dimmer (80% brightness)
            # first find out all of the neighboring panels
            neighbors = sheep.edge_neighbors(panel_id)

            # make a copy of the color so it's safe to change
            dim_color = self.color.copy()
            dim_color.v = 0.8

            # then set multiple panels in one call
            self.cells.set_cells(neighbors, dim_color)

            # then wait to draw the next frame
            yield self.frame_delay
Example #4
0
    def next_frame(self):
        """
        Draw the next step of the animation.  This is the main loop
        of the show.  Set some pixels and then 'yield' a number to
        indicate how long you'd like to wait before drawing the next
        frame.  Delay numbers are in seconds.
        """
        while True:
            # clear whatever was drawn last frame
            self.cells.clear()

            # choose a random panel on the sheep
            panel_id = random.choice(sheep.ALL)

            # set the chosen panel to the current color
            self.cells.set_cell(panel_id, self.color)

            # make the neighboring panels dimmer (80% brightness)
            # first find out all of the neighboring panels
            neighbors = sheep.edge_neighbors(panel_id)

            # make a copy of the color so it's safe to change
            dim_color = self.color.copy()
            dim_color.v = 0.8

            # then set multiple panels in one call
            self.cells.set_cells(neighbors, dim_color)

            # then wait to draw the next frame
            yield self.frame_delay
Example #5
0
 def choose_head(self, curr_cell, prev_cell):
     i = 10  # Number of tries to find a new head
     while (i > 0):
         i -= 1
         neighbors = sheep.edge_neighbors(curr_cell)
         if len(neighbors) == 0:
             return prev_cell
         elif len(neighbors) == 1:
             return neighbors[0]
         else:
             new_head = choice(neighbors)
             if new_head != prev_cell and new_head <= 43 and new_head > 0:
                 return new_head
     return prev_cell
Example #6
0
	def choose_head(self, curr_cell, prev_cell):
		i = 10	# Number of tries to find a new head
		while (i > 0):
			neighbors = sheep.edge_neighbors(curr_cell)
			if len(neighbors) == 0:
				return prev_cell
			elif len(neighbors) == 1:
				return neighbors[0]
			else:
				new_head = choice(neighbors)
				if new_head != prev_cell and new_head <= 43 and new_head > 0:
					return new_head
			i -= 1
		return prev_cell
Example #7
0
    def next_frame(self):
        while True:
            for cellnum in sheep.ALL:
                self.sheep.clear()  # unnecessary for it to do a go here?

                col = self.color.copy()
                # set the primary panel to the base color
                self.sheep.set_cell(cellnum, col)

                # set edge neighbors to 80% brightness
                col.v = 0.8
                self.sheep.set_cells(sheep.edge_neighbors(cellnum), col)

                # set vertex neighbors to 20% brightness
                col.v = 0.2
                self.sheep.set_cells(sheep.vertex_neighbors(cellnum), col)

                yield self.speed
Example #8
0
    def next_frame(self):
        while True:
            for cellnum in sheep.ALL:
                self.sheep.clear()  # unnecessary for it to do a go here?

                col = self.color.copy()
                # set the primary panel to the base color
                self.sheep.set_cell(cellnum, col)

                # set edge neighbors to 80% brightness
                col.v = 0.8
                self.sheep.set_cells(sheep.edge_neighbors(cellnum), col)

                # set vertex neighbors to 20% brightness
                col.v = 0.2
                self.sheep.set_cells(sheep.vertex_neighbors(cellnum), col)

                yield self.speed
Example #9
0
    def next_frame(self):
        while True:

            color = self.color.copy()
            start = random.choice(sheep.ALL)

            for i in range(random.randint(3,5)):

                neighbors = sheep.edge_neighbors(start)
                if len(neighbors) > 2:
                    edges = random.sample(neighbors, 2)
                else:
                    edges = []

                self.clear()
                color.v = 1.0
                self.sheep.set_cell(start, color)
                color.v = 0.8
                self.sheep.set_cells(edges, color)
                yield self.speed

            self.clear()
            yield 1.0
Example #10
0
    def next_frame(self):
        while True:

            color = self.color.copy()
            start = random.choice(sheep.ALL)

            for i in range(random.randint(3, 5)):

                neighbors = sheep.edge_neighbors(start)
                if len(neighbors) > 2:
                    edges = random.sample(neighbors, 2)
                else:
                    edges = []

                self.clear()
                color.v = 1.0
                self.sheep.set_cell(start, color)
                color.v = 0.8
                self.sheep.set_cells(edges, color)
                yield self.speed

            self.clear()
            yield 1.0