Beispiel #1
0
def add():
    exp.append(
        SS(
            "file:///C:/Users/Couga/Documents/repos/twenty-four/milestone4/explosion-spritesheet.png",
            (9, 9),
            Vector(random.randrange(100, 400), random.randrange(100, 400)), 72,
            random.randrange(500, 2000), random.uniform(0.1, 0.4)))
Beispiel #2
0
 def __init__(self):
     self.hook = Hook(Vector(250, 250))
     self.line = Line(200, (251, 100), 2, self.hook)
     self.length = math.sqrt((self.line.begin[0] - self.line.end[0]) *
                             (self.line.begin[0] - self.line.end[0]) +
                             (self.line.begin[1] - self.line.end[1]) *
                             (self.line.begin[1] - self.line.end[1]))
Beispiel #3
0
 def __init__(self, pos, radius=10):
     self.pos = pos
     self.vel = Vector()
     self.radius = max(radius, 10)
     self.colour = 'White'
     self.rot = 0
     self.on_ground = True
Beispiel #4
0
 def test_pressure(self):
     
     earth = Earth()  
     pos = Vector([0.0, earth.radius, 0.0])
     p, d = earth.air_pressure_and_density(pos)
     print(p,d)
     self.assertTrue( p >= 101e3 and p < 102e3 )
Beispiel #5
0
def plot_air_pressure_to_alt( body, altitude ):
    altitude_list = []
    air_pressure_list = []
    density_list = []
    pos = Vector()

    steps = 1000
    for i in range(steps+1):
        alt = i * altitude / ( steps )
        pos[2] = body.radius + alt
        altitude_list.append( alt )
        P0, density = body.air_pressure_and_density( pos )
        air_pressure_list.append ( P0 )
        density_list.append ( density )

    fig = plt.figure()

    fig.suptitle('Air pressure at altitude')  # Add a title so we know which it is
    ax = fig.subplots(1,1)
    ax2 = ax.twinx()
    ax.plot(altitude_list, air_pressure_list, 'r')
    ax2.plot(altitude_list, density_list, 'b')
    ax.set_xlabel("Altitude [m]")
    ax.set_ylabel("Air pressure $Pa$")
    ax2.set_ylabel("Air density $kg/m^3$")
    ax2.yaxis.label.set_color("blue")
    ax.set_yscale('log')
    ax2.set_yscale('log')
    ax.grid()
    plt.show()        
Beispiel #6
0
 def update(self):
     self.back.update()
     #self.fish.update()
     self.rod.catch_fish(self.fish)
     if self.player.inBounds():
         if self.keyboard.right:
             self.player.addVel(Vector(1, 0) * 40)
         elif self.keyboard.left:
             self.player.addVel(Vector(-1, 0) * 40)
         elif self.keyboard.down:
             self.rod.down()
     else:
         self.player.set()
     if self.player.vel.length() > 5:
         #checks whether player has moved and so fish would be released
         self.rod.playermoved()
     self.player.update()
Beispiel #7
0
 def allign(self,fish):
     if len(fish) < 1:
         return
     # calculate the average velocities of the other boids
     avg = Vector()
     count = 0
     for boid in fish:
         if(boid.pos - self.pos).length()<self.per:
             count+=1
             avg += boid.vel
     
     if count>0:
         avg = avg.divide(count)		
         # set our velocity towards the others
         return (avg).normalize()
     else:
         return Vector()
Beispiel #8
0
 def test_velocity(self):
     
     earth = Earth()  
     pos = Vector([0.0, earth.radius, 0.0])
     velocity = earth.surface_speed(pos)
     #print(velocity)
     v = velocity.magnitude
     self.assertTrue( v >=  460 and v <= 465 )
Beispiel #9
0
 def accelleration(self, position):
     
     radius = position.magnitude
     v = Vector( position )
     a = -( self.__mass * constants.G) / (radius*radius)
     v.mult( a / position.magnitude )
     
     return v
