How to use the vpython.vpython.canvas function in vpython

To help you get started, we’ve selected a few vpython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vpython / vpython-jupyter / vpython / vpython.py View on Github external
return num

def sleep(dt): # don't use time.sleep because it delays output queued up before the call to sleep
    t = clock()+dt
    while clock() < t:
        rate(60)
    
radians = math.radians
degrees = math.degrees

while True:   ## try to make sure setup is complete
    rate(30)
    if baseObj.glow is not None: break
rate.active = False

scene = canvas()

# This must come after creating a canvas
class MISC(baseObj):
    def __init__(self):
        super(MISC, self).__init__() 
    
    def print(self, s):
        self.addmethod('GSprint', s)

__misc = MISC()

def GSprint(*args):
    s = ''
    for a in args:
        s += str(a)+' '
    s = s[:-1]
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def select(self):
        canvas.selected_canvas = self
        self.addmethod('select','None')
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def __init__(self, **args):
        args['_default_size'] = vector(1,1,1)
        args['_objName'] = "distant_light"
        self._direction = vector(0,0,1)
        super(distant_light, self).setup(args)

        if (canvas.get_selected() != None):
            canvas.get_selected().lights.append(self)
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def __init__(self, **args):    
        if 'canvas' in args:
            cv = args['canvas']
        else:
            cv = canvas.get_selected()
        if cv.vertexCount > canvas.maxVertices-1:
            raise ValueError('too many vertex objects in use for this canvas')        
        args['_default_size'] = None
        args['_objName'] = "vertex"
        self._triangleCount = 0
        self._normal = vector(0,0,1)
        self._bumpaxis = vector(1,0,0)
        self._texpos = vector(0,0,0)
        super(vertex, self).setup(args)
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
    @canvas.setter
    def canvas(self, value):
        raise AttributeError('Cannot assign camera to a different canvas')
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
# on_change functions that detect changes in e.g. obj.pos.y
                obj._pos.value = list_to_vec(p)
                s = evt['size']
                obj._size.value = list_to_vec(s)
                obj._axis.value = obj._size._x*norm(obj._axis)
            self._waitfor = True # what compound and text and extrusion are looking for
        else:
            if 'pos' in evt:
                pos = evt['pos']
                evt['pos'] = list_to_vec(pos)
                self.mouse._pos = evt['pos']
            if 'ray' in evt:
                ray = evt['ray']
                evt['ray'] = list_to_vec(ray)
                self.mouse._ray = evt['ray']
            canvas.hasmouse = self  
            if ev != 'update_canvas':   ## mouse events bound to functions, and pause/waitfor
                evt['canvas'] = self
                self.mouse._alt = evt['alt']
                self.mouse._shift = evt['shift']
                self.mouse._ctrl = evt['ctrl']
                evt1 = event_return(evt)  ## turn it into an object
                for fct in self._binds[ev]:
                    # inspect the bound function and see what it's expecting
                    if _ispython3: # Python 3
                        a = signature(fct)
                        if str(a) != '()': fct( evt1 )
                        else: fct()
                    else: # Python 2
                        a = getargspec(fct)
                        if len(a.args) > 0: fct( evt1 ) 
                        else: fct()
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def __init__(self, **args):
        display(HTML("""<div class="glowscript" id="glowscript"></div>"""))
        display(Javascript("""window.__context = { glowscript_container: $("#glowscript").removeAttr("id")}"""))

        super(canvas, self).__init__()   ## get idx, attrsupdt
        
        self._constructing = True        
        canvas.selected_canvas = self

        rate.active = False
            
        self._objz = set()
        self.lights = []
        self.vertexCount = 0
        self._visible = True
        self._background = vector(0,0,0)
        self._ambient = vector(0.2, 0.2, 0.2)
        self._height = 480
        self._width = 640
        self._align = 'none'
        self._fov = math.pi/3
        
        # The following determine the view:
        self._range = 1 # user can alter with zoom
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def __init__(self, **args):
        args['_default_size'] = vector(1,1,1)
        args['_objName'] = "distant_light"
        self._direction = vector(0,0,1)
        super(distant_light, self).setup(args)

        if (canvas.get_selected() != None):
            canvas.get_selected().lights.append(self)
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
    @canvas.setter
    def canvas(self,value):
        self._canvas = value
        if not self._constructing:
            raise AttributeError('canvas cannot be modified')