コード例 #1
0
ファイル: transforms.py プロジェクト: HENRDS/INE5408
 def on_btn_apply_scale_clicked(self, _: Gtk.Button) -> None:
     selected = self.model.selected
     center = selected.center
     m = scale(hpt(float(self.entry_scalex.get_text()), float(self.entry_scaley.get_text())))
     m = np.matmul(np.matmul(translate(center * hpt(-1, -1)), m), translate(center))
     selected.points = np.matmul(selected.points, m)
     self.win.hide()
     self.model.update()
コード例 #2
0
ファイル: transforms.py プロジェクト: HENRDS/INE5408
 def on_btn_apply_translation_clicked(self, _: Gtk.Button) -> None:
     selected = self.model.selected
     x, y = float(self.entry_translatex.get_text()), float(self.entry_translatey.get_text())
     m = translate(hpt(x, y))
     selected.points = selected.points @ m
     self.win.hide()
     self.model.update()
コード例 #3
0
	def move(self):
		'''self.loc is a tuple of floats, but rect.topleft is always
		converted to an integer because it has to be fitted to particular 
		pixels. At low speeds, the rounding down of the integer tuple
		can prevent diagonal motion. That's why we use self.loc instead.'''
		self.loc = geometry.translate(self.loc, \
			self.theta, self.speed)
		self.rect.center = self.loc
コード例 #4
0
    def apply_to(self, curve, avatar, t):
        if self.initial_filter(curve, avatar, t) == 0:
            return
        if self.initial_filter(curve, avatar, t) == 1:
            avatar.drawing_kit['pen color'] = None
            avatar.drawing_kit['brush color'] = None
            return

        s = self.get_progress_rate(t)

        f = s * NORMAL_NUMBER_OF_CHARACTERS_HORIZONTALLY / (2 * W)
        avatar.coords = translate(\
                                  col_to_array(\
                                               2, translate(\
                                                            avatar.coords,
                                                            avatar.anchor),
                                               wring, self.center, self.amplitude, f),
                                  scale(-1, avatar.anchor))
コード例 #5
0
 def make_section_quad(self, point, previous, width=None):
     width = width or self.width
     point = Point(*point)
     left = Line(previous.top_left, point)
     top_right = geometry.translate(left.end, left.angle + PI / 2, width)
     bottom_right = geometry.translate(left.start, left.angle + PI / 2,
                                       width)
     right = Line(bottom_right, top_right)
     intersection = previous.right.intersection(right)
     if intersection:
         bottom_right = intersection
         p = previous
         previous = Quad(coords=(p.bottom_left, p.bottom_right, p.top_left,
                                 bottom_right))
     else:
         bottom_right = previous.top_right
     new_quad = Quad(coords=(left.start, bottom_right, left.end, top_right))
     return previous, new_quad
コード例 #6
0
 def get_bounding_box(self):
     sx, sy, sz = self.size
     pts = np.array([[0, 0, sx, sx], [-sy / 2, sy / 2, sy / 2, -sy / 2],
                     [0, 0, 0, 0], [1, 1, 1, 1]])
     pts = geometry.aboutZ(self.theta).dot(pts)
     pts = geometry.translate(self.x, self.y).dot(pts)
     mins = pts.min(1)
     maxs = pts.max(1)
     xmin = mins[0]
     ymin = mins[1]
     xmax = maxs[0]
     ymax = maxs[1]
     return ((xmin, ymin), (xmax, ymax))
コード例 #7
0
	def move_cor(self, dt):
		if not self.speed:
			return
		d = self.speed * dt
		if not self.steering:
			self.x += d * math.sin(self.rot)
			self.y += d * math.cos(self.rot)
			return
		st = self.steering
		steer = (self.hwbase * math.sin(self.rot), self.hwbase * math.cos(self.rot))
		steer2 = geometry.translate(steer, self.rot + st + math.pi/2, 10)
		back = (self.htrack * math.cos(self.rot) - self.hwbase * math.sin(self.rot),
				-self.htrack * math.sin(self.rot) - self.hwbase * math.cos(self.rot))
		back2 = geometry.translate(back, self.rot + math.pi/2, 10)
		centre = (0,0) # the car centre point, same as origin as other things are shifted
		cor = geometry.line_intersection(steer + steer2, back2 + back)
		r = ((cor[0] - centre[0]) ** 2 + (cor[1] - centre[1]) ** 2) ** 0.5
		angle = d / r * [1, -1][self.steering < 0] * 1
		npos = geometry.rotate(centre, cor, angle)
		self.x += npos[0] - centre[0]
		self.y += npos[1] - centre[1]
		self.rot += angle
コード例 #8
0
	def resetWarps(self):
		self.warps = []
		#Place warp portals
		for c in self.connections:
			node_id, location = c
			#Get the slope of the line from self.loc to this other warp
			angle = angleFromPosition(self.loc, location)
			scaledDistance = cygeometry.distance(self.loc, location) * WARP_PORTAL_SCALING
			#print scaledDistance #TESTING
			x,y = translate(self.loc, angle, scaledDistance)
			temp = objInstances.WarpPortal(x=x, y=y, destinationNode=node_id,
						method=globalvars.scenario_manager.goToInfiniteSpace)
			self.warps.append(temp)
