Advertisement
Guest User

python vector2

a guest
Jan 4th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1.  
  2. class vector2:
  3.     def __init__(self, x_or_vec2, y=None):
  4.         self.x, self.y  = self.__check(x_or_vec2, y)
  5.         #self.value = [self.x, self.y]
  6.  
  7.     def __check(self, x_or_vec2, y=None):
  8.         if y == None:
  9.             x = x_or_vec2[0]
  10.             y = x_or_vec2[1]
  11.         else:
  12.             x = x_or_vec2
  13.             y = y
  14.         return int(x), int(y)
  15.  
  16.     def toString(self, withDot=True):
  17.         if withDot:
  18.             return "".join([str(self.x), ", ", str(self.y)])
  19.         else:
  20.             return "".join([str(self.x), " ", str(self.y)])
  21.     def Value(self):
  22.         return [self.x, self.y]
  23.     def reduce(self, x_or_vec2, y=None):
  24.         x, y = self.__check(x_or_vec2, y)
  25.         self.x = self.x - x
  26.         self.y = self.y - y
  27.     def increase(self, x_or_vec2, y=None):
  28.         x, y = self.__check(x_or_vec2, y)
  29.         self.x = self.x + x
  30.         self.y = self.y + y
  31.     def dive(self, x_or_vec2, y=None):
  32.         x, y = self.__check(x_or_vec2, y)
  33.         print x, y
  34.         self.x = self.x / x
  35.         self.y = self.y / y
  36.     def multiply(self, x_or_vec2, y=None):
  37.         x, y = self.__check(x_or_vec2, y)
  38.         self.x = self.x * x
  39.         self.y = self.y * y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement