In [3]:
from __future__ import print_function # For py 2.7 compat

from IPython.html import widgets # Widget definitions
from IPython.display import display # Used to display widgets in the notebook
from IPython.utils.traitlets import Unicode # Used to declare attributes of our widget
from IPython.display import HTML, Javascript
from IPython.html.widgets.widget_bool import _BoolWidget
from IPython.html.widgets.widget_float import _FloatWidget
from IPython.utils.traitlets import CInt, CFloat, Unicode
from IPython.html.widgets.widget import DOMWidget

In [4]:
with open("static/battlecruiser.js") as f:
    display(Javascript(f.read()))



In [5]:
with open("static/jQueryRotate.2.1.js") as f:
    display(Javascript(f.read()))



In [6]:
class BattleCruiserView(DOMWidget):
    _view_name = Unicode('BattleCruiserView', sync=True)
    value = CFloat(0.0, help="Float value", sync=True)
    axis_id = CInt(0, help='axis_id', sync=True)
    x = CFloat(0.0, help="Position (x) of the battlecruiser", sync=True)
    y = CFloat(0.0, help="Position (y) of the battlecruiser", sync=True)
    theta = CFloat(0.0, help="Orientation (degrees) of the battlecruiser", sync=True)
    description = Unicode('', help="Description of the float (label).", sync=True)

In [7]:
class BattleCruiser:
    def __init__(self, name="bc"):
        self.view=BattleCruiserView(description=name)

    def cmd(self, x, z):
        """
        Commands the battlecruiser with a twist of linear X, 
        and an angular Z.
        
        Examples:
        cmd(1,0): battlecruiser should move forward 1 x unit.
        cmd(0,30): battlecruiser should twist 30 degrees.
        """
        self.view.x+=x*math.cos(math.radians(self.view.theta))
        self.view.y+=x*math.sin(math.radians(self.view.theta))
        self.view.theta-=z

In [8]:
#NBINCLUDE_STOP

In [9]:
commodore=BattleCruiserView(description="bc")

In [11]:
commodore

In [ ]:
bc.cmd(10, 0)

In [ ]:
commodore.theta=0

In [ ]:
widgets.interact(set_pose,
         x=400,
         y=400,
         theta=360)

In [ ]:
commodore.x

In [ ]:
import math

In [ ]:
math.radians()

In [8]:
bc=BattleCruiser()

In [9]:
bc.view

In [ ]:


In [27]:
bc.cmd(10,0)

In [ ]:


In [ ]:
import time$
for i in range (100):
    commodore.x = i
    commodore.y = i
    time.sleep(.05)

In [ ]:
import time
while True:
    for i in range(360):
        axis1.theta=i
        axis1.x+=1.0
        time.sleep(.01)

In [ ]:
def set_pose(x,y,theta):
    commodore.x=x
    commodore.y=y
    commodore.theta=theta

In [ ]:
set_pose(100,40,130)

In [ ]:
widgets.interact(set_pose,
         x=400,
         y=400,
         theta=360)

In [ ]: