예제 #1
0
파일: soccer.py 프로젝트: dmaccarthy/sc8pr
 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
예제 #2
0
파일: soccer.py 프로젝트: swipswaps/sc8pr
 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
예제 #3
0
파일: robot.py 프로젝트: dmaccarthy/sc8pr
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
예제 #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
예제 #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)
예제 #6
0
파일: shape.py 프로젝트: dmaccarthy/sc8pr
 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)]
예제 #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)
예제 #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
예제 #9
0
파일: shape.py 프로젝트: dmaccarthy/sc8pr
 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