Beispiel #10
0
    def seperation(self,fish, minDistance):
        if len(fish) < 1:
            return Vector()

        distance = 0
        numClose = 0
        distsum = Vector()
        for boid in fish:
            distance = (self.pos-boid.pos).length()
            if  distance < minDistance and distance != 0:
                numClose += 1
                distsum += (boid.pos-self.pos).divide(distance**2)

        if numClose == 0:
            return Vector()

        return  (-distsum.divide(numClose)).normalize()
Beispiel #11
0
 def vector(self):
     """ compute its directional unit vector. """
     # @caution: always check length before compute vector!
     # @todo : check if vector length = 0
     if self.length() == 0:
         return (Vector(random.uniform(0.01, 0.09), random.uniform(0.01, 0.09), 0))
     else:
         return self.twin.origin.coord.substract(self.origin.coord).normalize()
Beispiel #12
0
    def __init__(self, time, dim, die, frame):
        self.score = 0
        self.time = time
        self.maxtime = 99.999
        self.starttime = self.time.time()
        self.scoreh = 30
        self.timeh = 20
        self.padding = 5
        self.size = Vector(
            frame.get_canvas_textwidth("Score: " + '{:04d}'.format(self.score),
                                       self.scoreh, "sans-serif") +
            self.padding * 2, self.padding * 2 + self.scoreh + self.timeh)
        self.pos = Vector(((Vector(dim[0], dim[1]) - self.size) / 2).x, 0)

        #reference to overlay class for if game ends
        self.die = die
        self.sound = Snd(self.time, "point.ogg", 0.5)
Beispiel #13
0
    def faceCenterPoint(self, f):
        """ get center Point for face f. """
        pts = self.facePoints(f)
        # print(pts[:,0])
        # print(pts[:,1])
        tpt = pts.sum(axis=0) # sum over all x and all y and get total pt

        # calculate averge and return
        return Vector(tpt[0]/(pts[:,0].size), tpt[1]/(pts[:,1].size), 0)
Beispiel #14
0
 def update(self):
     global scroll
     self.pos.add(self.vel)
     scroll.add(self.vel)
     self.vel.x *= 0.85
     self.rot = self.pos.x / (self.radius)
     if self.pos.x < 0:
         self.pos.add(Vector(WIDTH, 0))
     elif self.pos.x > WIDTH:
         self.pos.add(Vector(-WIDTH, 0))
     if not self.on_ground:
         self.vel.add(Vector(0, 2))
         if self.pos.y + self.radius > HEIGHT:
             self.pos.y = HEIGHT - self.radius
             self.vel.y *= -0.6
             if self.vel.length() < 10:
                 self.on_ground = True
                 self.vel.y = 0
Beispiel #15
0
    def cohesion(self,fish):
        if len(fish) < 1:
            return

        # calculate the average distances from the other boids
        com = Vector()
        count = 0
        for boid in fish:
            if boid.pos == self.pos:
                continue
            elif (boid.pos - self.pos).length()<self.per:
                com += (self.pos - boid.pos)
                count+=1
        if count>0:
            com = com.divide(count)
            return -com.normalize()
        else:
            return Vector()
Beispiel #16
0
    def __init__(self, stages, max_force, position, orientation = None):

        self.__stages = stages
        self.__current_stage = 0
        self.__max_force = max_force
        self.__position = position
        

        if orientation == None:
            # pick orientation orthogonal to surface.
            self.__orientation = self.__position.deepcopy().normalize()            
        else:
            self.__orientation = orientation

        self.__velocity = Vector()
        self.__drag = Vector()
        self.__thrust = Vector()
        self.__throttle = 0.0
Beispiel #17
0
 def __init__(self,pos,bounds,imgr,imgl):
     self.bounds = bounds
     self.max_vel = 75
     self.imgr = imgr 
     self.imgl = imgl
     self.size = 25
     self.per = self.size*3
     self.pos = pos
     angle = random.random()*math.pi*2
     self.vel = Vector(math.cos(angle),math.sin(angle)) * 20
Beispiel #18
0
def centerPtTest():
    AnnoPt = Vector(0,0,0)
    points= [(0,0), (10,0), (10,10), (0,10)]

    for pt in points:
        AnnoPt.x += pt[0]
        AnnoPt.y += pt[1]
    AnnoPt.x = AnnoPt.x / len(points)
    AnnoPt.y = AnnoPt.y / len(points)
    print(AnnoPt)
