Main
|
Resume
|
Showreel
|
Blog
|
Script
|
Contact
connexion
go to footer
expand all
|
collapse all
languages
class
All
JScript|XSI
Python|XSI
JScript|WEB
Python|Maya
All
Memo
learning
DDD
php
tool
keyboard tooltips
rig
Demo Vector 2D Class
- learning - felixlecha
# Demo Vector 2D Class import maya.cmds as mc class Vector2D(): ''' Create and Manage 2d Vector ''' def __init__(self, x=0, y=0): self.x = x self.y = y def __str__(self): return str( [self.x, self.y ] ) def __repr__(self): return str( [self.x, self.y ] ) def __add__( self, b ): type_b = self.var_type( b ) if type_b == 'Vector2D': return vector2D( x=self.x + b.x, y= self.y + b.y ) elif type_b == 'Number': return vector2D( x=self.x + b, y= self.y + b ) else: return None def var_type(self, b): ''' get the input type ''' if type(b).__name__ == 'instance': if b.__class__.__name__ is 'Vector2D': return 'Vector2D' elif type(b).__name__ in ['float', 'int']: return 'Number' else: return 'Unsupport' def reset( self, mode= 'script' ): self.x = 0 self.y = 0 if mode == 'menu': mc.inViewMessage( msg= 'Your vector is
reset
now !!!', fade=2 ) # init Some vectors vA = vector2D( x=1, y=3 ) vB = vector2D( x=6, y=2 ) # Print print vA.x print vA.y # Add vector + vector vC = vA + vB # Add vector + integer vD = vA + 2 # Reset vC.reset() vD.reset( mode= 'menu' )