コード例 #1
0
 def setup(self):
     Scene.setup(self)
     assert (isinstance(self.camera, MovingCamera))
     self.camera_frame = self.camera.frame
     # Hmm, this currently relies on the fact that MovingCamera
     # willd default to a full-sized frame.  Is that okay?
     return self
コード例 #2
0
 def setup(self):
     Scene.setup(self)
     assert(isinstance(self.camera, MovingCamera))
     self.camera_frame = self.camera.frame
     # Hmm, this currently relies on the fact that MovingCamera
     # willd default to a full-sized frame.  Is that okay?
     return self
コード例 #3
0
    def fillObject(self, _scene: scene.Scene, _object: object.Object):
        position_in_meters = _object.pos
        pixel_dimen = sprite.Sprite.PIXEL_DIMEN
        highest_point = _scene.getHighestPoint()

        text0 = self._font.render(f"{highest_point:.2f} m", False, (0, 0, 0))
        self.display.blit(text0, (0, 0))

        scale_factor = (self.size[1] * highest_point) / (
            self.size[1] - _object.sprite.original_size[1])

        _object.sprite.rescale(
            (int(_object.sprite.original_size[0] / scale_factor),
             int(_object.sprite.original_size[1] / scale_factor)))
        image = _object.sprite.getImageSurface()

        position_in_pixels = self.size[0]/2 + position_in_meters[0] / pixel_dimen - _object.sprite.size[0]/2, \
                             self.size[1] - self.size[1] * position_in_meters[1] / scale_factor - _object.sprite.size[1]

        text1 = self._font.render(f"t: {_object.getTimeElapsed():.2f}", False,
                                  (0, 0, 0))
        text2 = self._font.render(f"h: {_object.pos[1]:.2f}", False, (0, 0, 0))
        text3 = self._font.render(f"a: {_object.physics.a:.2f}", False,
                                  (0, 0, 0))

        self.display.blit(image, position_in_pixels)
        self.display.blit(text1,
                          (position_in_pixels[0] + _object.sprite.size[0],
                           min(position_in_pixels[1] - 50, self.size[1] - 90)))
        self.display.blit(text2,
                          (position_in_pixels[0] + _object.sprite.size[0],
                           min(position_in_pixels[1] - 25, self.size[1] - 65)))
        self.display.blit(text3,
                          (position_in_pixels[0] + _object.sprite.size[0],
                           min(position_in_pixels[1] - 0, self.size[1] - 40)))
コード例 #4
0
    def init_scene(self):
        self.scene = Scene.load_from_file(self.scene_file, self.scene_speed,
                                          self.SIDE_PANEL_WIDTH)

        for obj in self.scene.objects:
            if issubclass(type(obj), Light):
                self.lights.append(obj)
コード例 #5
0
 def get_moving_mobjects(self, *animations):
     moving_mobjects = Scene.get_moving_mobjects(self, *animations)
     if self.zoom_activated and self.little_rectangle in moving_mobjects:
         # When the camera is moving, so is everything,
         return self.mobjects
     else:
         return moving_mobjects
コード例 #6
0
    def process_scene(self, scene: Scene):
        ent = scene.entities()
        mhs = [entity.geometry for entity in ent]

        for idx, mesh in enumerate(mhs):
            mesh.project_to(camera=self.camera)
        pass
コード例 #7
0
 def get_moving_mobjects(self, *animations):
     # TODO: Code repetition from ZoomedScene
     moving_mobjects = Scene.get_moving_mobjects(self, *animations)
     if self.camera_frame in moving_mobjects:
         # When the camera is moving, so is everything,
         return self.mobjects
     else:
         return moving_mobjects
コード例 #8
0
 def get_moving_mobjects(self, *animations):
     moving_mobjects = Scene.get_moving_mobjects(self, *animations)
     all_moving_mobjects = self.camera.extract_mobject_family_members(
         moving_mobjects)
     movement_indicators = self.camera.get_mobjects_indicating_movement()
     for movement_indicator in movement_indicators:
         if movement_indicator in all_moving_mobjects:
             # When one of these is moving, the camera should
             # consider all mobjects to be moving
             return list_update(self.mobjects, moving_mobjects)
     return moving_mobjects
