Beispiel #1
0
def read_vertices(filename, ):
	""" spara resultatet av liknande fråga som denna som csv. X;Y;Z  ingen header
select x,y, id /*, sdo_geom.validate_geometry_with_context(y.shape, 0.0005), t1.* */  from  setfast.fastomry y 
    , TABLE(sdo_util.getvertices(
        sdo_util.extract(y.shape,1,1)
       )) t1
where y.objectid = 34486581
"""
	points = []
	f = open(filename, 'r')
	for row in f.readlines():
		if( row[0] == '\n' ):
			break
		cols = row.split(';')
		cols = map(lambda x: float(str.replace(x, ',', '.')), cols)
		print cols
		p = Point(cols[0], cols[1])
		p.id = cols[2]
		points.append(p)

	segments = []
	for p1,p2 in zip(points[:-1], points[1:]):
		l = Line(p1,p2)
		segments.append(l)
		

	return segments
Beispiel #2
0
 def isBallInFrontOfRobot(robotState,ball,param_x = .5, param_y = .04, behind_x = 0):
     refPoint = Point(ball.x-robotState.x,ball.y - robotState.y)
     if refPoint.x < 0:
       if abs(refPoint.x) < behind_x:
         print "behind ball %.2f m but still rushing" %(abs(refPoint.x))
         refPoint.x = -refPoint.x
       else:
         print "ball is too far behind, stopping rush"
         return False
     #print "refence from robot: %f, %f" % (refPoint.x,refPoint.y)
     #print "angle: %f" % robotState.theta
     rotatedPoint = MotionSkills.rotatePointByAngle(refPoint, robotState.theta)
     #print "rotatedPoint to robot frame: %f, %f" % (rotatedPoint.x,rotatedPoint.y)
     angleToGoal = MotionSkills.angleBetweenPoints(robotState, HOME_GOAL)
     angleDiff = abs(angleToGoal-robotState.theta)
     if angleDiff > math.pi:
         angleDiff = (2*math.pi - angleDiff)
     #print 'angle difference: %d' %((angleDiff/math.pi)*180)
     
     if rotatedPoint.x > 0 and rotatedPoint.x < param_x and rotatedPoint.y < param_y and rotatedPoint.y > -param_y:
         
         #print "Behind Ball!"
         if angleDiff < 0.15:
             #print "Angled toward Goal"
             return True
         print "Not angled to goal!"
         return False
     print "Not Behind Ball!"
     return False
Beispiel #3
0
    def getVelocity(self, at):
        #Get the location of the sphero
        spheroPoint = Point(at.x, at.y)
        #Get the vector towards the goal.
        
        #path should be set by set by the pathfinder?
        if spheroPoint.distanceTo(self.path[self.current]) < SIZE_OF_GRID:
            if self.current >= len(self.path) - 1:
                self.current = 0
            else:
                self.current += 1
        dest = self.path[self.current]

        x = y = 0
        up = Point(dest.x, dest.y - 1)
        left = Point(dest.x - 1, dest.y)
        down = Point(dest.x, dest.y + 1)
        right = Point(dest.x + 1, dest.y)
        poly = [up, left, down, right]
        wayPoint = AttractiveField(-1, 80, 1, poly)
        tmpPoint = wayPoint.getVect(spheroPoint).getPoint()
        x += tmpPoint.x
        y += tmpPoint.y

        #print "fields: " + str(self.fields)
        for field in self.fields:
            if type(field) is AttractiveField and field.inCircle(spheroPoint):
                return Point(0, 0)
            tmpPoint = field.getVect(spheroPoint).getPoint()
            print "vector" + str(field.id) + "=" + str(tmpPoint)
            x += tmpPoint.x
            y += tmpPoint.y
        point = Point(x, y)
        #print "velocity= " + str(point)
        return point
Beispiel #4
0
    def do_parse_vessel_file(self):
        # print "ok"
        start = time.time()
        with open(self.filePath, "r+b") as f:
            # memory-mapInput the file, size 0 means whole file
            map_input = mmap.mmap(f.fileno(), 0)

            # read content via standard file methods
            for s in iter(map_input.readline, ""):
                s = s.translate(None, "\r\n")
                # print s
                a_line_of_values = s.split(" ")
                # print a_line_of_values

                point = Point()
                if len(a_line_of_values) == 5:
                    point.set_reference_point(float(a_line_of_values[0]), float(a_line_of_values[1]),
                                              float(a_line_of_values[2]), float(a_line_of_values[3]),
                                              float(a_line_of_values[4]))
                    # print point.get_x()
                elif len(a_line_of_values) == 3:
                    point.set_centerline_point(float(a_line_of_values[0]), float(a_line_of_values[1]),
                                               float(a_line_of_values[2]))
                    # print point.get_x()
                self.vesselValues.append(point)

            map_input.close()
            end = time.time()
            print "Time for completion", end - start
 def testDistanceTo(self):
     p = Point(3,4)
     q = Point(4,5)
     
     self.assertEquals(p.distanceTo(q), q.distanceTo(p))
     self.assertEquals(p.distanceTo(q), math.sqrt(2))
     self.assertEquals(p.distanceTo(self.p0), 5.0)
Beispiel #6
0
 def center(points):
 	center_point = Point(0,0,0)
 	for point in points:
 		center_point.x += point.x
 		center_point.y += point.y
 	center_point.x = center_point.x/float(len(points))
 	center_point.y = center_point.y/float(len(points))	
     return center_point
    def test_get_distance(self):
        l = LaserMote()
        p = Point()
        p.last_seen_x = 20
        p.last_seen_y = 20
        l.point = p

        self.assertAlmostEqual(28.2842712, l.get_distance(40, 40), places=7, msg="get_distance failed test.",
                               delta=None)
Beispiel #8
0
	def position_at(self, time):
		dt = time - self.src_time

		if dt > 0.0 and self.total_time > 0.0:
			ratio = dt / self.total_time 
			p = Point()
			p.x = self.src.x + self.dx * ratio
			p.y = self.src.y + self.dy * ratio
			return p
		else:
			return self.src
Beispiel #9
0
 def __init__(self, name, mass, charge, x, y, velx, vely, accx, accy, fixed):
     Point.__init__(self, x, y)
     self.name = name
     self.mass = mass
     self.charge = charge
     self.velx = velx
     self.vely = vely
     self.accx = accx
     self.accy = accy
     self.rigid = fixed
     self.ForceList = []
     self.OverrideE = None
     self.OverrideG = None
Beispiel #10
0
    def isIntersected(line1, line2):
        vector1 = Point.getVector(line2.startPoint, line1.startPoint)
        vector2 = Point.getVector(line2.startPoint, line1.endPoint)
        vector3 = Point.getVector(line2.startPoint, line2.endPoint)
        if Point.crossProduct(vector1, vector3) * Point.crossProduct(vector2, vector3) > 0:
            return False

        vector1 = Point.getVector(line1.startPoint, line2.startPoint)
        vector2 = Point.getVector(line1.startPoint, line2.endPoint)
        vector3 = Point.getVector(line1.startPoint, line1.endPoint)
        if Point.crossProduct(vector1, vector3) * Point.crossProduct(vector2, vector3) > 0:
            return False

        return True
Beispiel #11
0
 def pointOrder(self, G):
     factors = ECMath.allFactors(self.order())
     a = self.getA()
     b = self.getB()
     p = self.getP()
     temp = Point()
     infinity = Point()
     multiple = 0
     for l in factors:
         temp = temp.add(G.mult(l-multiple, a, b, p), a, b, p)
         multiple = l
         if temp == infinity:
             return l
     return -1 # error
    def cloneLinkedList(self):
        cursor = self.HEAD
        
        # make a copy of the head first:
        newHead = Point(cursor.x, cursor.y)
        newHead.ear = cursor.ear
        newHead.name = cursor.name
        
        # use a loop to create clones of the rest of the points:
        cursor = cursor.next
        newCursor = newHead
        while cursor is not self.HEAD:
            newPoint = Point(cursor.x, cursor.y)
            newPoint.ear = cursor.ear
            newPoint.name = cursor.name
            
            # link the previous point to the new one:
            newCursor.next = newPoint
            newPoint.prev = newCursor
            
            cursor = cursor.next
            newCursor = newPoint           # same as: newCursor = newCursor.next

        # finally, link the new head and tail before returning the head:
        newHead.prev = newCursor
        newCursor.next = newHead
        return newHead, self.SIZE
Beispiel #13
0
class Avoider(Enemy):
    def __init__(self, scene, x, y):
        super().__init__(scene, x, y)
        self._velocity = Point(0, 0)
        self.set_shape(sh.STAR_SHAPE, Colors.avoid, True, 5)

    def update(self):
        player = self._scene.player
        vec_to_player = player.position - self.position
        dir_to_player = math.atan2(vec_to_player.y, vec_to_player.x)

        angle = self._angle_distance(player.direction, dir_to_player)
        if angle < math.pi/2:
            dirvec = vec_to_player
            speed = ACCELERATION
        else:
            avoid_point = Point(1, 1)
            avoid_count = 0

            for obj in self.scene.objects:
                if isinstance(obj, pl.Bullet):
                    distance = (obj.position - self.position).length_sqr()
                    if distance <= DISTANCE_SQR:
                        avoid_point += obj.position
                        avoid_count += 1

            if avoid_count > 0:
                avoid_point /= avoid_count
                dirvec = self.position - avoid_point
                speed = DODGE
            else:
                dirvec = vec_to_player
                speed = ACCELERATION

        self._velocity += dirvec * speed / dirvec.length()

        if self._velocity.length_sqr() > SPEED_SQR:
            self._velocity.normalize()
            self._velocity *= SPEED

        self.position += self._velocity
        self.direction += ANGULAR_SPEED
        super().update()

    def _angle_distance(self, alpha, beta):
        phi = abs(beta - alpha) % 360
        distance = 360 - phi if phi > 180 else phi
        return distance
Beispiel #14
0
 def __init__(self, origin, edge_length, dataset):
     self._origin = Point(origin)
     self._edge_length = edge_length
     self._dataset = dataset
     self._set_voxel_datapoints()
     self._set_voxel_dataedges()
     self._dc_vertices = []
