Skip to content

Commit 6e77058

Browse files
committed
Many changes
1 parent 4f43d06 commit 6e77058

File tree

11 files changed

+238
-81
lines changed

11 files changed

+238
-81
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ empty.pkl和spacecraft.pkl:solar_system.py使用pickle库存储天体数据,
4040
TESTs/solar_system_accelerate.py:使用C语言扩展提升计算的性能(经作者测试,与solar_system.py相比,速度约提升22~45倍),并增加了二阶龙格库塔法
4141
TESTs/solar_system_particles.py:使用更快的“粒子”计算小行星,用于提升计算性能(备用)
4242
TESTs/solar_system_blackhole1.py:行星掉入黑洞的模拟1
43-
TESTs/solar_system_blackhole2.py:行星掉入黑洞的模拟2(包含了turtle模块绘制旋转图片的技巧,[这篇文章](https://blog.csdn.net/qfcy_/article/details/120584657)
43+
TESTs/solar_system_blackhole2.py:行星掉入黑洞的模拟2,包含对turtle模块函数的修改和补丁,如turtle模块绘制旋转图片([这篇文章](https://blog.csdn.net/qfcy_/article/details/120584657)
4444
TESTs/solar_system_blackhole3.py:第3个行星掉入黑洞的模拟
4545
TESTs/solar_system_hill_sphere.py:[希尔球](https://baike.baidu.com/item/%E5%B8%8C%E5%B0%94%E7%90%83)[拉格朗日点](https://baike.baidu.com/item/%E6%8B%89%E6%A0%BC%E6%9C%97%E6%97%A5%E7%82%B9/731078) 现象模拟。希尔球指卫星到行星的距离不能超过最大值,也就是前面的第二张动图
4646
TESTs/solar_system_binary_star.py:双星系统模拟

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ TESTs/solar_system_particles.py:使用更快的“粒子”计算小行星,
6767

6868
TESTs/solar_system_blackhole1.py:行星掉入黑洞的模拟1
6969

70-
TESTs/solar_system_blackhole2.py:行星掉入黑洞的模拟2(包含了turtle模块绘制旋转图片的技巧,
70+
TESTs/solar_system_blackhole2.py:行星掉入黑洞的模拟2,包含对turtle模块函数的修改和补丁,如turtle模块绘制旋转图片(
7171
`这篇文章 <https://blog.csdn.net/qfcy_/article/details/120584657>`__\
7272

7373
TESTs/solar_system_blackhole3.py:第3个行星掉入黑洞的模拟

build/lib.win32-cpython-37/solar_system/TESTs/solar_system_blackhole2.py

Lines changed: 116 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
__version__="1.3.3"
2828

2929
## -- 重写turtle模块中的函数,在turtle模块源码的基础上加以修改 --
30+
# 由于turtle模块极少更新,修改的函数几乎不会在新版Python中不兼容
3031
images={} # 用于创建图像的引用
3132
def _image(self,filename):
3233
img=Image.open(filename)
@@ -90,44 +91,117 @@ def register_shape(self, name, shape=None):
9091
self._shapes[name] = shape
9192

9293
def _drawturtle(self):
93-
"""Manages the correct rendering of the turtle with respect to
94-
its shape, resizemode, stretch and tilt etc."""
95-
screen = self.screen
96-
shape = screen._shapes[self.turtle.shapeIndex]
97-
ttype = shape._type
98-
titem = self.turtle._item
99-
if self._shown and screen._updatecounter == 0 and screen._tracing > 0:
100-
self._hidden_from_screen = False
101-
tshape = shape._data
102-
if ttype == "polygon":
103-
if self._resizemode == "noresize": w = 1
104-
elif self._resizemode == "auto": w = self._pensize
105-
else: w =self._outlinewidth
106-
shape = self._polytrafo(self._getshapepoly(tshape))
107-
fc, oc = self._fillcolor, self._pencolor
108-
screen._drawpoly(titem, shape, fill=fc, outline=oc,
109-
width=w, top=True)
110-
elif ttype == "image":
111-
screen._drawimage(titem, self._position, tshape,
112-
self.heading(),self._stretchfactor[0])
113-
elif ttype == "compound":
114-
for item, (poly, fc, oc) in zip(titem, tshape):
115-
poly = self._polytrafo(self._getshapepoly(poly, True))
116-
screen._drawpoly(item, poly, fill=self._cc(fc),
117-
outline=self._cc(oc), width=self._outlinewidth, top=True)
118-
else:
119-
if self._hidden_from_screen:
120-
return
121-
if ttype == "polygon":
122-
screen._drawpoly(titem, ((0, 0), (0, 0), (0, 0)), "", "")
123-
elif ttype == "image":
124-
screen._drawimage(titem, self._position,
125-
screen._shapes["blank"]._data)
126-
if titem in images:del images[titem] # 如果已隐藏,则释放图像引用
127-
elif ttype == "compound":
128-
for item in titem:
129-
screen._drawpoly(item, ((0, 0), (0, 0), (0, 0)), "", "")
130-
self._hidden_from_screen = True
94+
"""Manages the correct rendering of the turtle with respect to
95+
its shape, resizemode, stretch and tilt etc."""
96+
screen = self.screen
97+
shape = screen._shapes[self.turtle.shapeIndex]
98+
ttype = shape._type
99+
titem = self.turtle._item
100+
if self._shown and screen._updatecounter == 0 and screen._tracing > 0:
101+
self._hidden_from_screen = False
102+
tshape = shape._data
103+
if ttype == "polygon":
104+
if self._resizemode == "noresize": w = 1
105+
elif self._resizemode == "auto": w = self._pensize
106+
else: w =self._outlinewidth
107+
shape = self._polytrafo(self._getshapepoly(tshape))
108+
fc, oc = self._fillcolor, self._pencolor
109+
screen._drawpoly(titem, shape, fill=fc, outline=oc,
110+
width=w, top=True)
111+
elif ttype == "image":
112+
screen._drawimage(titem, self._position, tshape,
113+
self.heading(),self._stretchfactor[0])
114+
elif ttype == "compound":
115+
for item, (poly, fc, oc) in zip(titem, tshape):
116+
poly = self._polytrafo(self._getshapepoly(poly, True))
117+
screen._drawpoly(item, poly, fill=self._cc(fc),
118+
outline=self._cc(oc), width=self._outlinewidth, top=True)
119+
else:
120+
if self._hidden_from_screen:
121+
return
122+
if ttype == "polygon":
123+
screen._drawpoly(titem, ((0, 0), (0, 0), (0, 0)), "", "")
124+
elif ttype == "image":
125+
screen._drawimage(titem, self._position,
126+
screen._shapes["blank"]._data)
127+
if titem in images:del images[titem] # 如果已隐藏,则释放图像引用
128+
elif ttype == "compound":
129+
for item in titem:
130+
screen._drawpoly(item, ((0, 0), (0, 0), (0, 0)), "", "")
131+
self._hidden_from_screen = True
132+
133+
def _drawline(self, lineitem, coordlist=None,
134+
fill=None, width=None, top=False):
135+
"""Configure lineitem according to provided arguments:
136+
coordlist is sequence of coordinates
137+
fill is drawing color
138+
width is width of drawn line.
139+
top is a boolean value, which specifies if polyitem
140+
will be put on top of the canvas' displaylist so it
141+
will not be covered by other items.
142+
"""
143+
if coordlist is not None:
144+
cl=(value for coord in coordlist for value in
145+
(coord[0] * self.xscale, -coord[1] * self.yscale)) # 迭代器
146+
self.cv.coords(lineitem, *cl)
147+
if fill is not None:
148+
self.cv.itemconfigure(lineitem, fill=fill)
149+
if width is not None:
150+
self.cv.itemconfigure(lineitem, width=width)
151+
if top:
152+
self.cv.tag_raise(lineitem)
153+
154+
def _goto(self, end): # 优化绘制较长天体轨道的性能
155+
"""Move the pen to the point end, thereby drawing a line
156+
if pen is down. All other methods for turtle movement depend
157+
on this one.
158+
"""
159+
## Version with undo-stuff
160+
go_modes = ( self._drawing,
161+
self._pencolor,
162+
self._pensize,
163+
isinstance(self._fillpath, list))
164+
screen = self.screen
165+
undo_entry = ("go", self._position, end, go_modes,
166+
(self.currentLineItem,
167+
self.currentLine[:],
168+
screen._pointlist(self.currentLineItem),
169+
self.items[:])
170+
)
171+
if self.undobuffer:
172+
self.undobuffer.push(undo_entry)
173+
start = self._position
174+
if self._speed and screen._tracing == 1:
175+
diff = (end-start)
176+
diffsq = (diff[0]*screen.xscale)**2 + (diff[1]*screen.yscale)**2
177+
nhops = 1+int((diffsq**0.5)/(3*(1.1**self._speed)*self._speed))
178+
delta = diff * (1.0/nhops)
179+
for n in range(1, nhops):
180+
if n == 1:
181+
top = True
182+
else:
183+
top = False
184+
self._position = start + delta * n
185+
if self._drawing:
186+
screen._drawline(self.drawingLineItem,
187+
(start, self._position),
188+
self._pencolor, self._pensize, top)
189+
self._update()
190+
if self._drawing:
191+
screen._drawline(self.drawingLineItem, ((0, 0), (0, 0)),
192+
fill="", width=self._pensize)
193+
# Turtle now at end,
194+
if self._drawing: # now update currentLine
195+
self.currentLine.append(end)
196+
if isinstance(self._fillpath, list):
197+
self._fillpath.append(end)
198+
###### vererbung!!!!!!!!!!!!!!!!!!!!!!
199+
self._position = end
200+
if self._creatingPoly:
201+
self._poly.append(end)
202+
if len(self.currentLine) > 320: # tkinter.Canvas上一条线的最大长度,turtle中原本为42
203+
self._newLine()
204+
self._update() #count=True)
131205

132206
if Image: # 若导入PIL模块成功
133207
# 用重写的函数替换turtle模块中原来的函数
@@ -137,6 +211,10 @@ def _drawturtle(self):
137211
turtle.TurtleScreen.register_shape=register_shape
138212
turtle.RawTurtle._drawturtle=_drawturtle
139213

214+
# 不依赖PIL
215+
turtle.TurtleScreenBase._drawline=_drawline
216+
turtle.RawTurtle._goto=_goto
217+
140218
# ---------------------重写结束-------------------------
141219

142220
class GravSys(solar_system.GravSys):
Binary file not shown.
Binary file not shown.

dist/solar-system-1.3.3.tar.gz

1.06 KB
Binary file not shown.
1 KB
Binary file not shown.

solar_system.egg-info/PKG-INFO

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Summary: Python模拟万有引力、太阳系行星运动的库,模拟天体
55
Home-page: https://github.com/qfcy/python-gravity-simulation
66
Author: 七分诚意 qq:3076711200
77
Author-email: 3076711200@qq.com
8-
Keywords: solar,system,solarsys,turtle,graphics,太阳系,引力,模拟,物理,天文,astronomy,gravity,physics,mercury,venus,earth,mars,jupiter,saturn,uranus,neptune,pluto
8+
Keywords: solar,system,solarsys,turtle,graphics,astronomy,gravity,physics,太阳系,引力,模拟,物理,天文,mercury,venus,earth,mars,jupiter,saturn,uranus,neptune,pluto
99
Classifier: Programming Language :: Python
1010
Classifier: Topic :: Scientific/Engineering :: Astronomy
1111
Classifier: Topic :: Multimedia :: Graphics
@@ -82,7 +82,7 @@ TESTs/solar_system_particles.py:使用更快的“粒子”计算小行星,
8282

8383
TESTs/solar_system_blackhole1.py:行星掉入黑洞的模拟1
8484

85-
TESTs/solar_system_blackhole2.py:行星掉入黑洞的模拟2(包含了turtle模块绘制旋转图片的技巧,
85+
TESTs/solar_system_blackhole2.py:行星掉入黑洞的模拟2,包含对turtle模块函数的修改和补丁,如turtle模块绘制旋转图片(
8686
`这篇文章 <https://blog.csdn.net/qfcy_/article/details/120584657>`__\ )
8787

8888
TESTs/solar_system_blackhole3.py:第3个行星掉入黑洞的模拟
@@ -322,6 +322,6 @@ CSDN home page:`qfcy\_ <https://blog.csdn.net/qfcy_>`__
322322
Bilibili home page:`qfcy\_ <https://space.bilibili.com/454233262>`__
323323

324324
.. |image1| image:: https://img-blog.csdnimg.cn/69ef2a3fef3b4b3198b292d427e51f42.gif#pic_center
325-
.. |image2| image:: https://img-blog.csdnimg.cn/3b8256294fae45cca841577167394dca.gif#pic_center
325+
.. |image2| image:: https://i-blog.csdnimg.cn/direct/9fbf963a5b1a4cbaa18a5d3dcd5110a5.gif#pic_center
326326
.. |image3| image:: https://img-blog.csdnimg.cn/478371f05bdf4940b84a6d31625c82b6.png#pic_center
327327
.. |image4| image:: https://img-blog.csdnimg.cn/2816259f85374130ac35060d08df3af2.png#pic_center

solar_system.egg-info/SOURCES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ solar_system.egg-info/PKG-INFO
1313
solar_system.egg-info/SOURCES.txt
1414
solar_system.egg-info/dependency_links.txt
1515
solar_system.egg-info/top_level.txt
16+
solar_system/TESTs/solar_system_accelerate_util.c
1617
solar_system/TESTs/BlackHole.jpg
1718
solar_system/TESTs/solar_system_accelerate.py
1819
solar_system/TESTs/solar_system_accelerate_util.c

0 commit comments

Comments
 (0)