Exemplo n.º 1
0
 def collideRobot(self, pos):
     sk = self.sketch
     r = self.radius
     for s in sk.sprites():
         if isinstance(s, SoccerRobot) and dist(s.pos, pos) < r + s.radius:
             return True
     return False
Exemplo n.º 2
0
 def collideRobot(self, pos):
     sk = self.sketch
     r = self.radius
     for s in sk.sprites():
         if isinstance(s, SoccerRobot) and dist(s.pos, pos) < r + s.radius:
             return True
     return False
Exemplo n.º 3
0
def _distToWall(pos, angle, sWidth, w, h):
    "Calculate the distance to the sketch walls in the specified direction"
    walls = Polygon([(0,0), (w,0), (w,h), (0,h)])
    w += h
    pts = []
    for n in (-1, 0, 1):
        v = vec2d(w, angle + n * sWidth)
        line = Line(pos, vector=v)
        pts.extend(walls.intersect(line))
    return min(dist(pos, pt) for pt in pts) if len(pts) else None
Exemplo n.º 4
0
def _distToWall(pos, angle, sWidth, w, h):
    "Calculate the distance to the sketch walls in the specified direction"
    walls = Polygon([(0, 0), (w, 0), (w, h), (0, h)])
    w += h
    pts = []
    for n in (-1, 0, 1):
        v = vec2d(w, angle + n * sWidth)
        line = Line(pos, vector=v)
        pts.extend(walls.intersect(line))
    return min(dist(pos, pt) for pt in pts) if len(pts) else None
Exemplo n.º 5
0
	def setup(self):
		RobotThread.log = False
		self.config(bg="white", border="blue", weight=1)
		for name in self.names:
			self[name] = PartyRobot(self)
		RobotThread.log = True
		robo = Robot(["#ff5050", "#ffd428"])
		self["Red"] = self.bindBrain(robo).config(width=2*RADIUS,
			pos=self.center, mass=1, bounce=BOTH, greet=None)
		for r in self:
			while min(dist(r.pos, s.pos) for s in self if s is not r) < 2 * r.radius:
				r.pos = r.randPos(self)
		self.cd = Collisions(self)
Exemplo n.º 6
0
 def intersect(self, other):
     "Find the intersection(s) of two circles as list of points"
     R = self.radius
     r = other.radius
     d = dist(self.pos, other.pos)
     if d > r + R or d == 0 or d < abs(r - R): return []
     r2 = r * r
     x = (d*d + r2 - R*R) / (2*d)
     ux, uy = delta(self.pos, other.pos, 1)
     x0, y0 = other.pos
     x0 += x * ux
     y0 += x * uy
     if x < r:
         y = sqrt(r2 - x*x)
         return [(x0 - y * uy, y0 + y * ux), (x0 + y * uy, y0 - y * ux)]
     else: return [(x0, y0)]
Exemplo n.º 7
0
 def setup(self):
     RobotThread.log = False
     self.config(bg="white", border="blue", weight=1)
     for name in self.names:
         self[name] = PartyRobot(self)
     RobotThread.log = True
     robo = Robot(["#ff5050", "#ffd428"])
     self["Red"] = self.bindBrain(robo).config(width=2 * RADIUS,
                                               pos=self.center,
                                               mass=1,
                                               bounce=BOTH,
                                               greet=None)
     for r in self:
         while min(dist(r.pos, s.pos)
                   for s in self if s is not r) < 2 * r.radius:
             r.pos = r.randPos(self)
     self.cd = Collisions(self)
Exemplo n.º 8
0
 def containsPoint(self, pos):
     "Determine if the point is within the circle; do not account for canvas offset"
     return dist(self.pos, pos) < self.radius
Exemplo n.º 9
0
 def containsPoint(self, pos):
     "Determine if the point is within the circle; do not account for canvas offset"
     return dist(self.pos, pos) < self.radius