Exemple #1
0
def main():
    boucle = 1
    running = False
    trace = False
    x, y, m = physics.barycentre([pi, po])
    while boucle:
        for event in pygame.event.get():
            if event.type == QUIT:
                boucle = 0
            if event.type == KEYDOWN:
                if event.key == K_SPACE:
                    running = obool(running)
                if event.key == K_t:
                    trace = obool(trace)

        if running:
            pi.tick()
            po.tick()
            x, y, m = physics.barycentre([pi, po])
        if not trace:
            fen.fill((255, 255, 255))
        pygame.draw.circle(fen, (0, 0, 0), (int(po.posx), int(po.posy)),
                           po.mass)
        pygame.draw.circle(fen, (0, 0, 0), (int(pi.posx), int(pi.posy)),
                           pi.mass)
        pygame.draw.circle(fen, (0, 100, 0), (int(x), int(y)), 2)

        pygame.draw.line(fen,
                         (254 * (1 - math.exp(-pi.distance(po) / 160)), 0, 0),
                         (int(po.posx), int(po.posy)),
                         (int(pi.posx), int(pi.posy)))

        pygame.display.flip()
Exemple #2
0
def main():
	boucle = 1
	running = False
	trace = False
	x,y,m = physics.barycentre([pi,po])
	while boucle:
		for event in pygame.event.get():
			if event.type == QUIT:
				boucle = 0
			if event.type == KEYDOWN:
				if event.key == K_SPACE:
					running = obool(running)	
				if event.key == K_t:
					trace = obool(trace)
					
		if running: 
			pi.tick()
			po.tick()
			x,y,m = physics.barycentre([pi,po])
		if not trace:
			fen.fill((255,255,255))
		pygame.draw.circle(fen,(0,0,0),(int(po.posx),int(po.posy)),po.mass)
		pygame.draw.circle(fen,(0,0,0),(int(pi.posx),int(pi.posy)),pi.mass)
		pygame.draw.circle(fen,(0,100,0),(int(x),int(y)),2)

		pygame.draw.line(fen,(254*(1-math.exp(-pi.distance(po)/160)),0,0),(int(po.posx),int(po.posy)),(int(pi.posx),int(pi.posy)))
		
		pygame.display.flip()
Exemple #3
0
def main():
    boucle = 1
    running = False
    trace = False
    while boucle:
        for event in pygame.event.get():
            if event.type == QUIT:
                boucle = 0
            if event.type == KEYDOWN:
                if event.key == K_SPACE:
                    running = obool(running)
                if event.key == K_t:
                    trace = obool(trace)

        if not trace:
            fen.fill((255, 255, 255))
        for i in systeme.objectlist:
            pygame.draw.circle(fen, (0, 0, 0), (int(i.posx), int(i.posy)),
                               i.mass / 40000)

        bar = physics.barycentre(systeme.objectlist)
        x, y, m = bar
        pygame.draw.circle(fen, (0, 128, 0), (int(x), int(y)), 5)

        if running:
            systeme.update()

        pygame.display.flip()
Exemple #4
0
def main():
    boucle = 1
    running = False
    trace = False
    while boucle:
        for event in pygame.event.get():
            if event.type == QUIT:
                boucle = 0
            if event.type == KEYDOWN:
                if event.key == K_SPACE:
                    running = obool(running)
                if event.key == K_t:
                    trace = obool(trace)

        if not trace:
            fen.fill((255, 255, 255))
        i = systeme.objectlist[0]
        pygame.draw.circle(fen, (128, 0, 0), (int(i.posx), int(i.posy)), 10)
        j = systeme.objectlist[1]
        pygame.draw.circle(fen, (0, 0, 128), (int(j.posx), int(j.posy)), 10)

        bar = physics.barycentre(systeme.objectlist)
        x, y, m = bar
        pygame.draw.circle(fen, (0, 128, 0), (int(x), int(y)), 5)

        if running:
            #start = time.time()
            systeme.update_euler()
            #print time.time() - start

        pygame.display.flip()