コード例 #9
0
 def initialize(self):
     self.scene = Scene.load_from_file(self.scene_file, self.scene_speed,
                                       self.SIDE_PANEL_WIDTH)
     self.screen = self.scene.screen
     self.side_panel = SidePanel(self.scene, self.population_num)
     self.engine = GaEngine(self.scene, self.side_panel,
                            self.population_num, self.elitism_num,
                            self.robot_random_direction, self.multicore,
                            self.obstacle_sensor_error,
                            self.mutation_probability,
                            self.mutation_coefficient, self.selection_ratio,
                            self.long_lasting_generations, self.verbose)
コード例 #10
0
 def get_moving_mobjects(self, *animations):
     moving_mobjects = Scene.get_moving_mobjects(self, *animations)
     all_moving_mobjects = self.camera.extract_mobject_family_members(
         moving_mobjects
     )
     movement_indicators = self.camera.get_mobjects_indicating_movement()
     for movement_indicator in movement_indicators:
         if movement_indicator in all_moving_mobjects:
             # When one of these is moving, the camera should
             # consider all mobjects to be moving
             return list_update(self.mobjects, moving_mobjects)
     return moving_mobjects
コード例 #11
0
ファイル: bayes_footnote.py プロジェクト: starizyj/manim
    def generate_random_number(self):
        morty = self.morty
        bubble = morty.get_bubble("", direction=LEFT)
        numbers = [Integer(random.choice(range(100))) for x in range(30)]
        numbers.append(Integer(67))
        for number in numbers:
            number.next_to(morty, UP, LARGE_BUFF, RIGHT)

        for number in numbers:
            self.add(number)
            Scene.wait(self, 0.1)
            self.remove(number)
        self.play(
            ShowCreation(bubble),
            number.move_to,
            bubble.get_bubble_center(),
            DOWN + LEFT,
            morty.change,
            "pondering",
        )
        self.wait()

        morty.bubble = bubble
        self.number = number
コード例 #12
0
def parse_scene_json(scene_json):
    """
    Param: scene_file - json file of scene description
    Returns: Scene obj to render
    """

    with open(scene_json, 'r') as scene_des:
        scene = json.loads(scene_des.read())['scene']

    # objects, lights, camera = scene['shapes'], scene['lights'], scene['camera']
    cam = Camera(**scene['camera'])

    lights = []
    for i in range(len(scene['lights'])):
        if scene['lights'][i]['type'] == 'point':
            lights.append(PointLight(**scene['lights'][i]))
        elif scene['lights'][i]['type'] == 'directional':
            lights.append(DirLight(**scene['lights'][i]))

    objects = []
    for obj in scene['shapes']:
        kwargs = obj['geomParams']
        if obj['mat_type'] == 'base':
            obj_type = RefBlinnMaterial
        elif obj['mat_type'] == 'transmissive':
            obj_type = TransmissiveMaterial
        elif obj['mat_type'] == 'reflective':
            obj_type = ReflectiveMaterial
        elif obj['mat_type'] == 'path_blinn':
            obj_type = PathBlinnMaterial

        kwargs.update({'material': obj_type(**obj['material'])})
        if obj['geometry'] == 'sphere':
            scene_obj = Sphere(**kwargs)
        elif obj['geometry'] == 'cylinder':
            scene_obj = Cylinder(**kwargs)
        elif obj['geometry'] == 'plane':
            scene_obj = Plane(**kwargs)
        elif obj['geometry'] == 'triangle':
            scene_obj = Triangle(**kwargs)
        elif obj['geometry'] == 'cone':
            scene_obj = Cone(**kwargs)
        elif obj['geometry'] == 'cuboid':
            scene_obj = Cuboid(**kwargs)
        objects.append(scene_obj)
    return Scene(cam, lights, objects)
コード例 #13
0
    def compile_play_args_to_animation_list(self, *args):
        """
        Add animations so that all pi creatures look at the
        first mobject being animated with each .play call
        """
        animations = Scene.compile_play_args_to_animation_list(self, *args)
        if not self.any_pi_creatures_on_screen():
            return animations

        non_pi_creature_anims = filter(
            lambda anim: anim.mobject not in self.get_pi_creatures(),
            animations
        )
        if len(non_pi_creature_anims) == 0:
            return animations
        first_anim = non_pi_creature_anims[0]
        # Look at ending state
        first_anim.update(1)
        point_of_interest = first_anim.mobject.get_center()
        first_anim.update(0)

        for pi_creature in self.get_pi_creatures():
            if pi_creature not in self.get_mobjects():
                continue
            if pi_creature in first_anim.mobject.submobject_family():
                continue
            anims_with_pi_creature = filter(
                lambda anim: pi_creature in anim.mobject.submobject_family(),
                animations
            )
            for anim in anims_with_pi_creature:
                if isinstance(anim, Transform):
                    index = anim.mobject.submobject_family().index(pi_creature)
                    target_family = anim.target_mobject.submobject_family()
                    target = target_family[index]
                    if isinstance(target, PiCreature):
                        target.look_at(point_of_interest)
            if not anims_with_pi_creature:
                animations.append(
                    ApplyMethod(pi_creature.look_at, point_of_interest)
                )
        return animations