Beispiel #19
0
 def draw(self,canvas,center=(-1,-1),size=(-1,-1),rotation=0):
     self.fno = round((time.time()%(self.time/1000))/(self.time/1000)*(self.framecount-1))
     x = self.fno  % self.size[0]
     y = (self.fno - x)/self.size[0]
     if center[0] < 0:
         center = self.pos.get_p()
     if size[0] <0:
         size =(self.adim[0]*self.scale,self.adim[1]*self.scale)
     loc = Vector(x*self.adim[0],y*self.adim[1])
     canvas.draw_image(self.img,(self.cent+loc).get_p(),self.adim,center,size,rotation)
Beispiel #20
0
	def catch_fish(self,school):
		if self.moveable():
			self.moved = False#check wether the boat can be moved
		if self.direction != 0:
			#if the hook is moving through the water 
			if not self.moved:
				#catch the fish if allowed 
				self.courtFish = self.mergerlist(self.courtFish,school.touching_fish(self.hookpos()[0],10))
			#move the fish to the new hook position
			school.move_fish(self.hookpos()[0],self.courtFish,self.hookvel())
		else:
			#if the hook is stationary and has realed in fish
			for fish in self.courtFish:
				if type(fish) != Shark:
					#animate each fish to the bucket
					fish.animstart(self.player.getPos()-Vector(30,-25))
				else:
					fish.animstart(self.player.getPos()+Vector(8,-25))
				self.flyingFish.append(fish)#move the fish to the flying fish list to keep track of them
			self.courtFish = []#remove all fish from the hook. 
Beispiel #21
0
def draw(canvas):
	global lasttime,t
	if (time.time() - lasttime) > 1/50:
		if cam.rays>Camera.WIDTH/10:
			cam.rays -=1
	elif(time.time() - lasttime) < 1/60:
		if cam.rays < Camera.WIDTH:
			cam.rays +=1
	lasttime = time.time()
	#cam.rot +=0.2
	cam.draw(canvas,lines,kbd.draw)
	if kbd.draw:
		for i in lines:
			if cam.insidefov(i):
				i.draw(canvas)
			else:
				i.draw(canvas,"red")
	else:
		canvas.draw_circle(cam.project(Vector(300,100)),5,2,"blue","blue")
		canvas.draw_circle(cam.project(Vector(300,200)),5,2,"blue","blue")
Beispiel #22
0
    def __init__(self, dimensions, time):
        self.time = time
        self.lastFrameTime = self.time.time()
        self.canvas_dim = dimensions

        #address needed to gain local directory to access images folder below
        addr = os.getcwd()

        ##image info + dimensions (constants)
        self.img = simplegui.load_image("file:///" + addr +
                                        "/images/boat2.png")
        self.dim = (4096, 4096)
        self.cen = (self.dim[0] / 2, self.dim[1] / 2)
        self.draw_dim = (140, 160)
        self.y_offset = 80

        ##player position and velocity
        self.pos = Vector(
            self.draw_dim[0] / 2,
            self.draw_dim[1] / 5 + self.canvas_dim[1] * 0.3 - self.y_offset)
        self.vel = Vector(0, 0)
Beispiel #23
0
 def __init__(self, count, dim):
     self.fish = []
     random.seed(time.time())
     self.imgr = SpriteSheet(
         "https://raw.githubusercontent.com/CougarTasker/twenty-four/master/proto/images/right.png",
         (2, 2),
         time=400,
         scale=0.2)
     self.imgl = SpriteSheet(
         "https://raw.githubusercontent.com/CougarTasker/twenty-four/master/proto/images/left.png",
         (2, 2),
         time=400,
         scale=0.2)
     for i in range(count):
         self.fish.append(
             Fsh(
                 Vector(random.random() * dim[0],
                        random.random() * dim[1]),
                 Bounds(Vector(0, 0.325 * dim[1]),
                        Vector(dim[0], dim[1] * 0.675)), self.imgr,
                 self.imgl))
Beispiel #24
0
    def __init__(self, x, border, color, direction="t"):

        directions = ["r", "l", "t", "b"]
        if (not direction in directions):
            direction = directions[0]
            print("error incorrect direction given")
        if (direction == "r"):
            self.normal = Vector(-1, 0)
        elif (direction == "l"):
            self.normal = Vector(1, 0)
        elif (direction == "t"):
            self.normal = Vector(0, 1)
        else:
            self.normal = Vector(0, -1)
        if self.vert():
            self.y = x
        else:
            self.x = x
        self.direction = direction
        self.border = border
        self.color = color
Beispiel #25
0
 def __init__(self,
              url,
              size=(1, 1),
              pos=Vector(),
              framecount=-1,
              time=1000,
              scale=1):
     if framecount == -1:
         framecount = size[0] * size[1]
     self.framecount = framecount
     self.url = url
     self.size = size
     self.img = simplegui.load_image(url)
     self.bdim = Vector(self.img.get_width(),
                        self.img.get_height())  # before dimentions
     self.adim = (self.bdim.x / self.size[0], self.bdim.y / self.size[1]
                  )  # after dimaentions
     self.cent = Vector(self.adim[0] / 2, self.adim[1] / 2)
     self.fno = 0
     self.time = time
     self.pos = pos
     self.scale = scale
Beispiel #26
0
 def draw(self,canvas):
     #canvas.draw_circle(self.pos.get_p(),4,1,"red","red")
     
     a = self.vel.angle(Vector(0,1))
     if self.vel.x > 0: 
         a *= -1 
         img = self.imgr
         a += math.pi/2
     else:
         a -= math.pi/2
         img = self.imgl
     
     img.pos = self.pos
     img.draw(canvas,rotation=a)
Beispiel #27
0
 def __init__(self,
              pos=Vector(WIDTH / 2, HEIGHT / 2),
              fov=60,
              zoom=10,
              rotation=0,
              height=50,
              rays=50,
              vrot=0):
     self.fov = fov
     self.height = height
     self.rays = rays
     self.vrot = vrot
     self.pos = pos
     self.rot = rotation
     self.zoom = zoom
Beispiel #28
0
 def vline(self, dist, wallheight):
     print(dist)
     ph = self.zoom * math.tan(self.fov) * HEIGHT / WIDTH
     va = (Vector(self.zoom, ph)).rotate(self.vrot)
     vb = (Vector(self.zoom, -ph)).rotate(self.vrot)
     plane = Line(vb, va)
     top = Line(Vector(), Vector(dist, wallheight - self.height))
     bottom = Line(Vector(), Vector(dist, -self.height))
     return [
         plane.dist(top, False)[1] / (2 * ph) * HEIGHT,
         plane.dist(bottom, False)[1] / (2 * ph) * HEIGHT
     ]
Beispiel #29
0
	def vline(self,dist,wallheight,y):
		ph = self.zoom*math.tan(self.fov*math.pi/360)*self.HEIGHT/self.WIDTH
		va = (Vector(self.zoom,ph)).rotate(self.vrot)
		vb = (Vector(self.zoom,-ph)).rotate(self.vrot)
		plane = Line(va,vb)
		top = Line(Vector(),Vector(dist,y+wallheight-self.height))
		bottom = Line(Vector(),Vector(dist,y-self.height))

		bd = plane.dist(bottom,False)
		td = plane.dist(top,False)
		if (bd[0] == -1 or td[0] == -1):
			return [-1,-1] 
		return [bd[1]/(2*ph)*self.HEIGHT,td[1]/(2*ph)*self.HEIGHT]
Beispiel #30
0
def pysloop():
	if kbd.left:
		cam.rot -=1.5
	if kbd.right:
		cam.rot +=1
	mv = Vector()
	if kbd.a:
		mv.y -= 1
	if kbd.d:
		mv.y += 1
	if kbd.w:
		mv.x += 1
	if kbd.s:
		mv.x -= 1
	if kbd.up:
		cam.rays +=1
	if kbd.down:
		cam.rays -=1
	cam.move(mv)
	cam.colides(lines)