Beispiel #15
0
 def __init__(self, scene, x, y, n=2):
     super().__init__(scene, x, y)
     self._velocity = Point(0, 0)
     self._size = n
     myscale = SCALE - n*2
     self.set_shape(sh.BRICK_SHAPE[n], Colors.split, True, myscale)
     self._sleep = SLEEP_TIME if n < 2 else 0
Beispiel #16
0
 def __init__(self, scene, x, y, direction):
     super().__init__(scene)
     self.position = Point(x, y)
     self.set_shape(sh.BULLET_SHAPE, Colors.bullet, True, 5)
     self.direction = direction
     self._velocity = Point.anglelen(direction, BULLET_SPEED)
     self._clamp_inside = False
Beispiel #17
0
    def onMouseClic(self, event):
        items = self.cv.find_withtag("current")
        self.ClicGauche_depart = Point(event.x, event.y)

        if len(items):
            print("selection forme")

            self.idForme = items[0]
            self.forme_active = self.map[self.idForme]

            # dessiner le contour de selection

            print("MAP: " + self.map.__str__())
            print("ID: " + self.idForme.__str__())

            print("NOM: " + self.forme_active._get_nom())
            self.majEntry()
        else:
            try:
                print("dessinDown")
                if self.PeutDessiner:
                    # id de la forme sur le canvas
                    self.forme_active.maj(Point(event.x, event.y), Point(event.x, event.y))
                    self.forme_active.write()
                    self.idForme = self.fabrique.fabriquer_forme(self.forme_active, self.cv)
                    self.map[self.idForme] = self.forme_active
                else:
                    # Deselection de tout
                    self.GroupeActif = -1
                self.majEntry()
            except:
                pass  # ne rien faire quand aucune action est selectionnee (clic dans le vide)
Beispiel #18
0
 def zoom(self, action, coef):
     super().zoom()
     if(action):
         #Modif des points
         AModifX = round( ((self._get_largeur() * coef) - self._get_largeur()) / 2 , 0)
         AModifY = round( ((self._get_hauteur() * coef) - self._get_hauteur()) / 2 , 0 )
         
         self._point1 = Point(self._point1._get_x() - AModifX, self._point1._get_y() - AModifY)
         self._point2 = Point(self._point2._get_x() + AModifX, self._point2._get_y() + AModifY)
     else:
         #Modif des points
         AModifX = round( ((self._get_largeur() / coef) - self._get_largeur()) / 2 , 0)
         AModifY = round( ((self._get_hauteur() / coef) - self._get_hauteur()) / 2 , 0 )
         
         self._point1 = Point(self._point1._get_x() - AModifX, self._point1._get_y() - AModifY)
         self._point2 = Point(self._point2._get_x() + AModifX, self._point2._get_y() + AModifY)
Beispiel #19
0
class Walker:
	"""
	A walker
	"""
	def __init__(self):
		pass

	def initialise(self):
		self.point = Point()
		self.point.from_prior()
		self.num_scalars = len(self.point.scalars)

		# Assign a direction for the walker to travel in
		self.direction = -np.log(rng.rand(self.num_scalars))
		self.direction /= self.direction.sum()

		# Give a hard edge to the distribution
		self.edge = -np.Inf*np.ones(self.num_scalars)

		# Keep track of which choices were made
		self.choices = []
		self.keep = []

	def advance(self, steps=1000):
		self.keep.append(self.point.scalars)

		choice = rng.choice(np.arange(0, self.num_scalars),\
				p=self.direction)
		self.choices.append(choice)
		self.edge[choice] = self.point.scalars[choice]

		accept = 0
		for i in xrange(0, steps):
			proposal = copy.deepcopy(self.point)
			logH = proposal.perturb()
			if logH > 0.:
				logH = 0.
			if np.all(proposal.scalars >= self.edge) \
				and rng.rand() <= np.exp(logH):
				self.point = proposal
				accept += 1
		print('Accepted {a}/{b}. Scalars={s}'\
			.format(a=accept, b=steps, s=self.point.scalars))

		if accept <= 0.05*steps:
			return False
		return True
Beispiel #20
0
	def __init__(self):
		self.src        = Point()
		self.dest       = Point()
		self.src_time   = 0.0
		self.speed      = 0.0
		self.distance   = 0.0
		self.total_time = 0.0
		self.dx         = 0.0
		self.dy         = 0.0
Beispiel #21
0
	def calcDirection(self):
		del self.direction[:]
		n = len(self.points)
		for i in range(0,n-1):
			a,b = self.points[i].getCoords()
			c,d = self.points[i+1].getCoords()

			dx = c - a
			dy = d - b

			d = Point(dx, dy)

			if d.length() < 0.001:
				d = Point(0, 0)
			else:
				d.normalize()

			self.direction.append(d)
Beispiel #22
0
class Brick(Enemy):
    def __init__(self, scene, x, y, n=2):
        super().__init__(scene, x, y)
        self._velocity = Point(0, 0)
        self._size = n
        myscale = SCALE - n*2
        self.set_shape(sh.BRICK_SHAPE[n], Colors.split, True, myscale)
        self._sleep = SLEEP_TIME if n < 2 else 0

    def destroy(self):
        if self._size > 0:
            s = SCALE
            off = self._size*s
            n = self._size - 1
            for x in range(0, 2):
                for y in range(0, 2):
                    celloffset = Point(off + x*s, off + y*s)
                    cellpos = self.position + celloffset
                    child = Brick(self._scene, cellpos.x, cellpos.y, n)
                    child._velocity = (cellpos - self.position)*2
                    self._scene.add_object(child)

        super().destroy()

    def update(self):
        if self._sleep <= 0:
            player = self._scene.player
            dirvec = player.position - self.position
            self._velocity += dirvec * ACCELERATION / dirvec.length()
        else:
            self._sleep -= 1

        if self._velocity.length_sqr() > SPEED:
                self._velocity.normalize()
                self._velocity *= SPEED

        self.position += self._velocity
        self.direction += self._velocity.length()*ANGULAR_SPEED
        super().update()
Beispiel #23
0
    def update(self):
        angl = random.uniform(0, math.pi*2)
        self._velocity += Point.anglelen(angl, ACCELERATION)
        self._velocity *= SPEED / self._velocity.length()
        self.position += self._velocity
        self.direction += ANGULAR_SPEED

        w = self.scene_manager.window_size()
        if self.position.x < 0 or self.position.x > w[0]:
            self._velocity.x *= -1
        if self.position.y < 0 or self.position.y > w[1]:
            self._velocity.y *= -1

        super().update()
Beispiel #24
0
 def setFromQTransform(self, tr):
     p1 = Point(tr.map(0., 0.))
     p2 = Point(tr.map(1., 0.))
     p3 = Point(tr.map(0., 1.))
     
     dp2 = Point(p2-p1)
     dp3 = Point(p3-p1)
     
     ## detect flipped axes
     if dp2.angle(dp3) > 0:
         #da = 180
         da = 0
         sy = -1.0
     else:
         da = 0
         sy = 1.0
         
     self._state = {
         'pos': Point(p1),
         'scale': Point(dp2.length(), dp3.length() * sy),
         'angle': (np.arctan2(dp2[1], dp2[0]) * 180. / np.pi) + da
     }
     self.update()
Beispiel #25
0
class PointMass:
    def __init__(self, x,  y, inverse_mass):
        self.inverse_mass = inverse_mass
        self.position = Point(x, y)
        self.velocity = Point(0, 0)
        self.acceleration = Point(0, 0)
        self.damping = MASS_DAMPING

    def apply(self, force):
        self.acceleration += force * self.inverse_mass

    def update(self):
        if (self.acceleration.length_sqr() == 0 and
            self.velocity.length_sqr() == 0):
            return

        self.velocity += self.acceleration
        self.position += self.velocity
        self.acceleration.coords = (0, 0)
        if (self.velocity.length_sqr() < sys.float_info.epsilon):
            self.velocity.coords = (0, 0)

        self.velocity *= self.damping
        self.damping = self.damping
Beispiel #26
0
	def initialise(self):
		self.point = Point()
		self.point.from_prior()
		self.num_scalars = len(self.point.scalars)

		# Assign a direction for the walker to travel in
		self.direction = -np.log(rng.rand(self.num_scalars))
		self.direction /= self.direction.sum()

		# Give a hard edge to the distribution
		self.edge = -np.Inf*np.ones(self.num_scalars)

		# Keep track of which choices were made
		self.choices = []
		self.keep = []
def main():
    # Use this to test the constructor
    
    p1 = Point()

    # Use these to test the getters
    
    print ("Default p1 x =", p1.getX())
    print ("Default p1 y =", p1.getY())

    # Use these to test the setters
    
    p1.setX(1)
    p1.setY(2)
    print ()
    print ("Modified p1 x =", p1.getX())
    print ("Modified p1 y =", p1.getY())

    # Use this to test the __str__
    
    print ()
    print ("Modified Point p1 =", p1)
Beispiel #28
0
	def calcMotionEnergy(self):
		n = len(self.points)
		l = 3
		speed = []
		for i in range(0,n-l-1):
			a,b = self.points[i].getCoords()
			dx = dy = 0
			for j in range(l):
				index = i+j+1
				c,d = self.points[i+l+1].getCoords()

				dx = dx + c - a
				dy = dy + d - b

			dx = dx/l
			dy = dy/l

			d = Point(dx, dy)
			speed.append(d)

		n = len(speed)

		if n == 0:
			return 0
			
		e = Point(0, 0)
		mx = my = 0
		for i in range(0,n):
			a,b = speed[i].getCoords()
			mx = mx + a
			my = my + b

		mx = mx/n
		my = my/n

		for i in range(0,n):
			a,b = speed[i].getCoords()

			dx = mx - a
			dy = my - b

			dx2 = dx*dx
			dy2 = dy*dy

			e.x = e.x + dx2
			e.y = e.y + dy2

		print(str(n-1))
		e.x = e.x/(n-1)
		e.y = e.y/(n-1)

		return e.length()
Beispiel #29
0
class Particle:
    def __init__(self, x=0.0, y=0.0, w=1.0):
        self.location = Point(x,y)
        self.weight = w

    def getLocation(self):
        return str(self.location.getX())+','+str(self.location.getY())

    def getWeight(self):
        return self.weight

    def setLocation(self,x,y):
        self.location.setX(x)
        self.location.setY(y)

    def setWeight(self, w):
        self.weight = w
