当前位置: 首页>>代码示例>>Python>>正文


Python Mobject.apply_function方法代码示例

本文整理汇总了Python中mobject.Mobject.apply_function方法的典型用法代码示例。如果您正苦于以下问题:Python Mobject.apply_function方法的具体用法?Python Mobject.apply_function怎么用?Python Mobject.apply_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mobject.Mobject的用法示例。


在下文中一共展示了Mobject.apply_function方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PiCreature

# 需要导入模块: from mobject import Mobject [as 别名]
# 或者: from mobject.Mobject import apply_function [as 别名]

#.........这里部分代码省略.........
        return [getattr(self, pn) for pn in self.PART_NAMES]

    def get_white_parts(self):
        return [
            getattr(self, pn) 
            for pn in self.WHITE_PART_NAMES+self.MOUTH_NAMES
        ]

    def get_mouth_center(self):
        result = self.body.get_center()
        result[0] = self.eyes.get_center()[0]
        return result
        # left_center  = self.left_eye.get_center()
        # right_center = self.right_eye.get_center()
        # l_to_r = right_center-left_center
        # eyes_to_mouth = rotate_vector(l_to_r, -np.pi/2, OUT)
        # eyes_to_mouth /= np.linalg.norm(eyes_to_mouth)
        # return left_center/2 + right_center/2 + \
        #        PI_CREATURE_MOUTH_TO_EYES_DISTANCE*eyes_to_mouth

    def highlight(self, color, condition = None):
        for part in set(self.get_parts()).difference(self.get_white_parts()):
            part.highlight(color, condition)
        return self

    def move_to(self, destination):
        self.shift(destination-self.get_bottom())
        return self

    def change_mouth_to(self, mouth_name):
        #TODO, This is poorly implemented
        self.mouth = getattr(self, mouth_name) 
        self.sub_mobjects = list_update(
            self.sub_mobjects, 
            self.get_parts()
        )
        self.mouth.highlight(WHITE)
        return self

    def give_smile(self):
        return self.change_mouth_to("smile")

    def give_frown(self):
        return self.change_mouth_to("frown")

    def give_straight_face(self):
        return self.change_mouth_to("straight_mouth")

    def get_eye_center(self):
        return self.eyes.get_center()

    def make_mean(self):
        eye_x, eye_y = self.get_eye_center()[:2]
        def should_delete((x, y, z)):
            return y - eye_y > 0.3*abs(x - eye_x)
        self.eyes.highlight("black", should_delete)
        self.give_straight_face()
        return self

    def make_sad(self):
        eye_x, eye_y = self.get_eye_center()[:2]
        eye_y += 0.15
        def should_delete((x, y, z)):
            return y - eye_y > -0.3*abs(x - eye_x)
        self.eyey.highlight("black", should_delete)
        self.give_frown()
        return self

    def get_step_intermediate(self, pi_creature):
        vect = pi_creature.get_center() - self.get_center()
        result = self.copy().shift(vect / 2.0)
        left_forward = vect[0] > 0
        if self.right_leg.get_center()[0] < self.left_leg.get_center()[0]:
            #For Mortimer's case
            left_forward = not left_forward
        if left_forward:
            result.left_leg.wag(vect/2.0, DOWN)
            result.right_leg.wag(-vect/2.0, DOWN)
        else:
            result.right_leg.wag(vect/2.0, DOWN)
            result.left_leg.wag(-vect/2.0, DOWN)
        return result

    def blink(self):
        bottom = self.eyes.get_bottom()
        self.eyes.apply_function(
            lambda (x, y, z) : (x, bottom[1], z)
        )
        return self

    def shift_eyes(self):
        for eye in self.left_eye, self.right_eye:
            eye.rotate_in_place(np.pi, UP)
        return self

    def to_symbol(self):
        Mobject.__init__(
            self,
            *list(set(self.get_parts()).difference(self.get_white_parts()))
        )
开发者ID:Rubixdarcy,项目名称:manim,代码行数:104,代码来源:characters.py


注:本文中的mobject.Mobject.apply_function方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。