How to use the vector.Vector2 function in vector

To help you get started, weβve selected a few vector 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.

lkesteloot / lathser / outline.py View on Github
def get_outlines(image):
edges = []

# Generate edges for each pixel.
print "Generating edges..."
width, height = image.size
for y in range(height - 1):
for x in range(width - 1):
this = image.getpixel((x, y))
right = image.getpixel((x + 1, y))
down = image.getpixel((x, y + 1))

if this != right:
edges.append(Edge(Vector2(x + 1, y), Vector2(x + 1, y + 1)))
if this != down:
edges.append(Edge(Vector2(x, y + 1), Vector2(x + 1, y + 1)))
print "Made %d edges." % len(edges)
if not edges:
print "Error: Found no pixels in image."
sys.exit(1)

# Put into a hash by the edges.
print "Hashing edges..."
edgemap = collections.defaultdict(list)
for edge in edges:
edgemap[edge.v1].append(edge)
edgemap[edge.v2].append(edge)
print "Found %d unique vertices." % len(edgemap)

# Walk around, starting at any edge.
Greymerk / python-rpg / src / util / cardinals.py View on Github
key_map[K_UP] =	directions.NORTH
key_map[K_DOWN] = directions.SOUTH
key_map[K_LEFT] = directions.WEST
key_map[K_RIGHT] = directions.EAST

names = {}
names[directions.NORTH] = "North"
names[directions.SOUTH] = "South"
names[directions.WEST] = "West"
names[directions.EAST] = "East"

values = {}
values[directions.NORTH] = Vector2(0, -1)
values[directions.SOUTH] = Vector2(0, 1)
values[directions.WEST] = Vector2(-1, 0)
values[directions.EAST] = Vector2(1, 0)

@staticmethod
def choice():
return choice(Cardinal.values.values())

@staticmethod
def toward(pos, tar):
diff = Vector2(tar)
diff -= pos
if pos == tar:
return None

if abs(diff[0]) &gt; abs(diff[1]):
if diff[0] &lt; 0:
return Cardinal.directions.WEST
else:
Greymerk / python-rpg / src / util / cardinals.py View on Github
key_map = {}
key_map[K_UP] =	directions.NORTH
key_map[K_DOWN] = directions.SOUTH
key_map[K_LEFT] = directions.WEST
key_map[K_RIGHT] = directions.EAST

names = {}
names[directions.NORTH] = "North"
names[directions.SOUTH] = "South"
names[directions.WEST] = "West"
names[directions.EAST] = "East"

values = {}
values[directions.NORTH] = Vector2(0, -1)
values[directions.SOUTH] = Vector2(0, 1)
values[directions.WEST] = Vector2(-1, 0)
values[directions.EAST] = Vector2(1, 0)

@staticmethod
def choice():
return choice(Cardinal.values.values())

@staticmethod
def toward(pos, tar):
diff = Vector2(tar)
diff -= pos
if pos == tar:
return None

if abs(diff[0]) &gt; abs(diff[1]):
if diff[0] &lt; 0:
lkesteloot / lathser / vector.py View on Github
def flipX(self):
return Vector2(-self.x, self.y)
lkesteloot / lathser / outline.py View on Github
def make_heat_sensor():
x = 3.0*DPI
y = 2.5*DPI
pointCount = 10

points = []

points.append(Vector2(x, y - 2))
points.append(Vector2(x, y))
#    for i in range(pointCount + 1):
#        t = float(i)/pointCount*math.pi*2

return [points]
lkesteloot / lathser / vector.py View on Github
def reciprocal(self):
return Vector2(-self.y, self.x)
lkesteloot / lathser / vector.py View on Github
def project(self, transform, angle):
# Rotate around Z axis.
rx = math.cos(angle)*self.x - math.sin(angle)*self.y
ry = math.sin(angle)*self.x + math.cos(angle)*self.y
rz = self.z

x, y = transform.transform(ry, rz)

return Vector2(x, y)
lkesteloot / lathser / vector.py View on Github
def __add__(self, other):
return Vector2(self.x + other.x, self.y + other.y)
lkesteloot / lathser / outline.py View on Github
def make_time_waster(long_delay):
x = 10*DPI
y = 2.5*DPI
if long_delay:
else:
pointCount = 10

points = []

for i in range(pointCount + 1):
t = float(i)/pointCount*math.pi*2

return [points]

vector

Vector classes and utilities

BSD-3-Clause