1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
from math import *
import pygame,sys
m = (3.302E23,1.9891E30)
xcoord = [0.0579E12,0]
ycoord = [0,0]
v = [-47864.122098284774,0.0]
vhoek = [radians(90),0]
vx = []
vy = []
G = 6.6726E-11
dt = 500
i = 0
while i < len(m):
vx.append(cos(vhoek[i])*v[i])
vy.append(sin(vhoek[i])*v[i])
i += 1
pygame.init()
size = (600,600)
zwart = (0,0,0)
wit = (255,255,255)
screen = pygame.display.set_mode(size)
screen.fill(zwart)
bla = 0
while 1:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN and event.key == pygame.K_q:
sys.exit()
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
while 1:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
bla = 1
if bla == 1:
bla = 0
break
i = 0
while i < len(m):
j = 0
while j < len(m):
if not j==i:
onderling = ((xcoord[i]-xcoord[j])**2 + (ycoord[i]-ycoord[j])**2)**0.5
F = (G*m[i]*m[j])/(onderling**2)
a = F/m[i]
if ycoord[i]-ycoord[j] == 0:
if xcoord[i]-xcoord[j] < 0:
fhoek = 0
if xcoord[i]-xcoord[j] > 0:
fhoek = radians(180)
elif xcoord[i]-xcoord[j] == 0:
if ycoord[i]-ycoord[j] < 0:
fhoek = radians(90)
if ycoord[i]-ycoord[j] > 0:
fhoek = radians(270)
else:
fhoek = atan((ycoord[i]-ycoord[j])/(xcoord[i]-xcoord[j]))
#als de andere massa links onder deze massa ligt:
if xcoord[i]-xcoord[j] > 0 and ycoord[i]-ycoord[j] > 0:
fhoek += radians(180)
#print "linksonder",i
#als de andere massa linksboven deze massa ligt:
if xcoord[i]-xcoord[j] > 0 and ycoord[i]-ycoord[j] < 0:
fhoek += radians(180)
#print "linksboven",i
#als de andere massa rechtsonder deze massa ligt:
if xcoord[i]-xcoord[j] < 0 and ycoord[i]-ycoord[j] > 0:
fhoek += radians(0)
#print "rechstonder",i
#als de andere massa rechtsboven deze massa ligt:
if xcoord[i]-xcoord[j] < 0 and ycoord[i]-ycoord[j] < 0:
fhoek += radians(0)
#print "rechtsboven",i
#als de andere massa links deze massa ligt:
if xcoord[i]-xcoord[j] > 0 and ycoord[i]-ycoord[j] == 0:
fhoek += radians(180)
#als de andere massa rechts van deze massa ligt:
if xcoord[i]-xcoord[j] < 0 and ycoord[i]-ycoord[j] == 0:
fhoek += radians(0)
#als de andere massa boven deze massa ligt:
if xcoord[i]-xcoord[j] == 0 and ycoord[i]-ycoord[j] < 0:
fhoek += radians(0)
#als de andere massa onder deze massa ligt:
#if xcoord[i]-xcoord[j] == 0 and ycoord[i]-ycoord[j] > 0:
#fhoek += radians(
#print "pal onder"
ax = cos(fhoek)*a
ay = sin(fhoek)*a
dvx = ax * dt
dvy = ay * dt
xcoord[i] += vx[i] * dt
ycoord[i] += vy[i] * dt
vx[i] += dvx
vy[i] += dvy
j += 1
i += 1
i = 0
while i < len(m):
pygame.draw.circle(screen,wit,((xcoord[i]*(300/0.1083E12)+300),(ycoord[i]*(300/0.1083E12)+300)),2,0)
i += 1
pygame.display.flip()
|