Beispiel #1
0
	def look_at(self, pos, screen):
		""" Look at the position pos, calculated relative to the peeper's origin.
		"""

		# origin-centered position
		vec = pos[0]-self.origin[0], pos[1]-self.origin[1]
		norm = math.sqrt(vec[0]**2+vec[1]**2)

		# if you get the mouse just right the norm is zero, fix it
		if norm < self.pupil_radius:
			left_pupil = self.left_eye_pos[0]-(vec[0]),self.left_eye_pos[1]+(vec[1])
			right_pupil = self.right_eye_pos[0]+(vec[0]),self.right_eye_pos[1]+(vec[1])
		else:
			if norm == 0:
				norm = 0.001
			left_pupil = self.left_eye_pos[0]+self.pupil_radius*(vec[0]/norm),self.left_eye_pos[1]+self.pupil_radius*(vec[1]/norm)
			right_pupil = self.right_eye_pos[0]+self.pupil_radius*(vec[0]/norm),self.right_eye_pos[1]+self.pupil_radius*(vec[1]/norm)

		# right eye
		pygame.draw.circle(screen,THECOLORS["white"],conv_to_int(self.right_eye_pos),self.radius,0)
		pygame.draw.circle(screen,THECOLORS["black"],conv_to_int(self.right_eye_pos),self.radius,2)
		pygame.draw.circle(screen,THECOLORS["black"],conv_to_int(right_pupil),int(self.pupil_size))

		# left eye
		pygame.draw.circle(screen,THECOLORS["white"],conv_to_int(self.left_eye_pos),self.radius,0)
		pygame.draw.circle(screen,THECOLORS["black"],conv_to_int(self.left_eye_pos),self.radius,2)
		pygame.draw.circle(screen,THECOLORS["black"],conv_to_int(left_pupil),int(self.pupil_size))
Beispiel #2
0
	def draw(self,screen):
		screen.fill((200,200,255,255))
		#pos = pygame.mouse.get_pos()
		pos = self.get_avgd_shadow()
		for p in self.peepers:
			p.look_at(pos,screen)

		# draw the shadow
		shadow_pts_coll = self.shadow.read()
		if len(shadow_pts_coll) > 2: pygame.draw.polygon(screen,THECOLORS["gray"],shadow_pts)
		for shadow_pts in shadow_pts_coll:
			for pt in shadow_pts:
				pygame.draw.circle(screen,THECOLORS["red"],tuple((int(i) for i in pt)),3)

		# draw the avgd center
		pygame.draw.circle(screen,THECOLORS["white"],conv_to_int(pos),5)