B
    È S]	  ã               @   s`   d Z ddlmZmZmZmZ dZG dd„ deƒZ	G dd„ deƒZ
dd	„ Zed
kr\eƒ  eƒ  dS )a°         turtle-example-suite:

        tdemo_planets_and_moon.py

Gravitational system simulation using the
approximation method from Feynman-lectures,
p.9-8, using turtlegraphics.

Example: heavy central body, light planet,
very light moon!
Planet has a circular orbit, moon a stable
orbit around the planet.

You can hold the movement temporarily by
pressing the left mouse button with the
mouse over the scrollbar of the canvas.

é    )ÚShapeÚTurtleÚmainloopÚVec2Dé   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚGravSysc             C   s   g | _ d| _d| _d S )Nr   g{®Gáz„?)ÚplanetsÚtÚdt)Úself© r   ú+lib/python3.7/turtledemo/planet_and_moon.pyÚ__init__   s    zGravSys.__init__c             C   s   x| j D ]}| ¡  qW d S )N)r   Úinit)r   Úpr   r   r   r      s    zGravSys.initc             C   s>   x8t dƒD ],}|  j| j7  _x| jD ]}| ¡  q&W q
W d S )Ni'  )Úranger	   r
   r   Ústep)r   Úir   r   r   r   Ústart    s    zGravSys.startN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r      s   r   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚStarc             C   sT   t j| |d |  ¡  || _|  |¡ || _|j | ¡ || _|  	d¡ |  
¡  d S )N)ÚshapeÚuser)r   r   ZpenupÚmÚsetposÚvr   ÚappendÚgravSysZ
resizemodeZpendown)r   r   Úxr   r   r   r   r   r   r   '   s    

zStar.__init__c             C   s,   | j j}|  ¡ | _| jd| | j  | _d S )Ng      à?)r   r
   ÚaccÚar   )r   r
   r   r   r   r   1   s    
z	Star.initc             C   sV   t ddƒ}xF| jjD ]:}|| kr| ¡ |  ¡  }|t|j t|ƒd  | 7 }qW |S )Nr   é   )ÚVecr   r   ÚposÚGr   Úabs)r   r"   Úplanetr   r   r   r   r!   5   s    
"zStar.accc             C   sj   | j j}|  |  ¡ || j  ¡ | j j | ¡dkrJ|  |  | j jd ¡¡ |  	¡ | _
| j|| j
  | _d S )Nr   )r   r
   r   r%   r   r   ÚindexZ
setheadingZtowardsr!   r"   )r   r
   r   r   r   r   <   s    
z	Star.stepN)r   r   r   r   r   r!   r   r   r   r   r   r   &   s   
r   c              C   s|  t ƒ } |  ¡  |  ¡  dd¡ |  ¡  |  ¡  |  d¡ |  d¡ |  ¡  |  	dd¡ |  
¡  |  ¡ }|  ¡  |  	dd¡ |  
¡  |  ¡ }tdƒ}| |d¡ | |d¡ |  ¡  d|¡ |  ¡  d	d¡ tƒ }td
tddƒtddƒ|dƒ}| d¡ | d¡ | ¡  tdtddƒtddƒ|dƒ}| d¡ | d¡ td	tddƒtddƒ|dƒ}| d¡ | d¡ | ¡  | ¡  dS )Nr   é   éZ   é´   ZcompoundZorangeZbluer(   é   i@B g      ÀÚcircleZyellowgÍÌÌÌÌÌü?iÔ0  éÒ   éÃ   Zgreengš™™™™™é?éÜ   i'  g      à?zDone!)r   ÚresetZ	getscreenZtracerZhtZpuÚfdÚltZ
begin_polyr.   Zend_polyZget_polyr   ZaddcomponentZregister_shaper   r   r$   ZcolorZ	shapesizeZpencolorr   r   )ÚsZm1Zm2ZplanetshapeZgsZsunZearthZmoonr   r   r   ÚmainF   sD    







r6   Ú__main__N)Ú__doc__Zturtler   r   r   r   r$   r&   Úobjectr   r   r6   r   r   r   r   r   Ú<module>   s    '