Ejemplo n.º 1
0
 def process(self):
     self.to_apply = {act: [Behavior([0])] for act in self.device.actuators}
     pos = self.device.position
     node_under = next((nd for nd in self.view.network.nodes
                        if State.which(nd.distance_to(pos)) == State.on),
                       None)
     if node_under:
         for lk in self.view.network.links:
             if State.which(lk.distance_to(pos)) == State.on:
                 [act] = self.device.actuators_for(lk)
                 self.to_apply[act].append(Behavior([99]))
     elif len(self.view.network.links) > 0:
         cl = None  # closest link
         for lk in self.view.network.links:
             if lk.closer_than(cl, pos):
                 cl = lk
         if State.which(cl.distance_to(pos)) == State.on:
             for act in self.device.actuators_for(cl):
                 self.to_apply[act].append(
                     Behavior(Behavior.gen_oscillation(0, 90, 10)))
         elif State.which(cl.distance_to(pos)) == State.hot:
             self.to_apply[self.device.actuator_to(cl)].append(
                 Behavior(Behavior.gen_oscillation(0, 20, 10)))
         else:
             self.to_apply[self.device.actuator_to(cl)].append(
                 Behavior([20]))
     super().apply()
Ejemplo n.º 2
0
 def what_under(self, pos):
     node_under = next((nd for nd in self.nodes if State.which(
         nd.distance_to(pos)) == State.on), None)
     if node_under:
         return node_under
     link_under = next((lk for lk in self.links if State.which(
         lk.distance_to(pos)) == State.on), None)
     return link_under
Ejemplo n.º 3
0
 def what_under(self, pos):
     node_under = next((nd for nd in self.nodes
                        if State.which(nd.distance_to(pos)) == State.on),
                       None)
     if node_under:
         return node_under
     link_under = next((lk for lk in self.links
                        if State.which(lk.distance_to(pos)) == State.on),
                       None)
     return link_under