Beispiel #30
0
class NodeMovement:
	def __init__(self):
		self.src        = Point()
		self.dest       = Point()
		self.src_time   = 0.0
		self.speed      = 0.0
		self.distance   = 0.0
		self.total_time = 0.0
		self.dx         = 0.0
		self.dy         = 0.0

	def load_trace(self, trace):
		l = trace.split()
		self.src_time   = float(l[1])
		self.src.x      = float(l[3][1:-1])
		self.src.y      = float(l[4][:-1])
		self.src.z      = float(l[5][:-2])
		self.dest.x     = float(l[6][1:-1])
		self.dest.y     = float(l[7][:-2])
		self.speed      = float(l[8])

		self.distance   = self.src.distance_to(self.dest)
		self.total_time = self.distance / self.speed
		self.dx         = self.dest.x - self.src.x
		self.dy         = self.dest.y - self.src.y

	def position_at(self, time):
		dt = time - self.src_time

		if dt > 0.0 and self.total_time > 0.0:
			ratio = dt / self.total_time 
			p = Point()
			p.x = self.src.x + self.dx * ratio
			p.y = self.src.y + self.dy * ratio
			return p
		else:
			return self.src
Beispiel #31
0
def main_lab2():
    # p = generate_simple_polygon(100, 700)
    # p0 = generate_random_point(100, 700)

    # p = [Point(200, 400), Point(400, 200), Point(600, 400), Point(400, 600)]
    # p0 = Point(300, 400)

    p = [Point(100, 200), Point(200, 200), Point(400, 100), Point(300, 400)]
    p0 = Point(400, 400)

    q = Point(dimensionalTest(p, p0) - 1, p0.y)

    print("angle test")
    if ray_test(p, p0):
        print("In polygon")
    else:
        print("Not in polygon")

    draw_lab2(p, p0, q)
Beispiel #32
0
def PointRotate3D(p1, p2, p0, theta):
    from Point import Point
    from math import cos, sin, sqrt

    # Translate so axis is at origin
    p = p0 - p1
    # Initialize point q
    q = Point(0.0, 0.0, 0.0)
    N = (p2 - p1)
    Nm = sqrt(N.x**2 + N.y**2 + N.z**2)

    # Rotation axis unit vector
    n = Point(N.x / Nm, N.y / Nm, N.z / Nm)

    # Matrix common factors
    c = cos(theta)
    t = (1 - cos(theta))
    s = sin(theta)
    X = n.x
    Y = n.y
    Z = n.z

    # Matrix 'M'
    d11 = t * X**2 + c
    d12 = t * X * Y - s * Z
    d13 = t * X * Z + s * Y
    d21 = t * X * Y + s * Z
    d22 = t * Y**2 + c
    d23 = t * Y * Z - s * X
    d31 = t * X * Z - s * Y
    d32 = t * Y * Z + s * X
    d33 = t * Z**2 + c

    #            |p.x|
    # Matrix 'M'*|p.y|
    #            |p.z|
    q.x = d11 * p.x + d12 * p.y + d13 * p.z
    q.y = d21 * p.x + d22 * p.y + d23 * p.z
    q.z = d31 * p.x + d32 * p.y + d33 * p.z

    # Translate axis and rotated point back to original location
    return q + p1
    def __init__(self):
        window = Tk()
        window.title("Triangle Angles")

        self.canvas = Canvas(window, width=300, height=200, bg="white")
        self.canvas.pack()
        self.p1 = Point(40, 40)
        self.p2 = Point(80, 80)
        self.p3 = Point(40, 80)
        self.points = [self.p1, self.p2, self.p3]
        self.activePoint = self.p1
        self.draggable = False
        self.drawTriangle()
        self.drawAngles()

        self.canvas.bind("<Button-1>", self.processClick)
        self.canvas.bind("<B1-Motion>", self.processDrag)
        self.canvas.bind("<ButtonRelease-1>", self.processUp)

        window.mainloop()
Beispiel #34
0
    def FieldPressedListener(self, event):
        mouse_x = event.x - self._gui.get_width_border()
        mouse_y = event.y - self._gui.get_height_border()
        good = False
        if (self._world.get_board_type() == df.const.RECTANGLE):
            x = self.in_box_x(mouse_x)
            y = self.in_box_y(mouse_y)
            if (0 <= x < self._world.get_width() and 0 <= y < self._world.get_height()):
                good = True

        else:  # HEXAGON
            point = Point()
            point.to_hex(mouse_x, mouse_y, self._gui.get_hex_height())
            x = point.get_x()
            y = point.get_y()
            if (0 <= x < self._world.get_width() and 0 <= y < self._world.get_height()):
                good = True
        if (good is True and self._world.field_free(x, y)):
            print("Clicked at", x + 1, y + 1)
            self._combo_box = RadioButton(x, y)
            self._combo_box.add_spawn_listener(self.SpawnListener)
Beispiel #35
0
    m = sum(points, Point(0, 0)) / len(points)
    number(id, m)
    for i in range(len(neighbours)):
        p1 = points[i]
        p2 = points[(i + 1) % len(points)]
        p = ((p1 + p2) / 2 + m) / 2
        number(neighbours[i] % len(order), p)


"""i = w.create_line(xy, fill="red")
w.coords(i, new_xy) # change coordinates
w.itemconfig(i, fill="blue") # change color

w.delete(i) # remove"""

p1 = Point(300, 300)
p2 = Point(350, 300)

shape = net
shapes = []
shapespoly = []
order = sorted(shape)


class Poly:
    def __init__(self, id, points):
        self.n = []
        self.id = id
        self.points = points
        realid = id % len(order)
        self.pid = make(points, int((id - realid) / len(order)))
Beispiel #36
0
 def log(self):
     E = EllipticCurve(self.a, self.b, self.p)
     P = Point(self.Px, self.Py, 1)
     G = Point(self.Gx, self.Gy, 1)
     R = E.log(P, G)
     self._output.insert(END, "log_G" + str(P) + " = " + str(R) + "\n")
Beispiel #37
0
 def add(self):
     P = Point(self.Px, self.Py, 1)
     Q = Point(self.Qx, self.Qy, 1)
     R = P.add(Q, self.a, self.b, self.p)
     self._output.insert(END, str(P) + " + " + str(Q) + " = " + str(R) + "\n")
Beispiel #38
0
import rospy
from std_msgs.msg import String
from subscriber.msg import FieldPositions
from subscriber.srv import *
from Point import Point
from velchange import *
import math
from numpy import matrix
import signal
import sys
# from roboclaw import *

start_time = 1

centerField = Point()
goal = Point()
#hardcoded if vision is untrustworthy
centerField.x = 423
centerField.y = 234
goal.x = 0
goal.y = 234
defensex = 50
globalCounter = 0
dbehind = 20
yNorthThreshold = -30
ySouthThreshold = 15
yNorthOffset = -16
ySouthOffset = 18
goalYOffset = -12
fastMaxSpeed = .9
Beispiel #39
0
    def ScalePoint(self, p_org: Point):
        x_low = p_org.xVal_ * self.scale_factor_ - (self.scale_factor_ - 1)
        x_high = p_org.xVal_ * self.scale_factor_
        x_range = range(x_low, x_high + 1)

        y_low = p_org.yVal_ * self.scale_factor_ - (self.scale_factor_ - 1)
        y_high = p_org.yVal_ * self.scale_factor_
        y_range = range(y_low, y_high + 1)

        out = []
        for i in x_range:
            for j in y_range:
                out.append(Point(i, j))

        return out


if __name__ == "__main__":
    # testField = ObstacleField(72, 96, 24, 34, 24, 6, [Point(3,3), Point(3,4), Point(3,5), Point (3,6)])
    testField = ObstacleField(
        8, 10, 2, 2, 2, 2,
        [Point(3, 3), Point(3, 4),
         Point(3, 5), Point(3, 6)])
    scaler = ObstacleFieldScaler(4, testField)

    print("\nOriginal")
    print(scaler.field_.toString())
    print("\n\nScaled by:", scaler.scale_factor_)
    print("\n\nResult")
    print(scaler.scaled_field_.toString())
Beispiel #40
0
 def test_too_far(self):
     wall = Polygon([Point(0, 0), Point(0, 2)])
     expected = 100
     result = wall.range_measurement(Point(500, 1), math.pi, 5, 100)
     self.assertEqual(result, expected)
Beispiel #41
0
def init_segments():
    return [(Point(4, 0), Point(14, 6)), (Point(12, 0), Point(16, 2)), (Point(4, 12), Point(16, 13)),
            (Point(14, 6), Point(14, 14)), (Point(1, 7), Point(4, 1)), (Point(6, -2), Point(0, 12)),
            (Point(11, 16), Point(0, 8)), (Point(12, 15), Point(3, -2)), (Point(10, 0), Point(0, 12.5))]
 def __init__(self, arm_length=200):
     self.arm_length = arm_length
     self.center = Point(400, 400)
     self.input = []
     self.output = []
 def translate(self, center, angle):
     return Point(center.x + self.arm_length * np.sin(angle),
                  center.y - self.arm_length * np.cos(angle))
Beispiel #44
0
 def __init__(self, x, y, radius):
     if radius < 0:
         raise ValueError("promień ujemny")
     self.pt = Point(x, y)
     self.radius = radius