コード例 #14
0
ファイル: pi_creature_scene.py プロジェクト: yype/manim
    def compile_play_args_to_animation_list(self, *args):
        """
        Add animations so that all pi creatures look at the
        first mobject being animated with each .play call
        """
        animations = Scene.compile_play_args_to_animation_list(self, *args)
        if not self.any_pi_creatures_on_screen():
            return animations

        non_pi_creature_anims = filter(
            lambda anim: anim.mobject not in self.get_pi_creatures(),
            animations
        )
        if len(non_pi_creature_anims) == 0:
            return animations
        first_anim = non_pi_creature_anims[0]
        # Look at ending state
        first_anim.update(1)
        point_of_interest = first_anim.mobject.get_center()
        first_anim.update(0)

        for pi_creature in self.get_pi_creatures():
            if pi_creature not in self.get_mobjects():
                continue
            if pi_creature in first_anim.mobject.submobject_family():
                continue
            anims_with_pi_creature = filter(
                lambda anim: pi_creature in anim.mobject.submobject_family(),
                animations
            )
            for anim in anims_with_pi_creature:
                if isinstance(anim, Transform):
                    index = anim.mobject.submobject_family().index(pi_creature)
                    target_family = anim.target_mobject.submobject_family()
                    target = target_family[index]
                    if isinstance(target, PiCreature):
                        target.look_at(point_of_interest)
            if not anims_with_pi_creature:
                animations.append(
                    ApplyMethod(pi_creature.look_at, point_of_interest)
                )
        return animations
コード例 #15
0
 def __new__(cls):
     kwargs = {
         "scene_name": LIVE_STREAM_NAME,
         "open_video_upon_completion": False,
         "show_file_in_finder": False,
         # By default, write to file
         "write_to_movie": True,
         "show_last_frame": False,
         "save_pngs": False,
         # If -t is passed in (for transparent), this will be RGBA
         "saved_image_mode": "RGB",
         "movie_file_extension": ".mp4",
         "quiet": True,
         "ignore_waits": False,
         "write_all": False,
         "name": LIVE_STREAM_NAME,
         "start_at_animation_number": 0,
         "end_at_animation_number": None,
         "skip_animations": False,
         "camera_config": HIGH_QUALITY_CAMERA_CONFIG,
         "frame_duration": MEDIUM_QUALITY_FRAME_DURATION,
     }
     return Scene(**kwargs)
コード例 #16
0
 def add(self, *mobjects):
     Scene.add(self, *list(mobjects)+self.foreground_mobjects)
コード例 #17
0
ファイル: graph_theory.py プロジェクト: zimmermant/manim
 def __init__(self, graph, *args, **kwargs):
     # See CubeGraph() above for format of graph
     self.graph = graph
     Scene.__init__(self, *args, **kwargs)
コード例 #18
0
 def non_blink_wait(self, time=1):
     Scene.wait(self, time)
     return self
コード例 #19
0
ファイル: game.py プロジェクト: lubingGitHub/planeGame
def run():
    gua_game = Guagame()
    scene = Scene()
    gua_game.replace_scene(scene)
    gua_game.begin()
コード例 #20
0
 def __init__(self, graph, *args, **kwargs):
     # See CubeGraph() above for format of graph
     self.graph = graph
     Scene.__init__(self, *args, **kwargs)
コード例 #21
0
 def non_blink_wait(self, time=1):
     Scene.wait(self, time)
     return self
コード例 #22
0
ファイル: three_d_scene.py プロジェクト: saimachi/manim
 def get_moving_mobjects(self, *animations):
     moving_mobjects = Scene.get_moving_mobjects(self, *animations)
     camera_mobjects = self.camera.get_value_trackers()
     if any([cm in moving_mobjects for cm in camera_mobjects]):
         return self.mobjects
     return moving_mobjects
コード例 #23
0
 def get_frame(self):
     frame = Scene.get_frame(self)
     if self.zoom_activated:
         (up, left), (down, right) = self.zoomed_canvas_pixel_indices
         frame[left:right, up:down, :] = self.zoomed_camera.get_image()
     return frame
