def update(self,model): temp=model.find(lambda a:isinstance(a,Prey)) for i in temp: if self.distance(i.get_location())<=Hunter.eye: self.set_angle(atan2(i.get_location()[1]-self.get_location()[1],i.get_location()[0]-self.get_location()[0])) Pulsator.update(self,model) self.move()
def __init__(self, x, y): Pulsator.__init__(self, x, y) width, height = self.get_dimension() variable_one = 0 variable_two = 5 Mobile_Simulton.__init__(self, x, y, width, height, variable_one, variable_two) self.randomize_angle()
def __init__(self, x, y): Pulsator.__init__(self, x, y) width, height = self.get_dimension() self.speed = 5 self.angle = 0 Mobile_Simulton.__init__(self, x, y, width, height, self.angle, self.speed) self.randomize_angle()
def update(self): Pulsator.update(self) self.counter += 1 self._x = self.get_location()[0] self._y = self.get_location()[1] if self.counter == Special.Counter: self.set_location(self._x + (randrange(-75, 75)), self._y + (randrange(-75, 75))) self.counter = 0
def __init__(self, x, y): Pulsator.__init__(self, x, y) Mobile_Simulton.__init__(self, x, y, width=10 * 2, height=10 * 2, angle=random() * math.pi, speed=5)
def __init__(self, x, y): self.randomize_angle() Pulsator.__init__(self, x, y) Mobile_Simulton.__init__(self, x, y, width=Pulsator.radius, height=Pulsator.radius, angle=self._angle, speed=5)
def update(self, model): Pulsator.update(self, model) g = model.find(lambda x: isinstance(x, Prey)) for f in g: if self.distance(f.get_location()) <= self.dis: y = f.get_location()[1] - self.get_location()[1] x = f.get_location()[0] - self.get_location()[0] angle = atan2(y, x) self.set_angle(angle) self.move()
def __init__(self, x, y): Pulsator.__init__(self, x, y) Mobile_Simulton.__init__(self, x, y, width=20, height=20, angle=1, speed=5) Mobile_Simulton.randomize_angle(self)
def update(self): Pulsator.update(self) in_hunt_radius = model.find(lambda x: isinstance(x, Prey) and x. distance(self.get_location()) <= 200) if len(in_hunt_radius) > 0: closest = sorted(in_hunt_radius, key=lambda x: x.distance(self.get_location()))[0] self.set_angle( atan2(closest.get_location()[1] - self.get_location()[1], closest.get_location()[0] - self.get_location()[0])) self.move()
def update(self, model): matched = model.find(lambda s: isinstance(s,Simulton ) and type(s) is not Special and self.min_distance>=self.distance(s.get_location())) Pulsator.update(self, model) if matched: matched_min = [i for i in sorted(matched, key = lambda i: self.distance(i.get_location()))] new_x, new_y = matched_min[0].get_location() x, y = self.get_location() self.set_angle(atan2( new_y -y, new_x -x)) print('myangle', self.get_angle()) self.move() return matched
def update(self, eaten): x, y = self.get_location() hunting_set = model.find( lambda x: self.distance(x) <= Hunter.hunting_range) if hunting_set != set(): closest = min(hunting_set, key=lambda k: k.distance((x, y))) x1, y1 = closest.get_location() angle = atan2(y1 - y, x1 - x) self.set_angle(angle) Pulsator.update(self, eaten) self.move()
def update(self, model): target_simu = model.find( lambda x: isinstance(x, Prey) and self.distance(x.get_location( )) <= Hunter.search_distance) for target in target_simu: position_target = target.get_location() position_hunter = self.get_location() self.set_angle( atan2(position_target[1] - position_hunter[1], position_target[0] - position_hunter[0])) Pulsator.update(self, model) self.move()
def __init__(self, x, y): self.vision = 200 Pulsator.__init__(self, x, y) Mobile_Simulton.__init__(self, x, y, self._width, self._height, angle=0, speed=5) self.randomize_angle() self._color = 'brown'
def __init__(self, x, y): Pulsator.__init__(self, x, y) self.randomize_angle() w, h = self.get_dimension() Mobile_Simulton.__init__(self, x, y, width=w, height=h, angle=self.get_angle(), speed=5) self._distance_constant = 200
def update(self): closest = None Pulsator.update(self) s = model.find(lambda x: isinstance(x, Prey) and self.distance( (x._x, x._y)) < 200) minimum = 200 for p in s: if minimum > self.distance((p._x, p._y)): closest = p minimum = self.distance((p._x, p._y)) if closest != None: self._angle = atan2(closest._y - self._y, closest._x - self._x) self.move()
def update(self): Pulsator.update(self) a_set = model.find(lambda x: isinstance(x, Prey)) chase = None d = Hunter.dis for i in a_set: if self.distance(i.get_location()) <= d: d = self.distance(i.get_location()) chase = i.get_location() if chase != None: angle = atan2(chase[1] - self.get_location()[1], chase[0] - self.get_location()[0]) self.set_angle(angle) self.move()
def update(self, model): Pulsator.update(self, model) nearbyPrey = model.find(lambda x: isinstance(x, Prey) and self. distance((x.get_location())) <= 200) toSort = [] for prey in nearbyPrey: toSort.append((prey, self.distance((prey.get_location())))) if toSort != []: prey_to_chase = min(toSort, key=lambda x: x[1]) xp, yp = Prey.get_location(prey_to_chase[0]) xh, yh = self.get_location() diff_y = yp - yh diff_x = xp - xh self.set_angle(atan2(diff_y, diff_x)) Mobile_Simulton.move(self)
def update(self): self.move() Pulsator.update(self) current = 201 chase = 0 for b in (list(model.find(Ball))+list(model.find(Floater))): coord = (b._x, b._y) leng = hypot(coord[0]-self._x, coord[1]-self._y) if leng<Hunter.constant: if leng<current: current=leng chase = b if chase != 0: self._angle = atan2(chase._y-self._y, chase._x-self._x)
def update(self, model): closestd = Hunter.vision closest = None for p in model.find(lambda c: isinstance(c, Prey) and self.distance( (c._x, c._y)) <= Hunter.vision): if self.distance(p.get_location()) < closestd: closestd = self.distance(p.get_location()) closest = p if closest != None: px, py = closest.get_location() sx, sy = self.get_location() self.set_angle(atan2(py - sy, px - sx)) Pulsator.update(self, model) self.move()
def update(self, model): p = lambda sim: (isinstance(sim, Prey) and self.distance( sim.get_location()) <= 200) hunt = model.find(p) s_hunt = sorted(hunt.copy(), key=lambda x: self.distance(x.get_location())) if len(s_hunt) > 0: closest = s_hunt[0] cx, cy = closest.get_location() dif_x = cx - self._x dif_y = cy - self._y new_angle = atan2(dif_y, dif_x) self.set_angle(new_angle) Pulsator.update(self, model) self.move()
def update(self, model): self.move() self.wall_bounce() closest = None near = model.find(lambda s: isinstance(s, Prey) and Mobile_Simulton. distance(self, s.get_location()) <= Hunter.distance) if len(near) != 0: closest_distance = min( [Mobile_Simulton.distance(self, (n._x, n._y)) for n in near]) for simulton in near: if Mobile_Simulton.distance( self, (simulton._x, simulton._y)) == closest_distance: closest = simulton self._angle = atan2(closest._y - self._y, closest._x - self._x) Pulsator.update(self, model)
def update(self, model): Pulsator.update(self, model) self.move() self.wall_bounce() prey_nearby = False nearest_distance = Hunter.view_distance for item in model.find(Prey): dist = self.distance(item.get_location()) if dist < Hunter.view_distance and dist < nearest_distance: nearest = item nearest_distance = dist prey_nearby = True if prey_nearby: self._angle = atan2(-(self._y - nearest._y), -(self._x - nearest._x))
def mouse_click(x, y): if obj_kind == 'Remove': for obj in balls.copy(): left = obj.get_location()[0] - (obj.get_dimension()[0] / 2) right = obj.get_location()[0] + (obj.get_dimension()[0] / 2) up = obj.get_location()[1] + (obj.get_dimension()[1] / 2) down = obj.get_location()[1] - (obj.get_dimension()[1] / 2) if left <= x <= right: if down <= y <= up: balls.remove(obj) else: working_obj = eval(obj_kind) if obj_kind == 'Ball' or obj_kind == 'Floater' or obj_kind == 'Special': balls.add( working_obj(x, y, working_obj.radius, working_obj.radius, working_obj.speed, 0, working_obj.color)) elif obj_kind == 'Black_Hole': balls.add( working_obj(x, y, working_obj.radius, working_obj.radius, working_obj.color)) elif obj_kind == 'Pulsator': balls.add( Pulsator(x, y, working_obj.radius, working_obj.radius, working_obj.color)) elif obj_kind == 'Hunter': balls.add( working_obj(x, y, working_obj.radius, working_obj.radius, working_obj.speed, 0, working_obj.color))
def update(self): closest = None Pulsator.update(self) s = model.find(lambda x: isinstance (x,Prey) and self.distance((x._x, x._y) )< 200) minimum = 200 for p in s: if minimum > self.distance( (p._x, p._y)): closest = p minimum = self.distance( (p._x, p._y)) if closest != None: self._angle = atan2( closest._y - self._y, closest._x - self._x) self.move()
def mouse_click(x, y): global object if object == 'Ball': balls.add(Ball(x, y, random_angle())) elif object == "Floater": balls.add(Floater(x, y, random_angle())) elif object == "Black_Hole": simu.add(Black_Hole(x, y)) elif object == "Pulsator": simu.add(Pulsator(x, y)) elif object == "Remove": g = balls h = set() k = set() for f in g: if f.contains((x, y)): h.add(f) for s in simu: if s.contains((x, y)): k.add(s) for l in h: remove(l) for b in k: simu.remove(b) pass elif object == "Hunter": simu.add(Hunter(x, y, random_angle()))
def update(self, model): Pulsator.update(self, model) self.move() # finding prey all_prey = model.find(lambda x: isinstance(x, Prey)) close_prey = [] for prey in all_prey: position = prey.get_location() if self.distance(position) < self.in_distance: close_prey.append((self.distance(position), prey)) if len(close_prey) != 0: prey_object = sorted(close_prey, key = lambda x: x[0])[0][1] px, py = prey_object.get_location() hx, hy = self.get_location() new_angle = atan2(py - hy, px - hx) self.set_angle(new_angle)
def update(self): Pulsator.update(self) self.move() self.wall_bounce() def p(arg): return isinstance( arg, Prey) and self.distance(arg.get_location()) <= 200 eatable = model.find(p) if len(eatable) != 0: nearest = list(eatable)[0].get_location() for i in eatable: if self.distance(i.get_location()) < self.distance(nearest): nearest = i.get_location() self.set_angle(atan2(nearest[1] - self._y, nearest[0] - self._x))
def update(self, model): self.move() result = dict() for item in model.find(lambda x: isinstance(x, Prey)): if Mobile_Simulton.distance(self, (item._x, item._y)) < Hunter.distance: result[Mobile_Simulton.distance(self, item.get_location())] = item if result != dict(): m = min(result) min_location = result[m].get_location() hunter_location = self.get_location() new_x_angle = min_location[0] - hunter_location[0] new_y_angle = min_location[1] - hunter_location[1] Mobile_Simulton.set_angle(self, atan2(new_y_angle, new_x_angle)) Pulsator.update(self, model)
def __init__(self, x, y, width, height, speed, angle, color): Pulsator.__init__(self, x, y, width, height, color) Mobile_Simulton.__init__(self, x, y, width, height, angle, speed) self._x = x self._y = y self._width = width * 2 self._height = height * 2 self._speed = speed self._angle = angle self._color = color self._close_items = [] self._smallest = 0 self.obj_eaten = set() self.randomize_angle()
def update(self): Pulsator.update(self) temp = model.find(self.hunt_contains_obj) closest = None ticker = None for i in temp: if ticker == None: ticker = self.distance(i.get_location()) closest = i else: if self.distance(i.get_location()) < ticker: ticker = self.distance(i.get_location()) closest = i if closest != None: self._angle = atan2((closest.get_location()[1] - self._y), (closest.get_location()[0] - self._x)) self.move()
def update(self,balls): self.move() alist = self.return_alist(balls) if 0 < len(alist): self.return_diff(alist) return Pulsator.update(self,balls)
def update(self, model): def seek(xy): return self.distance(xy) <= Hunter.range target = model.find(seek) if len(target) != 0: closest = min( [self.distance(mark.get_location()) for mark in target]) for mark in target: if closest == self.distance(mark.get_location()): lock = mark trail = atan2(lock._y - self._y, lock._x - self._x) self.set_angle(trail) self.move() Pulsator.update(self, model) ate = model.find(self.contains) if self.get_dimension() == (0, 0): ate.add(self) return ate
def update(self, model): Pulsator.update(self, model) Mobile_Simulton.move(self) prey_set = model.find(lambda x: isinstance(x, Prey)) can_see = set() for prey in prey_set: distance = ((self._x - prey._x)**2 + (self._y - prey._y)**2)**0.5 if distance < self.vision: can_see.add(prey) nearby = [] for prey in can_see: distance = ((self._x - prey._x)**2 + (self._y - prey._y)**2)**0.5 nearby.append((prey, distance)) if len(nearby) > 0: closest = sorted(nearby, key=lambda x: x[1])[0] self.set_angle( atan2((closest[0]._y - self._y), (closest[0]._x - self._x)))
def update(self,model): chase=set(a for a in model.simuls if isinstance(a,Prey)) want=set() try: for item in chase: if self.distance(item.get_location())<=Hunter.dist: want.add(item) if len(want)==0: self.move() else: fez=min(want,key=lambda prey_on: self.distance(prey_on.get_location())) dif_y=fez.get_location()[1]-self.get_location()[1] dif_x=fez.get_location()[0]-self.get_location()[0] self.set_angle(atan2(dif_y,dif_x)) Pulsator.update(self,model) self.move() except RuntimeError: pass
def update(self,model): eaten = Pulsator.update(self,model) seen = model.find(lambda x : isinstance(x,Prey) and self.distance(x.get_location()) <= Hunter.see_distance) if seen: min_dist,who = min([(self.distance(s.get_location()),s) for s in seen]) sx,sy = self.get_location() x,y = who.get_location() self.set_angle(atan2(y-sy,x-sx)) self.move() return eaten
def update(self): eat = Pulsator.update(self) Mobile_Simulton.update(self) aim = model.find(lambda x: isinstance(x, Prey) and self.visible_distance(x.get_location())) if aim: first_target = min([s.get_location() for s in aim], key = lambda x: self.distance(x)) x,y = first_target self.set_angle(self.angle_to(x,y)) return eat
def __init__(self,x,y): Pulsator.__init__(self,x,y) w,h = self.get_dimension() Mobile_Simulton.__init__(self,x,y,w,h,0,5) self.randomize_angle()
def __init__(self,x,y): Pulsator.__init__(self, x, y) Mobile_Simulton.__init__(self, x, y, self._width, self._height, 0, 5) self.randomize_angle()
def __init__(self, x, y): Pulsator.__init__(self,x,y) Mobile_Simulton.__init__(self,x,y, width = 10 * 2, height = 10 * 2, angle = random()* math.pi ,speed = 5)
def __init__(self, x, y): Pulsator.__init__(self, x, y) Mobile_Simulton.__init__(self, x, y, 20, 20, 0, 5) self.randomize_angle()
def __init__(self, x, y): Mobile_Simulton.__init__(self, x, y, self.radius*2, self.radius*2, 1, 5) Pulsator.__init__(self, x, y) self.randomize_angle()
def __init__(self, x, y): Pulsator.__init__(self, x, y) self.counter = 0
def __init__(self,x,y,size = 20): Pulsator.__init__(self,x,y) Mobile_Simulton.__init__(self, x, y, self.radius, self.radius, random.random()*math.pi*2,5) self.set_dimension(size, size) self._image = PhotoImage(Image.open('deathstar.gif').convert('RGBA').resize((size, size), Image.ANTIALIAS)) self.radius = (self._image.height()/2)+((self._image.width()**2)/(8 * self._image.height()))