Commit 228205b8 authored by Shiven Bhatt's avatar Shiven Bhatt
Browse files

rasterization triangle scene

parent 55c05557
from time import gmtime
from cv2 import rectangle
from manim import *
from numpy import tri
class Slide1(Scene):
SCREEN_WIDTH = 14.2
class Video(Scene):
def construct(self):
image_no_raytracing = ImageMobject("giraffe.jpg")
image_with_raytracing = ImageMobject("giraffe2.jpg")
image_no_raytracing.set_x(-1)
image_no_raytracing.set_y(0)
image_no_raytracing.scale_to_fit_width(1)
self.image_slideshow([
(["giraffe.jpg"], 3),
(["giraffe.jpg", "giraffe2.jpg", "giraffe.jpg"], 3),
])
image_with_raytracing.set_x(1)
image_with_raytracing.set_y(0)
image_with_raytracing.scale_to_fit_width(1)
def image_slideshow(self, slides):
for slide in slides:
images, duration = slide
group = self.get_image_group(images)
self.play(FadeIn(group))
self.wait(duration)
self.play(FadeOut(group))
self.play(FadeIn(image_no_raytracing, image_with_raytracing), run_time=3)
def get_image_group(self, images):
image_width = SCREEN_WIDTH / (len(images))
all_images = []
for image in images:
im = ImageMobject(image)
im.scale_to_fit_width(image_width)
all_images.append(im)
group = Group(*all_images)
group.arrange()
return group
class RasterizationTriangleScene(ThreeDScene):
def construct(self):
self.set_camera_orientation(phi=PI / 4, theta=PI / 6, gamma= PI / 2)
cube = Cube(side_length=1)
cube.shift([0, 0, 3])
rect = Rectangle(width=7, height=5)
rect.shift([-1, 0, -4])
self.add(rect)
self.add(cube)
self.wait(1)
triangle = Polygon([0, 0, 0], [0, 1, 0], [1, 0, 0], stroke_width = 1, stroke_color=RED)
triangle.shift([-0.5, -0.5, 2.5])
self.play(Create(triangle))
plane_triangle = Polygon([0, 0, 0], [0, 0.7, 0], [0.7, 0, 0], stroke_width = 1, stroke_color=RED)
plane_triangle.shift([-0.35, -0.35, -4])
self.play(Transform(triangle, plane_triangle))
self.wait(1)
self.move_camera(phi=PI, theta=0, gamma= PI / 2)
self.wait(1)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment