mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Fixed PiCreature.look
This commit is contained in:
parent
fb08fc0401
commit
ab0dfe7854
1 changed files with 25 additions and 13 deletions
|
@ -1,5 +1,6 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import warnings
|
import warnings
|
||||||
|
import operator as op
|
||||||
|
|
||||||
from constants import *
|
from constants import *
|
||||||
|
|
||||||
|
@ -97,9 +98,24 @@ class PiCreature(SVGMobject):
|
||||||
self.mouth.set_fill(BLACK, opacity=1)
|
self.mouth.set_fill(BLACK, opacity=1)
|
||||||
self.body.set_fill(self.color, opacity=1)
|
self.body.set_fill(self.color, opacity=1)
|
||||||
self.pupils.set_fill(BLACK, opacity=1)
|
self.pupils.set_fill(BLACK, opacity=1)
|
||||||
|
self.pupils.set_stroke(DARK_GREY, width=1)
|
||||||
|
self.add_pupil_light_spot(self.pupils)
|
||||||
self.eyes.set_fill(WHITE, opacity=1)
|
self.eyes.set_fill(WHITE, opacity=1)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def add_pupil_light_spot(self, pupils):
|
||||||
|
# Purely an artifact of how the SVGs were drawn.
|
||||||
|
# In a perfect world, this wouldn't be needed
|
||||||
|
for pupil in pupils:
|
||||||
|
index = 16
|
||||||
|
sub_points = pupil.points[:index]
|
||||||
|
pupil.points = pupil.points[index + 2:]
|
||||||
|
circle = VMobject()
|
||||||
|
circle.points = sub_points
|
||||||
|
circle.set_stroke(width=0)
|
||||||
|
circle.set_fill(WHITE, 1)
|
||||||
|
pupil.add(circle)
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
copy_mobject = SVGMobject.copy(self)
|
copy_mobject = SVGMobject.copy(self)
|
||||||
copy_mobject.name_parts()
|
copy_mobject.name_parts()
|
||||||
|
@ -135,19 +151,15 @@ class PiCreature(SVGMobject):
|
||||||
direction /= norm
|
direction /= norm
|
||||||
self.purposeful_looking_direction = direction
|
self.purposeful_looking_direction = direction
|
||||||
for pupil, eye in zip(self.pupils.split(), self.eyes.split()):
|
for pupil, eye in zip(self.pupils.split(), self.eyes.split()):
|
||||||
pupil_radius = pupil.get_width() / 2.
|
c = eye.get_center()
|
||||||
eye_radius = eye.get_width() / 2.
|
right = eye.get_right() - c
|
||||||
pupil.move_to(eye)
|
up = eye.get_top() - c
|
||||||
if direction[1] < 0:
|
vect = direction[0] * right + direction[1] * up
|
||||||
pupil.shift(pupil_radius * DOWN / 3)
|
v_norm = np.linalg.norm(vect)
|
||||||
pupil.shift(direction * (eye_radius - pupil_radius))
|
p_radius = 0.5 * pupil.get_width()
|
||||||
bottom_diff = eye.get_bottom()[1] - pupil.get_bottom()[1]
|
vect *= (v_norm - p_radius) / v_norm
|
||||||
if bottom_diff > 0:
|
pupil.move_to(c + vect)
|
||||||
pupil.shift(bottom_diff * UP)
|
self.pupils[1].align_to(self.pupils[0], DOWN)
|
||||||
# TODO, how to handle looking up...
|
|
||||||
# top_diff = eye.get_top()[1]-pupil.get_top()[1]
|
|
||||||
# if top_diff < 0:
|
|
||||||
# pupil.shift(top_diff*UP)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def look_at(self, point_or_mobject):
|
def look_at(self, point_or_mobject):
|
||||||
|
|
Loading…
Add table
Reference in a new issue