How to use the vpython.vpython.baseObj 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 self._canvas.up
    @up.setter
    def up(self, value):
        self._canvas.up = value
        
    def rotate(self, angle=0, axis=None, origin=None):
        c = self._canvas
        if axis is None: axis = c.up
        newaxis = self.axis.rotate(angle=angle, axis=axis)
        newpos = self.pos
        if origin is not None:
            newpos = origin + (self.pos-origin).rotate(angle=angle, axis=axis)
        c.center = newpos + newaxis
        c.forward = norm(newaxis)

class canvas(baseObj):
    selected_canvas = None
    hasmouse = None
    maxVertices = 65535  ## 2^16 - 1  due to GS weirdness
    
    def __init__(self, **args):
        if _isnotebook:
            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
            
        self._objz = set()
        self.lights = []
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def delete(self):
        baseObj.decrObjCnt()
        cmd = {"cmd": "delete", "idx": self.idx}
        if (baseObj.glow != None):
            baseObj.glow.comm.send([cmd])
        else:
            self.appendcmd(cmd)
        #baseObj.cmds.append(cmd)
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
if len(args1) > 0: raise AttributeError('Malformed constructor')
            self.append(tpos)
        if len(args1) > 0:
            self.append(*args1)    
                
    @property
    def origin(self):   
        raise AttributeError('The points object does not have an origin')
    @origin.setter
    def origin(self,value):
        raise AttributeError('The points object does not have an origin')

    def rotate(self, **args):
        raise AttributeError('The points object has no rotate method.')        
        
class gobj(baseObj):
    def setup(self, args):
        super(gobj, self).__init__()
    ## default values of shared attributes
        self._color = vector(0,0,0)
        self._interval = -1
        self._graph = None
        #self._plot = []
        objName = args['_objName']
        del args['_objName']
        self._constructing = True ## calls are from constructor
        
        argsToSend = [] ## send to GlowScript only attributes specified in constructor
                        ## default values will be used for others    

        ## process pos here   
        if 'pos' in args:
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
obj._checked = evt['value']
                # inspect the bound function and see what it's expecting
                if _ispython3: # Python 3
                    a = signature(obj._bind)
                    if str(a) != '()': obj._bind( obj )
                    else: obj._bind()
                else: # Python 2
                    a = getargspec(obj._bind)
                    if len(a.args) > 0: obj._bind( obj ) 
                    else: obj._bind()
            else:   ## a canvas event
                if 'trigger' not in evt:
                    cvs = baseObj.object_registry[evt['canvas']]
                    cvs.handle_event(evt)
            if _isnotebook:
                baseObj.trigger()
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
self.addattr('space')

    @property
    def pixel_pos(self):
        return self._pixel_pos
    @pixel_pos.setter
    def pixel_pos(self,value):
        self._pixel_pos = value
        if not self._constructing:
            self.addattr('pixel_pos')  

class frame(object):
    def __init__(self, **args):
        raise NameError('frame is not yet implemented')
    
class Mouse(baseObj):

    def __init__(self, canvas):
        self._pos = None
        self._ray = None
        self._alt = False
        self._ctrl = False
        self._shift = False
        self._canvas = canvas
        self._pick = None
        
        super(Mouse, self).__init__()
        
    @property
    def pos(self):
        if self._pos is None: # can be none if mouse has never been inside canvas
            self._pos = vector(0,0,0)
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
if (canvas.get_selected() != None):
            canvas.get_selected().lights.append(self)
        
    @property
    def direction(self):
        return self._direction
    @direction.setter
    def direction(self,value):
        self._direction = value
        if not self._constructing:
            self.addattr('direction')
   
print_anchor = 3  ## problematic -- intended to point at print area
## title_anchor = 1 and caption_anchor = 2 are attributes of canvas

class controls(baseObj):
    attrlists = { 'button': ['text', 'textcolor', 'background', 'disabled'],
                  'checkbox':['checked', 'text'],
                  'radio':['checked', 'text'],
                  'menu':['selected', 'choices', 'index'],
                  'slider':['vertical', 'min', 'max', 'step', 'value', 'length',
                            'width', 'left', 'right', 'top', 'bottom', 'align']
                }
    def setup(self, args):
        super(controls, self).__init__()  ## get idx, attrsupdt from baseObj
        ## default values of common attributes
        self._constructing = True
        argsToSend = []
        objName = args['_objName']
        del args['_objName']
        if 'pos' in args:
            self.location = args['pos']
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def __init__(self, obj, **args):
        args['_default_size'] = None
        args['_objName'] = "attach_trail"
        self._radius = 0
        if callable(obj): # true if obj is a function
            baseObj.attach_trails.append(self)
            self._obj = "_func"
            self._func = obj
        else:
            self._radius = obj.size.y * 0.1
            self._color = obj.color
            self._obj = obj.idx
        args['_obj'] = self._obj
        self._last_val = None
        self._type = "curve"
        self._retain = -1
        self._pps = 0
        super(attach_trail, self).setup(args)
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def __init__(self, **kwargs):
        self.idx = baseObj.objCnt   ## an integer
        self.object_registry[self.idx] = self        
        if kwargs is not None:
            for key, value in kwargs.items():
                object.__setattr__(self, key, value)
        baseObj.incrObjCnt()
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def appendcmd(self,cmd):
        # The following code makes sure that constructors are sent to the front end first.
        cmd['_pass'] = 1 # indicate that this should be ignored by glowcomm/decode()
        #baseObj.glow.comm.send([cmd])
        if len(baseObj.cmds) == 0:
            commsend() # send any pending output
        baseObj.cmds.append(cmd)
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def __init__(self, **kwargs):
        self.idx = baseObj.objCnt   ## an integer
        self.object_registry[self.idx] = self        
        if kwargs is not None:
            for key, value in kwargs.items():
                object.__setattr__(self, key, value)
        baseObj.incrObjCnt()