class Game:
    def __init__(self, speed=5):
        self.speed = speed
        point_speed = self.speed
        # points
        self.upLeft = Point(upLeft, 1, posUpLeft, point_speed)
        self.upRight = Point(upRight, 2, posUpRight, point_speed)
        self.downLeft = Point(downLeft, 3, posDownLeft, point_speed)
        self.downRight = Point(downRight, 4, posDownRight, point_speed)
        # score
        self.score = Scoreboard()
        #
        self.perfect = 0
        self.great = 0
        self.bad = 0
        self.miss = 0
        self.performance = ""

    def update(self):
        if self.upLeft.spawnTime == 0:
            pygame.mixer.music.play(1)

        # verse 1
        if self.upLeft.spawnTime == 0:
            self.upLeft.add()
        if self.upRight.spawnTime == 34:
            self.upRight.add()
        if self.upLeft.spawnTime == 76:
            self.upLeft.add()
        if self.upRight.spawnTime == 115:
            self.upRight.add()
        if self.downRight.spawnTime == 142:  # moti
            self.downRight.add()
        if self.upLeft.spawnTime == 180 and self.downRight.spawnTime == 180:
            self.upLeft.add()
            self.downRight.add()
        if self.upRight.spawnTime == 195 and self.downLeft.spawnTime == 195:
            self.upRight.add()
            self.downLeft.add()
        if self.downRight.spawnTime == 225 and self.downLeft.spawnTime == 225:
            self.downLeft.add()
            self.downRight.add()
        if self.upRight.spawnTime == 235:  # yes
            self.upRight.add()
        if self.upRight.spawnTime == 260:  # yes
            self.upRight.add()

        if self.downLeft.spawnTime == 312:  # insti
            self.downLeft.add()
        if self.upRight.spawnTime == 355 and self.downLeft.spawnTime == 355:
            self.upRight.add()
            self.downLeft.add()
        if self.upLeft.spawnTime == 383 and self.downRight.spawnTime == 383:
            self.upLeft.add()
            self.downRight.add()
        if self.downRight.spawnTime == 403 and self.downLeft.spawnTime == 403:
            self.downLeft.add()
            self.downRight.add()
        if self.upLeft.spawnTime == 420:  # that's
            self.upLeft.add()
        if self.upLeft.spawnTime == 442:  # that's
            self.upLeft.add()

        if self.downLeft.spawnTime == 474:
            self.downLeft.add()
        if self.upLeft.spawnTime == 520:
            self.upLeft.add()
        if self.upRight.spawnTime == 557:
            self.upRight.add()
        if self.downRight.spawnTime == 594:
            self.downRight.add()
        if self.downRight.spawnTime == 634:
            self.downRight.add()
        if self.upRight.spawnTime == 674:
            self.upRight.add()
        if self.upLeft.spawnTime == 713:
            self.upLeft.add()
        if self.downLeft.spawnTime == 740:
            self.downLeft.add()

        if self.downRight.spawnTime == 752 and self.downLeft.spawnTime == 752:
            self.downLeft.add()
            self.downRight.add()
        if self.downRight.spawnTime == 805 and self.downLeft.spawnTime == 805:
            self.downLeft.add()
            self.downRight.add()

        if self.upRight.spawnTime == 835 and self.upLeft.spawnTime == 835:
            self.upLeft.add()
            self.upRight.add()
        if self.downRight.spawnTime == 865 and self.downLeft.spawnTime == 865:
            self.downRight.add()
            self.downLeft.add()
        if self.upRight.spawnTime == 895:
            self.upRight.add()
        if self.upRight.spawnTime == 915:
            self.upRight.add()
        if self.upRight.spawnTime == 937 and self.upLeft.spawnTime == 937:
            self.upRight.add()
            self.upLeft.add()
        if self.downRight.spawnTime == 960 and self.downLeft.spawnTime == 960:
            self.downLeft.add()
            self.downRight.add()

        if self.downRight.spawnTime == 990:
            self.downRight.add()
        if self.upRight.spawnTime == 1017:
            self.upRight.add()
        if self.upLeft.spawnTime == 1045:
            self.upLeft.add()
        if self.downLeft.spawnTime == 1070:
            self.downLeft.add()
        if self.downLeft.spawnTime == 1100:
            self.downLeft.add()
        if self.upLeft.spawnTime == 1120:
            self.upLeft.add()
        if self.upRight.spawnTime == 1140:
            self.upRight.add()
        if self.downRight.spawnTime == 1150:
            self.downRight.add()

        if self.upLeft.spawnTime == 1170:
            self.upLeft.add()
        if self.upLeft.spawnTime == 1190:
            self.upLeft.add()
        if self.upRight.spawnTime == 1235:
            self.upRight.add()
        if self.upRight.spawnTime == 1260:
            self.upRight.add()
        if self.downRight.spawnTime == 1285:
            self.downRight.add()
        if self.downRight.spawnTime == 1305:
            self.downRight.add()
        if self.upLeft.spawnTime == 1335:
            self.upLeft.add()
        if self.upLeft.spawnTime == 1355:
            self.upLeft.add()

        if self.upRight.spawnTime == 1380 and self.upLeft.spawnTime == 1380:
            self.upLeft.add()
            self.upRight.add()
        if self.upRight.spawnTime == 1400 and self.upLeft.spawnTime == 1400:
            self.upLeft.add()
            self.upRight.add()
        if self.downRight.spawnTime == 1435 and self.downLeft.spawnTime == 1435:
            self.downLeft.add()
            self.downRight.add()
        if self.downRight.spawnTime == 1455 and self.downLeft.spawnTime == 1455:
            self.downLeft.add()
            self.downRight.add()

        # verse 2
        if self.upLeft.spawnTime == 1529:
            self.upLeft.add()
        if self.upRight.spawnTime == 34 + 1529:
            self.upRight.add()
        if self.upLeft.spawnTime == 76 + 1529:
            self.upLeft.add()
        if self.upRight.spawnTime == 115 + 1529:
            self.upRight.add()

        if self.downRight.spawnTime == 1529:  # moti
            self.downRight.add()
        if self.upLeft.spawnTime == 180 + 1387 and self.downRight.spawnTime == 180 + 1387:
            self.upLeft.add()
            self.downRight.add()
        if self.upRight.spawnTime == 195 + 1387 and self.downLeft.spawnTime == 195 + 1387:
            self.upRight.add()
            self.downLeft.add()
        if self.downRight.spawnTime == 225 + 1387 and self.downLeft.spawnTime == 225 + 1387:
            self.downLeft.add()
            self.downRight.add()
        if self.upRight.spawnTime == 235 + 1387:  # yes
            self.upRight.add()
        if self.upRight.spawnTime == 260 + 1387:  # yes
            self.upRight.add()

        if self.downLeft.spawnTime == 312 + 1387:  # insti
            self.downLeft.add()
        if self.upRight.spawnTime == 355 + 1387 and self.downLeft.spawnTime == 355 + 1387:
            self.upRight.add()
            self.downLeft.add()
        if self.upLeft.spawnTime == 383 + 1387 and self.downRight.spawnTime == 383 + 1387:
            self.upLeft.add()
            self.downRight.add()
        if self.downRight.spawnTime == 403 + 1387 and self.downLeft.spawnTime == 403 + 1387:
            self.downLeft.add()
            self.downRight.add()
        if self.upLeft.spawnTime == 420 + 1387:  # that's
            self.upLeft.add()
        if self.upLeft.spawnTime == 442 + 1387:  # that's
            self.upLeft.add()

        if self.downLeft.spawnTime == 474 + 1387:
            self.downLeft.add()
        if self.upLeft.spawnTime == 520 + 1387:
            self.upLeft.add()
        if self.upRight.spawnTime == 557 + 1387:
            self.upRight.add()
        if self.downRight.spawnTime == 594 + 1387:
            self.downRight.add()
        if self.downRight.spawnTime == 634 + 1387:
            self.downRight.add()
        if self.upRight.spawnTime == 674 + 1387:
            self.upRight.add()
        if self.upLeft.spawnTime == 713 + 1387:
            self.upLeft.add()
        if self.downLeft.spawnTime == 740 + 1387:
            self.downLeft.add()

        if self.downRight.spawnTime == 752 + 1387 and self.downLeft.spawnTime == 752 + 1387:
            self.downLeft.add()
            self.downRight.add()  # one in a million
        if self.downRight.spawnTime == 805 + 1387 and self.downLeft.spawnTime == 805 + 1387:
            self.downLeft.add()
            self.downRight.add()

        if self.upRight.spawnTime == 835 + 1387 and self.upLeft.spawnTime == 835 + 1387:
            self.upLeft.add()
            self.upRight.add()  # high
        if self.downRight.spawnTime == 865 + 1387 and self.downLeft.spawnTime == 865 + 1387:
            self.downRight.add()
            self.downLeft.add()  # drop
        if self.upRight.spawnTime == 895 + 1387:
            self.upRight.add()
        if self.upRight.spawnTime == 915 + 1387:
            self.upRight.add()
        if self.upRight.spawnTime == 937 + 1387 and self.upLeft.spawnTime == 937 + 1387:
            self.upRight.add()
            self.upLeft.add()
        if self.downRight.spawnTime == 960 + 1387 and self.downLeft.spawnTime == 960 + 1387:
            self.downLeft.add()
            self.downRight.add()

        if self.downRight.spawnTime == 990 + 1387:
            self.downRight.add()
        if self.upRight.spawnTime == 1017 + 1387:
            self.upRight.add()
        if self.upLeft.spawnTime == 1045 + 1387:
            self.upLeft.add()
        if self.downLeft.spawnTime == 1070 + 1387:
            self.downLeft.add()
        if self.downLeft.spawnTime == 1100 + 1387:
            self.downLeft.add()
        if self.upLeft.spawnTime == 1120 + 1387:
            self.upLeft.add()
        if self.upRight.spawnTime == 1140 + 1387:
            self.upRight.add()
        if self.downRight.spawnTime == 1150 + 1387:
            self.downRight.add()  # what it sounds like

        if self.upLeft.spawnTime == 1170 + 1387:
            self.upLeft.add()
        if self.upLeft.spawnTime == 1190 + 1387:
            self.upLeft.add()
        if self.upRight.spawnTime == 1235 + 1387:
            self.upRight.add()
        if self.upRight.spawnTime == 1260 + 1387:
            self.upRight.add()
        if self.downRight.spawnTime == 1285 + 1387:
            self.downRight.add()
        if self.downRight.spawnTime == 1305 + 1387:
            self.downRight.add()
        if self.upLeft.spawnTime == 1335 + 1387:
            self.upLeft.add()
        if self.upLeft.spawnTime == 1355 + 1387:
            self.upLeft.add()

        if self.upRight.spawnTime == 1380 + 1387 and self.upLeft.spawnTime == 1380 + 1387:
            self.upLeft.add()
            self.upRight.add()
        if self.upRight.spawnTime == 1400 + 1387 and self.upLeft.spawnTime == 1400 + 1387:
            self.upLeft.add()
            self.upRight.add()
        if self.downRight.spawnTime == 1435 + 1387 and self.downLeft.spawnTime == 1435 + 1387:
            self.downLeft.add()
            self.downRight.add()
        if self.downRight.spawnTime == 1455 + 1387 and self.downLeft.spawnTime == 1455 + 1387:
            self.downLeft.add()
            self.downRight.add()

        # beat drop
        if self.downLeft.spawnTime == 2870:
            self.downLeft.add()

        self.upLeft.spawn()
        self.upLeft.move()
        self.upRight.spawn()
        self.upRight.move()
        self.downLeft.spawn()
        self.downLeft.move()
        self.downRight.spawn()
        self.downRight.move()
        self.score.display(self.score.score)

        Display_Performance(self.performance)
Beispiel #46
0
 def test_easy_hit(self):
     wall = Polygon([Point(0, 0), Point(0, 2)])
     expected = 1
     result = wall.range_measurement(Point(1, 1), math.pi, 0, 100)
     self.assertEqual(result, expected)
Beispiel #47
0
 def test_miss(self):
     wall = Polygon([Point(0, 0), Point(0, 2)])
     expected = 100
     result = wall.range_measurement(Point(1, 1), 0, 0, 100)
     self.assertEqual(result, expected)
Beispiel #48
0
def get_current_parameter(segment: tuple, vertex1: Point, vertex2: Point):
    normal_vector = Point(vertex2.y - vertex1.y, -(vertex2.x - vertex1.x))
    segment_vertex_vector = Point(vertex1.x - segment[0].x, vertex1.y - segment[0].y)
    segment_vector = Point(segment[1].x - segment[0].x, segment[1].y - segment[0].y)
    return (segment_vertex_vector * normal_vector) / (segment_vector * normal_vector)
Beispiel #49
0
 def test_triangle(self):
     triangle = Polygon([Point(2, 0), Point(0, 2), Point(2, 2)])
     expected = math.sqrt(2)
     result = triangle.range_measurement(Point(0, 0), math.pi / 4, 0, 100)
     self.assertAlmostEqual(result, expected)