コード例 #24
0
 def get_moving_mobjects(self, *animations):
     moving_mobjects = Scene.get_moving_mobjects(self, *animations)
     if self.camera.rotation_mobject in moving_mobjects:
         return list_update(self.mobjects, moving_mobjects)
     return moving_mobjects
コード例 #25
0
ファイル: 3D.py プロジェクト: Nejaa/tkinter-3d
    plane.copy().rotate(rotation=Quaternion.axis_angle(Vector(
        x=1), angle=-90)),
    plane.copy().rotate(rotation=Quaternion.axis_angle(Vector(y=1), angle=90)),
    # cube,
    # Cube(cube_size=cubeSize / 2, origin=Vector(y=(cubeSize + cubeSize / 2))),
    # Cube(cube_size=cubeSize / 2, origin=Vector(y=-(cubeSize + cubeSize / 2))),
    # Cube(cube_size=cubeSize / 2, origin=Vector(x=(cubeSize + cubeSize / 2))),
    # Cube(cube_size=cubeSize / 2, origin=Vector(x=-(cubeSize + cubeSize / 2))),
    # Cube(cube_size=cubeSize / 2, origin=Vector(z=(cubeSize + cubeSize / 2))),
    # Cube(cube_size=cubeSize / 2, origin=Vector(z=-(cubeSize + cubeSize / 2))),
]
[m.translate(origin) for m in meshes]
entities = [Entity(geometry=m) for m in meshes]
m.translate(Vector(x=cubeSize * 2))

scene = Scene()
[scene.scene_root.add_entity(e) for e in entities]

rot_speed = 180 / options.tickRate  # deg/s = rot speed/tick
cube_rot_axis = Vector(x=random(), y=random(), z=random())
point2 = cube_rot_axis.copy() * 100
point1 = -point2
rotationSpeeds = [
    # None,
    # None,
    # None,
    # Quaternion.axis_angle(cube_rot_axis, angle=rot_speed),
    # Quaternion.axis_angle(Vector(x=1), angle=-rot_speed),
    # Quaternion.axis_angle(Vector(x=1), angle=rot_speed),
    # Quaternion.axis_angle(Vector(y=1), angle=rot_speed),
    # Quaternion.axis_angle(Vector(y=1), angle=-rot_speed),
コード例 #26
0
ファイル: main.py プロジェクト: ramonsaraiva/mon
	cam.compute_lookat()
	scene.render()


if __name__ == '__main__':
	window = setup_sdl()
	glutInit()
	setup_gl()

	cam = Cam(90, width, height, 1000.0)
	cam._position.y = 25
	cam._position.z = -80
	cam.compute_eye()

	scene = Scene()

	"""
	for i in xrange(-bsize, bsize):
		for j in xrange(-bsize, bsize):
			for k in xrange(-bsize, bsize):
				entity = scene.add_entity()
				entity.load_model('resources/b3x1x5.obj')
				entity.translate = [i*10, j, k*10]
				e2 = scene.add_entity()
				e2.load_model('resources/b2.obj')
				e2.translate = [i*10, j, k*10]
	"""

	floor_size = 20
	for i in xrange(-floor_size, floor_size):
コード例 #27
0
 def add_foreground_mobjects(self, *mobjects):
     self.foreground_mobjects += list(mobjects)
     Scene.add(self, *mobjects)
コード例 #28
0
ファイル: main.py プロジェクト: EMarquer/nogrid-pathfinder
from gui.app import build
from scene.scene import Scene
from scene.scene import Path, Node
from scene.shapes import *

obstacles = {Circle(Node(7, 2), 2)}
scene = Scene(10, 5, obstacles=obstacles)

scene.nogrid_path = Path(
    [Node(.5, .5), Node(2, 3),
     Node(4, 5), Node(4.5, 3.5)])

from pathfinding.astar import *
from scene.coor_converter import *

converter = CoorConverter(scene.grid_precision, 1)

scene.grid[3][3] = 1
build(scene)
コード例 #29
0
 def get_moving_mobjects(self, *animations):
     moving_mobjects = Scene.get_moving_mobjects(self, *animations)
     if self.camera.rotation_mobject in moving_mobjects:
         return list_update(self.mobjects, moving_mobjects)
     return moving_mobjects
コード例 #30
0
 def play(self, *animations, **kwargs):
     Scene.play(
         self,
         *list(animations)+map(Animation, self.foreground_mobjects),
         **kwargs
     )