MCPcopy Index your code
hub / github.com/python/cpython / Star

Class Star

Lib/turtledemo/planet_and_moon.py:35–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33 p.step()
34
35class Star(Turtle):
36 def __init__(self, m, x, v, gravSys, shape):
37 Turtle.__init__(self, shape=shape)
38 self.penup()
39 self.m = m
40 self.setpos(x)
41 self.v = v
42 gravSys.planets.append(self)
43 self.gravSys = gravSys
44 self.resizemode("user")
45 self.pendown()
46 def init(self):
47 dt = self.gravSys.dt
48 self.a = self.acc()
49 self.v = self.v + 0.5*dt*self.a
50 def acc(self):
51 a = Vec(0,0)
52 for planet in self.gravSys.planets:
53 if planet != self:
54 v = planet.pos()-self.pos()
55 a += (G*planet.m/abs(v)**3)*v
56 return a
57 def step(self):
58 dt = self.gravSys.dt
59 self.setpos(self.pos() + dt*self.v)
60 if self.gravSys.planets.index(self) != 0:
61 self.setheading(self.towards(self.gravSys.planets[0]))
62 self.a = self.acc()
63 self.v = self.v + dt*self.a
64
65## create compound yellow/blue turtleshape for planets
66

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…