Beispiel #50
0
class Game:
    SCREEN = None
    MAP = {}
    MAPDIMENSIONS = Point(25, 23)
    PLAYERSTARTPOSITION = Point(11, 11) #should be 11 11
    ENEMYSTARTPOSITION = Point(10, 7) #should b e 10 7
    VIEWPORTDIMENSIONS = Point(8,8)
    PLAYER = None
    ENEMY = None
    turn = 0
    gameRunning = True
    gameState = "INGAME"
    offeringPosition = None
    offeringCountdown = 6
    debugMessage = ""
    controlString = "Movement: [w][a][s][d] [p]ick up [i]nspect dr[o]p"
    def __init__(self):
        intro = "You have been selected to become one of the seven boys and seven girls to be sacrificed as tribute to the great King Minos. Your parents and community have told you that it is a great honor to be selected, but it does not make the red hot iron brand shaped like an M any less painful. You scratch the sizzling wound on your chest as you are led down a dark hallway by the kings men. You see a rope mechanism leading down into a large circular pit. You know the guards are there to make sure the sacrifices do not jump into the pit. To lose a sacrifice before it is ready will anger the gods. The kings men put you into a barrel and slowly lower you into the pit. You cannot see out of the barrel but you know you are going down. After hours of waiting, the rope holding the barrel snaps, and you and your barrel are sent hurtling down into the abyss.\n\nYou come to in a dark featureless room made entirely out of smooth black stone. There is no light, but somehow you are able to see your own hands. There is no ceiling, but the walls are far too tall and smooth to climb. In the distance, you can hear the echos of hooves on stone. You are not the only one here."
        print(intro)
        playerInput = input("Enter any input to continue:")
        self.MAP = self.initMap()
        self.initEdges()
        self.MAP[Point(9,7)].addToInventory(Item("TORCH"))
        self.MAP[Point(1,1)].addToInventory(Item("SEVEN"))
        self.MAP[Point(4,5)].addToInventory(Item("FIFTYTHREE"))
        self.MAP[Point(9,17)].addToInventory(Item("ONEHUNDREDANDTHREE"))
        self.MAP[Point(1,21)].addToInventory(Item("FORTYONE"))
        self.MAP[Point(11,1)].addToInventory(Item("ONEHUNDREDANDONE"))
        self.MAP[Point(11,13)].addToInventory(Item("ONEHUNDREDANDSEVEN"))
        self.MAP[Point(23,1)].addToInventory(Item("OFFERINGS"))
        self.MAP[Point(23,17)].addToInventory(Item("SHACKLES"))
        self.MAP[Point(23,7)].setGenericClue("You can make out the word 'Μῑνώταυρος' etched onto the floor.")
        self.MAP[Point(16,7)].setGenericClue("I dedicate this LABYRINTH to my beloved son.")
        self.MAP[Point(15,17)].setMastermindDoor()
        self.MAP[Point(16,17)].setMastermind(self.MAP[Point(15,17)])
        self.MAP[Point(12,5)].setAlphaDoor()
        self.MAP[Point(11,5)].setAlphaDoorClue(self.MAP[Point(12,5)])
        self.MAP[Point(23,11)].setCipherDoor()
        self.MAP[Point(23,10)].setCipherDoorClue(self.MAP[Point(23,11)])
        self.MAP[Point(11,21)].setExit()
        self.MAP[Point(14,15)].setPuzzleChest()
        self.initializePlayer()
        self.initializeEnemy()
        self.gameLoop()

    def gameLoop(self):
        self.debugMessage = "Starting game..."
        while self.gameRunning == True:
            print(self.PLAYER.position)
            print(self.debugMessage)
            print(self.generateViewport())
            print(self.MAP[self.PLAYER.position].getDescription())
            playerInput = input("Movement: [w][a][s][d] [p]ick up [i]nspect dr[o]p: ")
            self.handleInput(playerInput)
            self.initEdges()
            if self.ENEMY != None:
                self.doEnemyTurn()
                self.checkIfDead()
            if self.MAP[self.PLAYER.position].ROOMTYPE == "EXIT":
                self.win()

    def doEnemyTurn(self):
        short = None
        if self.offeringPosition != None:
            short = self.shortestPath(self.MAP[self.ENEMY.position], self.MAP[self.offeringPosition])
        else:
            short = self.shortestPath(self.MAP[self.ENEMY.position],self.MAP[self.PLAYER.position])
        if self.ENEMY.position != self.PLAYER.position:
            if len(short) > 1:
                self.moveEnemy(short[1])
        if self.offeringPosition != None and self.offeringCountdown > 0:
            if self.ENEMY.position == self.offeringPosition:
                self.offeringCountdown -= 1
        if self.offeringPosition != None and self.offeringCountdown == 0:
            self.offeringCountdown = 5
            offeringIndex = self.MAP[self.offeringPosition].hasItem("OFFERINGS")
            self.MAP[self.offeringPosition].inventory.pop(offeringIndex)
            self.offeringPosition = None

    def moveEnemy(self, newRoom):
        if self.turn % 2 == 0:
            self.MAP[self.ENEMY.position].enemyInRoom = False
            self.ENEMY.position = newRoom.position
            newRoom.enemyInRoom = True
            print("ENEMY moved to" + str(newRoom.position))

    def checkIfDead(self):
        if self.ENEMY.position == self.PLAYER.position:
            print("GAME OVER")
            self.gameRunning = False

    def handleInput(self, playerInput):
        playerInput = playerInput.lower()
        if playerInput == "quit":
            self.debugMessage = "Quitting the game..."
            self.gameRunning = False
            return
        if self.gameState == "INGAME":
            newPosition = self.PLAYER.position
            if playerInput == "a":
                newPosition += Point(0, -1)
                if self.movePlayer(newPosition):
                    self.endTurn()
            elif playerInput == "d":
                newPosition += Point(0, 1)
                if self.movePlayer(newPosition):
                    self.endTurn()
            elif playerInput == "w":
                newPosition += Point(-1, 0)
                if self.movePlayer(newPosition):
                    self.endTurn()
            elif playerInput == "s":
                newPosition += Point(1, 0)
                if self.movePlayer(newPosition):
                    self.endTurn()
            elif playerInput == "p":
                if self.pickUpItem():
                    self.endTurn()
            elif playerInput == "i":
                self.inspectItem()
            elif playerInput == "o":
                if self.dropItem():
                    self.endTurn()
            elif playerInput == "isopsephy" and self.MAP[self.PLAYER.position].ROOMTYPE == "CIPHERDOORCLUE":
                self.MAP[self.PLAYER.position].isopsephy()
                self.endTurn()
            elif playerInput == "guess" and self.MAP[self.PLAYER.position].ROOMTYPE == "MASTERMIND":
                self.MAP[self.PLAYER.position].mastermindGuess()
                self.endTurn()
            elif playerInput == "open" and self.MAP[self.PLAYER.position].ROOMTYPE == "PUZZLECHEST":
                self.MAP[self.PLAYER.position].chestGuess()
                self.endTurn()
            elif playerInput == "i am a weenie":
                self.weenie()
                self.endTurn()
            else:
                return


    def endTurn(self):
        self.turn += 1
        print("----------Turn End----------")

    def weenie(self):
        print("input [0] to move to tree puzzle")
        print ("input [1] to move to cipher puzzle")
        print("input [2] to move to binary puzzle")
        print("input [3] to move to permutation puzzle")
        print("input [4] to remove danger")
        validInput = False
        selectedChoice = None
        while validInput == False:
            playerInput = input("input:")
            if playerInput in ["0","1","2","3","4"]:
                validInput = True
                selectedChoice = playerInput
        if selectedChoice == "0":
            self.weenieTeleport(Point(11,5))
            self.PLAYER.addToInventory(Item("FORTYONE"))
            self.PLAYER.addToInventory(Item("SEVEN"))
            self.PLAYER.addToInventory(Item("FIFTYTHREE"))
            self.PLAYER.addToInventory(Item("ONEHUNDREDANDSEVEN"))
            self.PLAYER.addToInventory(Item("ONEHUNDREDANDONE"))
            self.PLAYER.addToInventory(Item("ONEHUNDREDANDTHREE"))
        if selectedChoice == "1":
            self.weenieTeleport(Point(23,10))
        if selectedChoice == "2":
            self.weenieTeleport(Point(14,15))
        if selectedChoice == "3":
            self.weenieTeleport(Point(16,17))
        if selectedChoice == "4":
            self.MAP[self.ENEMY.position].enemyInRoom = False
            self.ENEMY = None

    def weenieTeleport(self, newPosition):
        self.MAP[self.PLAYER.position].playerInRoom = False
        self.PLAYER.position = newPosition
        self.MAP[self.PLAYER.position].playerInRoom = True
        self.debugMessage = "You teleported to " + str(newPosition)

    def movePlayer(self, newPosition):
        if self.PLAYER.hasItem("SHACKLES"):
            rand = random.randint(0,3)
            if rand == 1:
                print("The cursed SHACKLES slow you down.")
                return False
        if self.PLAYER.position == newPosition:
            self.debugMessage = "You didn't move"
            return False
        if newPosition in self.MAP:
            if self.MAP[newPosition].walkable == True:
                self.MAP[self.PLAYER.position].playerInRoom = False
                self.PLAYER.position = newPosition
                self.MAP[self.PLAYER.position].playerInRoom = True
                self.debugMessage = "You moved to" + str(newPosition)
                return True
            else:
                if self.MAP[newPosition].ROOMTYPE == "SOLID":
                    self.debugMessage = "You bumped into a wall..."
                elif self.MAP[newPosition].ROOMTYPE in ["ALPHADOOR", "CIPHERDOOR", "MASTERMINDDOOR"]:
                    self.debugMessage = "You bumped into a door..."
                return False
        else:
            self.debugMessage = "DEBUG: ATTEMPTED TO MOVE OUT OF BOUNDS!"
            return False

    def initializePlayer(self):
        self.PLAYER = Player(self.PLAYERSTARTPOSITION)
        self.MAP[self.PLAYERSTARTPOSITION].playerInRoom = True

    def initializeEnemy(self):
        self.ENEMY = Enemy(self.ENEMYSTARTPOSITION)
        self.MAP[self.ENEMYSTARTPOSITION].enemyInRoom = True

    def generateViewport(self):
        upperLeftBound = self.PLAYER.position + Point(-3, -3)
        lowerRightBound = self.PLAYER.position + Point(4, 4)
        mapString = self.printMap(upperLeftBound, lowerRightBound)
        return mapString

    def pickUpItem(self):
        if len(self.MAP[self.PLAYER.position].inventory) == 0:
            print("Nothing to pick up...")
            return False
        if len(self.MAP[self.PLAYER.position].inventory) == 1:
            item = self.MAP[self.PLAYER.position].getItem(0)
            self.PLAYER.addToInventory(item)
            print("You picked up a " + item.NAME)
            return True
        validInput = False
        while validInput == False:
            playerInput = input("Enter the index of the item you wish to pick up: ")
            if playerInput.isnumeric() == True:
                if 0 <= int(playerInput) < len(self.MAP[self.PLAYER.position].inventory):
                    validInput = True
                else:
                    print("Not a valid index. Item not found")
                    return False
            else:
                print("Not a valid number.")
                return False
        itemIndex = int(playerInput)
        item = self.MAP[self.PLAYER.position].getItem(itemIndex)
        self.PLAYER.addToInventory(item)
        print("You picked up a " + item.NAME)
        return True

    def dropItem(self):
        if len(self.PLAYER.inventory) == 0:
            print("Nothing to drop...")
            return False
        validInput = False
        while validInput == False:
            playerInput = input("Enter the index of the item in your inventory you wish to drop: ")
            if playerInput.isnumeric() == True:
                if 0 <= int(playerInput) < len(self.PLAYER.inventory):
                    validInput = True
                else:
                    print("Not a valid index. Item not found")
                    return False
            else:
                print("Not a valid number.")
                return False
        itemIndex = int(playerInput)
        item = self.PLAYER.getItem(itemIndex)
        if item.value != None:
            print("You inserted " + item.NAME + " into the door...")
            self.MAP[self.PLAYER.position].addToInventory(item)
            return True
        elif item.NAME == "OFFERINGS":
            if self.offeringPosition == None:
                print("You have placed the OFFERINGS on the floor. RUN.")
                self.offeringPosition = self.PLAYER.position
                self.MAP[self.PLAYER.position].addToInventory(item)
                return True
            else:
                print("You have already placed OFFERINGS.")
                return False
        elif item.NAME == "SHACKLES":
            print("You can't drop these SHACKLES. They appear to be cursed.")
            return False
        else:
            print("You have dropped " + item.NAME + " on the floor...")
            self.MAP[self.PLAYER.position].addToInventory(item)
            return True

    def inspectItem(self):
        if len(self.PLAYER.inventory) == 0:
            print("Nothing to inspect...")
            return
        validInput = False
        while validInput == False:
            playerInput = input("Enter the index of the item in your inventory you wish to inspect: ")
            if playerInput.isnumeric() == True:
                if 0 <= int(playerInput) < len(self.PLAYER.inventory):
                    validInput = True
                else:
                    print("Not a valid index. Item not found")
                    return
            else:
                print("Not a valid number.")
                return
        itemIndex = int(playerInput)
        item = self.PLAYER.inventory[itemIndex]
        print("Description: " + item.description)

    def printMap(self, upperLeftBound, lowerRightBound):
        mapString = ""
        row = 0
        dist = self.dijkstra(self.MAP[self.PLAYER.position], self.makeWalkableRoomsSet())
        for room in self.MAP.values():
            room.isHidden = True
        for x in range(upperLeftBound.x, lowerRightBound.x):
            for y in range(upperLeftBound.y, lowerRightBound.y):
                if Point(x,y) in self.MAP:
                    if self.MAP[Point(x,y)] in dist:
                        vision = dist[self.MAP[Point(x,y)]]
                        if vision <= self.PLAYER.getVisionRadius():
                            self.MAP[Point(x,y)].isHidden = False
                            adjacents = [(0,1),(0,-1),(1,0),(-1,0), (1,1), (-1,-1), (1, -1), (-1,1)]
                            for adjacent in adjacents:
                                newPosition = Point(x,y) + adjacent
                                if newPosition in self.MAP:
                                    if self.MAP[newPosition].walkable == False:
                                        self.MAP[newPosition].isHidden = False
        for x in range(upperLeftBound.x,lowerRightBound.x):
            lineString = ""
            for y in range(upperLeftBound.y,lowerRightBound.y):
                if Point(x,y) in self.MAP:
                    distance = self.PLAYER.position - Point(x,y)

                    #print(Point(x,y))
                    visionRadius = self.PLAYER.getVisionRadius()
                    # if distance.x <= visionRadius and distance.x >= visionRadius * -1:
                    #     if distance.y <= visionRadius and distance.y >= visionRadius * -1:
                    #         self.MAP[Point(x,y)].isHidden = False
                    lineString += self.MAP[Point(x,y)].getRoomChar()
                else:
                    lineString += "\u2591"
            if row == 0:
                lineString += " Turn: " + str(self.turn)
            if row == 2:
                lineString += " Items in room:" + self.MAP[self.PLAYER.position].getInventoryString()
            if row == 3:
                lineString += " Inventory:" + self.PLAYER.getInventoryString()
            lineString += "\n"
            mapString += lineString
            row += 1
        return mapString

    @staticmethod
    def initMap():
        intMap = [
            [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
            [0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0],
            [0,1,0,0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,0],
            [0,1,0,0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,0],
            [0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
            [0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0],
            [0,1,1,1,1,1,0,1,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0],
            [0,0,0,0,0,1,0,1,1,1,1,0,1,1,1,1,0,1,0,0,0,0,0],
            [0,0,0,0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,0,0],
            [0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0],
            [0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0],
            [0,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1],
            [0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0],
            [0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0],
            [0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0],
            [0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0],
            [0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0],
            [0,1,0,0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,0],
            [0,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0],
            [0,0,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0],
            [0,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,0],
            [0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0],
            [0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0],
            [0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
            [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],]
        newDict = {}
        for x in range(len(intMap)):
            for y in range(len(intMap[x])):
                if intMap[x][y] == 0:
                    newDict[(x,y)] = Room(Point(x,y), "SOLID")
                if intMap[x][y] == 1:
                    newDict[(x,y)] = Room(Point(x,y), "EMPTY")
        return newDict

    def initEdges(self):
        for room in self.MAP.values():
            self.setEdges(room)

    def setEdges(self, currentRoom):
        adjacents = [(0,1),(1,0),(-1,0),(0,-1)]
        edges = []
        for adjacent in adjacents:
            newPosition = currentRoom.position + adjacent
            if (newPosition) in self.MAP:
                if self.MAP[newPosition].walkable == True:
                    edges.append(self.MAP[newPosition])
        currentRoom.edges = edges

    def makeWalkableRoomsSet(self):
        nodes = set()
        for room in self.MAP.values():
            if room.walkable:
                nodes.add(room)
        return nodes

    #adapted from https://gist.github.com/econchick/4666413
    def dijkstra(self, startNode, walkableRooms):
        visited = {startNode: 0}
        path = {}
        rooms = walkableRooms
        while rooms:
            minNode = None
            for node in rooms:
                if node in visited:
                    if minNode is None:
                        minNode = node
                    elif visited[node] < visited[minNode]:
                        minNode = node
            if minNode is None:
                break
            rooms.remove(minNode)
            current_weight = visited[minNode]
            for edge in minNode.edges:
                weight = current_weight + 1
                if edge not in visited or weight < visited[edge]:
                    visited[edge] = weight
                    path[edge] = minNode
        return visited

    def shortestPath(self, start, end):
        dist = self.dijkstra(start, self.makeWalkableRoomsSet())
        if end not in dist:
            return []
        def dfs(v, path = []):
            if v == start:
                return path
            distv = dist[v]
            for e in v.edges:
                if dist[e] < distv:
                    return dfs(e, path + [e])
        shortest = dfs(end, [end])
        shortest.reverse()
        return shortest

    def win(self):
        wintext = "The door opens and you climb the spiral staircase. You look down and see the walls of the LABYRINTH extending outwards in every direction into darkness. You do not know how tall this staircase is, but the sound of hooves on stone below motivates you to keep climbing. \n\nAfter what feels like many days of climbing the spiral staircase without rest, you feel wind for the first time. You continue to climb higher and higher until you are blinded by light.\n\nYou emerge the cave not far from home. You can smell the salt and hear the sea crashing against the rocks.\n\nTaking on a new identity, you sail far away from Crete. Sometimes, late at night, you wonder if the brand of sacrifice is permanent. Sometimes, just before you fall asleep, you can still hear the sound of hooves on stone.\n\n\nTHE END"
        print(wintext)
        self.gameRunning = False
Beispiel #51
0
 def __init__(self):
     self.point_start = Point(0, 0)
     self.point_end = Point(0, 0)
     self.__travel_x = 0
     self.__travel_y = 0
Beispiel #52
0
 def generateViewport(self):
     upperLeftBound = self.PLAYER.position + Point(-3, -3)
     lowerRightBound = self.PLAYER.position + Point(4, 4)
     mapString = self.printMap(upperLeftBound, lowerRightBound)
     return mapString
Beispiel #53
0
class ObstacleField:
    def __init__(self, heightInches, widthInches, entranceWidth, entranceOffset, exitWidth, exitOffset, occupiedPoints):
        self.heightInches_ = heightInches
        self.widthInches_ = widthInches
        self.entranceWidth_ = entranceWidth
        self.entranceOffset = entranceOffset
        self.exitWidth_ = exitWidth
        self.exitOffset_ = exitOffset

        # if the occupied points list is empty 
        assert type(occupiedPoints) is list, "occupiedPoints argument is not a list. Send an empty list if necessary."
        if len(occupiedPoints) != 0:
            self.isPopulated = True
            self.occupiedPoints_ = occupiedPoints
        else:
            self.isPopulated = False
            self.occupiedPoints_ = []

    def checkPointOccupied(self):
        # return true if the point is not occupied
        

    def toString(self):
        # Print out each coordinate in nested for loops
        rowString = ''
        # For the y axis
        for y in range(self.heightInches_ + 2): # Note, the + 2 here is for the boundaries
            
            # For the x axis
            for x in range(self.widthInches_ + 2): # Note, the + 2 here is for the boundaries

                if y == 0 or y == self.heightInches_ + 1: # If at the top or bottom row
                    rowString += 'x'
                else:
                    # Check to see if we are at the start or the end of the row
                    edgeColumnFlag = 0
                    if x == 0 or x == self.widthInches_ + 1:
                        edgeColumnFlag = 1

                        # Now we need to check to see if we are at the entrance or exit, and leave those clear
                        # Choose to look for either the entrance or exit
                        #if(y == 0):
                            # exit
                        #    if y == (exitOffset + 1): # The plus 1 is because this is an offset from the top wall

                        #else:
                            # entrance


                        # if not entrance or exit
                        rowString += 'x'

                    # Check each point in occupiedPoints
                    pointIsOccupiedFlag = 0
                    for point in self.occupiedPoints_:
                        if point.xVal_ == x and point.yVal_ == y:
                            # the point is occupied
                            rowString += 'x'
                            pointIsOccupiedFlag = 1

                    if not pointIsOccupiedFlag and not edgeColumnFlag: # if point is not occupied
                        rowString += ' '
            
            print(rowString)
            rowString = ''



if __name__ == "__main__":
    testField = ObstacleField(72, 96, 1, 0, 1, 0, [Point(3,3), Point(3,4)])
    testField.toString()
Beispiel #54
0
 def __init__(self):
     intro = "You have been selected to become one of the seven boys and seven girls to be sacrificed as tribute to the great King Minos. Your parents and community have told you that it is a great honor to be selected, but it does not make the red hot iron brand shaped like an M any less painful. You scratch the sizzling wound on your chest as you are led down a dark hallway by the kings men. You see a rope mechanism leading down into a large circular pit. You know the guards are there to make sure the sacrifices do not jump into the pit. To lose a sacrifice before it is ready will anger the gods. The kings men put you into a barrel and slowly lower you into the pit. You cannot see out of the barrel but you know you are going down. After hours of waiting, the rope holding the barrel snaps, and you and your barrel are sent hurtling down into the abyss.\n\nYou come to in a dark featureless room made entirely out of smooth black stone. There is no light, but somehow you are able to see your own hands. There is no ceiling, but the walls are far too tall and smooth to climb. In the distance, you can hear the echos of hooves on stone. You are not the only one here."
     print(intro)
     playerInput = input("Enter any input to continue:")
     self.MAP = self.initMap()
     self.initEdges()
     self.MAP[Point(9,7)].addToInventory(Item("TORCH"))
     self.MAP[Point(1,1)].addToInventory(Item("SEVEN"))
     self.MAP[Point(4,5)].addToInventory(Item("FIFTYTHREE"))
     self.MAP[Point(9,17)].addToInventory(Item("ONEHUNDREDANDTHREE"))
     self.MAP[Point(1,21)].addToInventory(Item("FORTYONE"))
     self.MAP[Point(11,1)].addToInventory(Item("ONEHUNDREDANDONE"))
     self.MAP[Point(11,13)].addToInventory(Item("ONEHUNDREDANDSEVEN"))
     self.MAP[Point(23,1)].addToInventory(Item("OFFERINGS"))
     self.MAP[Point(23,17)].addToInventory(Item("SHACKLES"))
     self.MAP[Point(23,7)].setGenericClue("You can make out the word 'Μῑνώταυρος' etched onto the floor.")
     self.MAP[Point(16,7)].setGenericClue("I dedicate this LABYRINTH to my beloved son.")
     self.MAP[Point(15,17)].setMastermindDoor()
     self.MAP[Point(16,17)].setMastermind(self.MAP[Point(15,17)])
     self.MAP[Point(12,5)].setAlphaDoor()
     self.MAP[Point(11,5)].setAlphaDoorClue(self.MAP[Point(12,5)])
     self.MAP[Point(23,11)].setCipherDoor()
     self.MAP[Point(23,10)].setCipherDoorClue(self.MAP[Point(23,11)])
     self.MAP[Point(11,21)].setExit()
     self.MAP[Point(14,15)].setPuzzleChest()
     self.initializePlayer()
     self.initializeEnemy()
     self.gameLoop()
Beispiel #55
0
 def mult(self):
     P = Point(self.Px, self.Py, 1)
     R = P.mult(self.k, self.a, self.b, self.p)
     self._output.insert(END, str(self.k) + str(P) + " = " + str(R) + "\n")
Beispiel #56
0
class Segment:

    Origin = Point(0, 0)

    def __init__(self, a, b):

        if a == b:
            raise Exception('Single point cannot form a line segment')
        # if the line is vertical
        if abs(a.x - b.x) <= EPS:
            if a.y < b.y:
                self.a = a
                self.b = b
            else:
                self.a = b
                self.b = a

        else:
            if a.x < b.x:
                self.a = a
                self.b = b
            else:
                self.a = b
                self.b = a

        self.length = a.distance(b)
        self.coordinates = (self.a, self.b)
        self.points = (self.a, self.b)

        # finding slope of the line
        if abs(b.x - a.x) <= EPS:
            self.slope = Inf
        else:
            self.slope = (b.y - a.y) / (b.x - a.x)

        self.angle = math.atan2(self.b.y - self.a.y, self.b.x - self.a.x)

    # Check if the two line segments ar
    def is_parallel(self, ls):
        diff = abs(self.angle - ls.angle)
        if diff < RadianEPS:
            return True
        if abs(diff - math.pi) < RadianEPS:
            return True
        return False

    # Check if the line segment contains the given point "p" or not
    def contains(self, p):
        # if p is same as self.a or self.b
        if p.distance(self.a) <= EPS or p.distance(self.b) <= EPS:
            return True
        if self.is_parallel(Segment(p, self.a)):
            # if the line is vertical
            if abs(self.a.x - self.b.x) <= EPS:
                if self.a.y <= p.y and p.y <= self.b.y:
                    return True
            elif self.a.x <= p.x and p.x <= self.b.x:
                return True
        return False

    # find the projection of the given point "p" on the line segment , also to
    # find the projection of the line segment on the line segment
    def projection(self, p):

        # if the incoming p is a LineSegment
        if isinstance(p, Segment):
            return Segment(self.projection(p.a), self.projection(p.b))

        # if the point is same as a
        if p == self.a:
            return self.a
        # if the point is same as b
        if p == self.b:
            return self.b

        # if the point itself lies on the line segment return the point
        if self.is_parallel(Segment(self.a, p)):
            return p

        # shift self.Origin to a
        bn = Point(self.b.x - self.a.x, self.b.y - self.a.y)
        pn = Point(p.x - self.a.x, p.y - self.a.y)

        # form the unit vector
        bn = Point(bn.x / self.Origin.distance(bn),
                   bn.y / self.Origin.distance(bn))

        # find dot product
        t = bn.x * pn.x + bn.y * pn.y

        # find the projected point
        ans = Point(t * bn.x, t * bn.y)

        # translate back the self.Origin
        ans = Point(ans.x + self.a.x, ans.y + self.a.y)

        return ans

    def extendedintersection(self, ls):
        xdiff = (self.b.x - self.a.x, ls.b.x - ls.a.x)
        ydiff = (self.b.y - self.a.y, ls.b.y - ls.a.y)

        def det(a, b):
            return a[0] * b[1] - a[1] * b[0]

        div = det(xdiff, ydiff)

        if abs(div) <= EPS:
            return None

        d = (det(self.a.coordinates,
                 self.b.coordinates), det(ls.a.coordinates, ls.b.coordinates))
        x = det(d, xdiff) / div
        y = det(d, ydiff) / div
        return Point(-x, -y)

    def intersection(self, ls):
        p = self.extendedintersection(ls)

        if not p:
            return False

        if self.contains(p) and ls.contains(p):
            return True

        return False

    # case1
    # A --------------
    # B   ----------

    # case2
    # A     --------------
    # B   ----------------------

    # case3
    # A --------------
    # B   -----------------

    # case4
    # A         --------------
    # B   ----------

    def facinglength(self, ls):
        # if the 2 LineSegments are not parallel => they will intersect => facing length = 0
        if not self.is_parallel(ls):
            return Decimal(0)

        # take projection of ls on self
        ls = self.projection(ls)

        # if the lines are exact vertical
        if self.slope == Inf:
            if self.b.y < ls.a.y or ls.b.y < self.a.y:
                return Decimal(0)

            # case 1
            if self.a.y <= ls.a.y and ls.b.y <= self.b.y:
                return ls.length

            # case 2
            if ls.a.y <= self.a.y and self.b.y <= ls.b.y:
                return self.length

            # case 3
            if self.a.y <= ls.a.y and self.b.y <= ls.b.y:
                return ls.a.distance(self.b)

            # case 4
            if ls.a.y <= self.a.y and ls.b.y <= self.b.y:
                return self.a.distance(ls.b)

            # case facinglength is 0
            return Decimal(0)

        if self.b.x < ls.a.x or ls.b.x < self.a.x:
            return Decimal(0)

        # case 1
        if self.a.x <= ls.a.x and ls.b.x <= self.b.x:
            return ls.length

        # case 2
        if ls.a.x <= self.a.x and self.b.x <= ls.b.x:
            return self.length

        # case 3
        if self.a.x <= ls.a.x and self.b.x <= ls.b.x:
            return ls.a.distance(self.b)

        # case 4
        if ls.a.x <= self.a.x and ls.b.x <= self.b.x:
            return self.a.distance(ls.b)

        # case facinglength is 0
        return Decimal(0)

    def prependiculardistance(self, ls):

        # if the incoming is a point
        if isinstance(ls, Point):
            return ls.distance(self.projection(ls))

        if not self.is_parallel(ls):
            return Decimal(0)

        # if the incoming is a line segment
        return ls.a.distance(self.projection(ls.a))

    def printme(self):
        print "Line is ", float(self.a.x), float(self.a.y), float(
            self.b.x), float(self.b.y)
Beispiel #57
0
 def pointOrder(self):
     order = EllipticCurve(self.a, self.b, self.p).pointOrder(Point(self.Gx, self.Gy, 1))
     self._output.insert(END, "|G| = " + str(order) + "\n")
Beispiel #58
0
 def __init__(self, w, h):
     self.winWidth = w
     self.winHeight = h
     self.startPosition = Point(890, 565)  #start race position
     self.endPosition = None  # end race position
     #self.vectorMap = VectorMap()
     #self.TriangleList = self.vectorMap.triangleObjects
     self.TriangleList = [
         Triangle(Point(1270.0, 510.0), Point(890.0, 620.0),
                  Point(890.0, 510.0)),
         Triangle(Point(780.0, 510.0), Point(780.0, 620.0),
                  Point(700.0, 600.0)),
         Triangle(Point(1500.0, 500.0), Point(1390.0, 450.0),
                  Point(1410.0, 400.0)),
         Triangle(Point(1500.0, 500.0), Point(1410.0, 400.0),
                  Point(1530.0, 410.0)),
         Triangle(Point(1270.0, 510.0), Point(1270.0, 620.0),
                  Point(890.0, 620.0)),
         Triangle(Point(1270.0, 620.0), Point(1270.0, 510.0),
                  Point(1410.0, 580.0)),
         Triangle(Point(1410.0, 580.0), Point(1270.0, 510.0),
                  Point(1390.0, 450.0)),
         Triangle(Point(1390.0, 450.0), Point(1500.0, 500.0),
                  Point(1410.0, 580.0)),
         Triangle(Point(1520.0, 200.0), Point(1530.0, 410.0),
                  Point(1410.0, 400.0)),
         Triangle(Point(800.0, 220.0), Point(790.0, 330.0),
                  Point(550.0, 180.0)),
         Triangle(Point(90.0, 160.0), Point(170.0, 90.0),
                  Point(220.0, 190.0)),
         Triangle(Point(220.0, 190.0), Point(170.0, 90.0),
                  Point(330.0, 150.0)),
         Triangle(Point(90.0, 160.0), Point(220.0, 190.0),
                  Point(180.0, 230.0)),
         Triangle(Point(50.0, 290.0), Point(180.0, 230.0),
                  Point(160.0, 300.0)),
         Triangle(Point(180.0, 230.0), Point(50.0, 290.0),
                  Point(90.0, 160.0)),
         Triangle(Point(70.0, 440.0), Point(50.0, 290.0),
                  Point(160.0, 300.0)),
         Triangle(Point(450.0, 150.0), Point(320.0, 40.0),
                  Point(460.0, 40.0)),
         Triangle(Point(450.0, 150.0), Point(460.0, 40.0),
                  Point(600.0, 80.0)),
         Triangle(Point(450.0, 150.0), Point(330.0, 150.0),
                  Point(320.0, 40.0)),
         Triangle(Point(450.0, 150.0), Point(600.0, 80.0),
                  Point(550.0, 180.0)),
         Triangle(Point(320.0, 40.0), Point(330.0, 150.0),
                  Point(170.0, 90.0)),
         Triangle(Point(150.0, 560.0), Point(70.0, 440.0),
                  Point(180.0, 410.0)),
         Triangle(Point(180.0, 410.0), Point(70.0, 440.0),
                  Point(160.0, 300.0)),
         Triangle(Point(150.0, 560.0), Point(180.0, 410.0),
                  Point(240.0, 480.0)),
         Triangle(Point(240.0, 480.0), Point(280.0, 610.0),
                  Point(150.0, 560.0)),
         Triangle(Point(280.0, 610.0), Point(240.0, 480.0),
                  Point(310.0, 500.0)),
         Triangle(Point(280.0, 610.0), Point(310.0, 500.0),
                  Point(420.0, 580.0)),
         Triangle(Point(530.0, 500.0), Point(390.0, 470.0),
                  Point(510.0, 390.0)),
         Triangle(Point(570.0, 500.0), Point(570.0, 380.0),
                  Point(730.0, 490.0)),
         Triangle(Point(570.0, 380.0), Point(570.0, 500.0),
                  Point(530.0, 500.0)),
         Triangle(Point(530.0, 500.0), Point(420.0, 580.0),
                  Point(390.0, 470.0)),
         Triangle(Point(700.0, 600.0), Point(570.0, 500.0),
                  Point(730.0, 490.0)),
         Triangle(Point(510.0, 390.0), Point(570.0, 380.0),
                  Point(530.0, 500.0)),
         Triangle(Point(730.0, 490.0), Point(780.0, 510.0),
                  Point(700.0, 600.0)),
         Triangle(Point(390.0, 470.0), Point(420.0, 580.0),
                  Point(310.0, 500.0)),
         Triangle(Point(550.0, 180.0), Point(600.0, 80.0),
                  Point(800.0, 220.0)),
         Triangle(Point(1120.0, 110.0), Point(1260.0, 50.0),
                  Point(1270.0, 170.0)),
         Triangle(Point(1270.0, 170.0), Point(1260.0, 50.0),
                  Point(1330.0, 160.0)),
         Triangle(Point(1120.0, 110.0), Point(1270.0, 170.0),
                  Point(1170.0, 210.0)),
         Triangle(Point(930.0, 220.0), Point(1120.0, 110.0),
                  Point(1170.0, 210.0)),
         Triangle(Point(940.0, 330.0), Point(930.0, 220.0),
                  Point(1170.0, 210.0)),
         Triangle(Point(800.0, 220.0), Point(930.0, 220.0),
                  Point(940.0, 330.0)),
         Triangle(Point(1380.0, 170.0), Point(1350.0, 50.0),
                  Point(1440.0, 70.0)),
         Triangle(Point(1380.0, 170.0), Point(1440.0, 70.0),
                  Point(1490.0, 120.0)),
         Triangle(Point(1380.0, 170.0), Point(1330.0, 160.0),
                  Point(1350.0, 50.0)),
         Triangle(Point(1410.0, 210.0), Point(1520.0, 200.0),
                  Point(1410.0, 400.0)),
         Triangle(Point(1410.0, 210.0), Point(1380.0, 170.0),
                  Point(1490.0, 120.0)),
         Triangle(Point(1490.0, 120.0), Point(1520.0, 200.0),
                  Point(1410.0, 210.0)),
         Triangle(Point(1350.0, 50.0), Point(1330.0, 160.0),
                  Point(1260.0, 50.0)),
         Triangle(Point(940.0, 330.0), Point(790.0, 330.0),
                  Point(800.0, 220.0)),
         Triangle(Point(780.0, 620.0), Point(890.0, 510.0),
                  Point(890.0, 620.0)),
         Triangle(Point(890.0, 510.0), Point(780.0, 620.0),
                  Point(780.0, 510.0))
     ]
     self.checkLines = [[Point(940, 565), Point(940, 566)], [Point(990, 565), Point(990, 566)], \
                    [Point(1060, 560), Point(1060, 570)], [Point(1160, 570), Point(1160, 560)], \
                    [Point(1300, 560), Point(1300, 562)], [Point(1440, 490), Point(1440, 491)], \
                    [Point(1460, 430), Point(1460, 431)], [Point(1465, 330), Point(1465, 331)], \
                    [Point(1440, 160), Point(1440, 161)], [Point(1350, 100), Point(1350, 101)], \
                    [Point(1220, 130), Point(1220, 131)], [Point(1070, 200), Point(1070, 201)], \
                    [Point(850, 280), Point(850, 281)], [Point(680, 200), Point(680, 201)], \
                    [Point(500, 100), Point(500, 101)], [Point(300, 100), Point(300, 101)], \
                    [Point(150, 170), Point(150, 171)], [Point(110, 370), Point(110, 371)], \
                    [Point(200, 520), Point(200, 521)], [Point(420, 520), Point(420, 521)], \
                    [Point(560, 440), Point(560, 441)], [Point(750, 550), Point(750, 551)]]
Beispiel #59
0
def numcenter(id, points):
    number(id, sum(points, Point(0, 0)) / len(points))
Beispiel #60
0
def import_point(row):
    c = np.array([row['X'],row['Y'],row['Z']], dtype='f')
    n = np.array([row['I'],row['J'],row['K']], dtype='f')
    d = np.array([row['Dir X'],row['Dir Y'],row['Dir Z']], dtype='f')
    return Point(c,n,d)