コード例 #9
0
	def draw_cor(self):
		st = self.steering
		m = (self.hwbase * math.sin(self.rot), self.hwbase * math.cos(self.rot))
		m2 = geometry.translate(m, self.rot + st + math.pi/2, 10)
		b = (self.htrack * math.cos(self.rot) - self.hwbase * math.sin(self.rot),
				-self.htrack * math.sin(self.rot) - self.hwbase * math.cos(self.rot))
		b2 = geometry.translate(b, self.rot + math.pi/2, 10)
		centre = (0,0) # the car centre point
		cor = geometry.line_intersection(m + m2, b2 + b)
		l1 = (m[0] - (m2[0]-m[0]) * 10, m[1] - (m2[1] - m[1]) * 10,
				m[0] + (m2[0]-m[0]) * 10, m[1] + (m2[1] - m[1]) * 10)
		l2 = (b[0] - (b2[0]-b[0]) * 10, b[1] - (b2[1] - b[1]) * 10,
				b[0] + (b2[0]-b[0]) * 10, b[1] + (b2[1] - b[1]) * 10)
		pyglet.graphics.draw(3, pyglet.gl.GL_POINTS,
			('v2f', m + m + b),
			('c3B', (255,0,0, 0,255,0, 0,0,255)))
		pyglet.graphics.draw(4, pyglet.gl.GL_LINES,
			('v2f', l1 + l2),
			('c3B', (0,255,0) * 4))
		if cor:
			glPointSize(8)
			pyglet.graphics.draw(1, pyglet.gl.GL_POINTS,
				('v2f', cor),
				('c3B', (0,175,80)))
コード例 #10
0
ファイル: ellipse.py プロジェクト: kennywbin/500lines
def Circle(center, radius, color=None):
    return Ellipse(color=color).transform(scale(radius, radius)).transform(
        translate(center.x, center.y))
コード例 #11
0
 def world_joint(self):
     return geometry.translate(self.q[0],
                               self.q[1]).dot(geometry.aboutZ(self.q[2]))
コード例 #12
0
 def prismatic(self):
     return geometry.translate(0., 0., -self.q)
コード例 #13
0
ファイル: ellipse.py プロジェクト: cscheid/tiny_gfx
def Circle(center, radius, color=None):
    return Ellipse(color=color).transform(
        scale(radius, radius)).transform(
        translate(center.x, center.y))
コード例 #14
0
	def setLeadIndicator(self):
		'''Sets the point in space that enemies should shoot 
		at to hit the player when the player is moving.'''
		#return self.rect.center
		self.lead_indicator = geometry.translate(self.rect.center, self.theta, self.speed*50.0) #The amount to translate depends on player speed, distance from enemy, and bullet speed. There might be a better way to do this.
コード例 #15
0
	def bounceOff(self, other):
		'''Other is another physical object that this physical object 
		just struck and should bounce off of.

		two objects, A and B, collide. let theta be the angle of the line from the 
		center of A to the center of B. Let A be the smaller of the two. let 
		theta' be a line perpendicular to theta.
		If A's direction is less than 90 degrees from pointing at B then 
		reflect A's direction over theta'. Reduce both objects' speeds. 
		else move A's direction half way to theta in the direction away from B. 
		Increase A's speed. Decrease B's speed. (This is the case where A 
		is hit from behind despite moving in the same direction as B.) '''
		#If either object uses rectangular, we need to bounce off differently
		if self.useRectangular or other.useRectangular:
			#Determine if the collision is in the x direction or the y direction.
			selfRight = self.rect.topleft[0]+self.collisionwidth+self.collisiontopleft[0]
			otherRight = other.rect.topleft[0]+other.collisionwidth+other.collisiontopleft[0]
			selfLeft = self.rect.topleft[0]+self.collisiontopleft[0]
			otherLeft = other.rect.topleft[0]+other.collisiontopleft[0]
			if selfRight > otherRight or otherLeft > selfLeft:
				#horizontal collision
				if self.theta > 0:
					self.setAngle(180.0 - self.theta)
				else:
					self.setAngle(-180.0 - self.theta)
			else:
				#vertical collision
				self.setAngle(-self.theta)
		#The following is for collisions with objects that are not rectangular.
		else:
			angleToOther = self.getAngleToTarget(target=other)
			if abs(angleToOther) < 90: #Relatively head on collision
				bounce_off_angle = 90 - angleToOther
				if angleToOther < 0:
					self.turnClockwise(bounce_off_angle)
				else:
					self.turnCounterClockwise(bounce_off_angle)
				#Decrease speed by an amount related to the
				#headon-ed-ness of the collision
				self.speed = self.speed / (1.0 + float(bounce_off_angle) / 90.0)
				self.targetSpeed = self.speed
			else: #Rear end collision
				#Increase speed, as when an object is hit from behind.
				#The angle will also change slightly to be more in the
				#direction of the object that struck us.
				#Specifically, change our angle to be halfway between 
				#our angle and the angle of other.
				#First pass for code follows. This is good enough for now.
				amountToTurn = (180 - abs(angleToOther))/2
				if angleToOther < 0:
					self.turnCounterClockwise(amountToTurn)
				else:
					self.turnClockwise(amountToTurn)
				#Increase speed by adding other object's speed
				self.speed = self.speed+other.speed
				#Decrease other object's speed
				other.speed -= self.speed
				other.targetSpeed = other.speed
		#Prevent multiple consecutive collisions with the same object
		#Get the angle to move away from other's center.
		angle_to_move = geometry.angleFromPosition(\
				other.rect.center, self.rect.center)
		while self.inCollision(other):
			self.loc = geometry.translate(self.loc, angle_to_move, 1.0)
			self.rect.center = self.loc
コード例 #16
0
	def translate(self, angle, magnitude):
		self.loc = geometry.translate(self.loc, \
			angle, magnitude)
		self.rect.centerx = self.loc[0]
		self.rect.centery = self.loc[1]