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.

github lkesteloot / lathser / outline.py View on Github external
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.
github Greymerk / python-rpg / src / util / cardinals.py View on Github external
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]) > abs(diff[1]):
			if diff[0] < 0:
				return Cardinal.directions.WEST
			else:
github Greymerk / python-rpg / src / util / cardinals.py View on Github external
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]) > abs(diff[1]):
			if diff[0] < 0:
github lkesteloot / lathser / vector.py View on Github external
def flipX(self):
        return Vector2(-self.x, self.y)
github lkesteloot / lathser / outline.py View on Github external
def make_heat_sensor():
    x = 3.0*DPI
    y = 2.5*DPI
    radius = DPI/32.0
    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
#        points.append(Vector2(x + math.cos(t)*radius, y + math.sin(t)*radius))

    return [points]
github lkesteloot / lathser / vector.py View on Github external
def reciprocal(self):
        return Vector2(-self.y, self.x)
github lkesteloot / lathser / vector.py View on Github external
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)
github lkesteloot / lathser / vector.py View on Github external
def __add__(self, other):
        return Vector2(self.x + other.x, self.y + other.y)
github lkesteloot / lathser / outline.py View on Github external
def make_time_waster(long_delay):
    x = 10*DPI
    y = 2.5*DPI
    if long_delay:
        radius = DPI*0.25
    else:
        radius = DPI*0.125
    pointCount = 10

    points = []

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

    return [points]