Exemple #5
0
def main():
    boucle = 1
    running = False
    trace = False
    while boucle:
        for event in pygame.event.get():
            if event.type == QUIT:
                boucle = 0
            if event.type == KEYDOWN:
                if event.key == K_UP:
                    boost.x, boost.y = +pichenette * math.sin(
                        rad), -pichenette * math.cos(rad)
                if event.key == K_RIGHT:
                    planete2.omega += 2
                if event.key == K_LEFT:
                    planete2.omega -= 2
                if event.key == K_DOWN:
                    boost.x, boost.y = -pichenette * math.sin(
                        rad), +pichenette * math.cos(rad)
                if event.key == K_SPACE:
                    running = obool(running)
                if event.key == K_t:
                    trace = obool(trace)
            if event.type == KEYUP:
                if event.key == K_UP or event.key == K_DOWN:
                    boost.x, boost.y = 0, 0

        rad = degtorad(planete2.theta)

        if running:
            planete2.tick()
            planete.tick()

        G = physics.barycentre([planete, planete2])
        x, y, m = G

        if not trace:
            fen.fill((255, 255, 255))
        pygame.draw.circle(fen, (0, 128, 0), (int(x), int(y)), 5)
        pygame.draw.circle(fen, (0, 0, 0),
                           (int(planete.posx), int(planete.posy)), 5)
        pygame.draw.circle(fen, (0, 0, 0),
                           (int(planete2.posx), int(planete2.posy)), 2)

        pygame.display.flip()
Exemple #6
0
def main():
	boucle = 1
	running = False
	trace = False
	while boucle:
		for event in pygame.event.get():
			if event.type == QUIT:
				boucle = 0
			if event.type == KEYDOWN:
				if event.key == K_UP:
					boost.x, boost.y  = +pichenette*math.sin(rad),-pichenette*math.cos(rad)
				if event.key == K_RIGHT:
					planete2.omega += 2
				if event.key == K_LEFT:
					planete2.omega -= 2
				if event.key == K_DOWN:
					boost.x, boost.y  = -pichenette*math.sin(rad),+pichenette*math.cos(rad)
				if event.key == K_SPACE:
					running = obool(running)	
				if event.key == K_t:
					trace = obool(trace)
			if event.type == KEYUP:
				if event.key == K_UP or event.key == K_DOWN:
					boost.x, boost.y  = 0,0
					
		rad = degtorad(planete2.theta)
		
		if running: 
			planete2.tick()
			planete.tick()
			
		G = physics.barycentre([planete,planete2])
		x,y,m = G
		
		if not trace:
			fen.fill((255,255,255))
		pygame.draw.circle(fen,(0,128,0),(int(x),int(y)),5)
		pygame.draw.circle(fen,(0,0,0),(int(planete.posx),int(planete.posy)),5)
		pygame.draw.circle(fen,(0,0,0),(int(planete2.posx),int(planete2.posy)),2)
		
		pygame.display.flip()
Exemple #7
-1
def main():
	boucle = 1
	running = False
	trace = False
	while boucle:
		for event in pygame.event.get():
			if event.type == QUIT:
				boucle = 0
			if event.type == KEYDOWN:
				if event.key == K_SPACE:
					running = obool(running)	
				if event.key == K_t:
					trace = obool(trace)
			
			
		if not trace:	
			fen.fill((255,255,255))
		for i in systeme.objectlist:
		
			pygame.draw.circle(fen,(0,0,0),(int(i.posx),int(i.posy)),1)
		
		
		bar = physics.barycentre(systeme.objectlist)
		x,y,m = bar
		pygame.draw.circle(fen,(0,128,0),(int(x),int(y)),5)
		
		if running:
			start = time.time()
			systeme.update()
			end = time.time()
			print end - start
			
		pygame.display.flip()