Skip to main content

A collection of utility functions to for creating CAD-like visuals in Manim.

Project description

Manim CAD drawing utils

This is a collecion of various functions and utilities that help creating manimations that look like CAD drawings. Also some other stuff that just looks cool.

Features:

  • Round corners
  • Chamfer corners
  • Dimensions
  • Dashed line, dashed mobject
  • Path offset mapping

Installation

manim-CAD_Drawing_Utils is a package on pypi, and can be directly installed using pip:

pip install manim-CAD_Drawing_Utils

Note: CAD_Drawing_Utils uses, and depends on SciPy and Manim.

Usage

Make sure include these two imports at the top of the .py file

from manim import *
from manim_cad_drawing_utils import *

Examples

pointer

class test_dimension_pointer(Scene):
    def construct(self):
        mob1 = Round_Corners(Triangle().scale(2),0.3)
        p = ValueTracker(0)
        dim1 = Pointer_To_Mob(mob1,p.get_value(),r'triangel', pointer_offset=0.2)
        dim1.add_updater(lambda mob: mob.update_mob(mob1,p.get_value()))
        dim1.update()
        PM = Path_mapper(mob1)
        self.play(Create(mob1),rate_func=PM.equalize_rate_func(smooth))
        self.play(Create(dim1))
        self.play(p.animate.set_value(1),run_time=10)
        self.play(Uncreate(mob1,rate_func=PM.equalize_rate_func(smooth)))
        self.play(Uncreate(dim1))
        self.wait()

pointer

dimension

class test_dimension(Scene):
    def construct(self):
        mob1 = Round_Corners(Triangle().scale(2),0.3)
        dim1 = Angle_Dimension_Mob(mob1,
                                   0.2,
                                   0.6,
                                   offset=-4,
                                   ext_line_offset=1,
                                   color=RED)
        dim2 = Linear_Dimension(mob1.get_critical_point(RIGHT),
                                mob1.get_critical_point(LEFT),
                                direction=UP,
                                offset=2.5,
                                outside_arrow=True,
                                ext_line_offset=-1,
                                color=RED)
        self.play(Create(mob1))
        self.play(Create(dim1), run_time=3)
        self.play(Create(dim2), run_time=3)
        self.wait(3)
        self.play(Uncreate(mob1), Uncreate(dim2))

dimension

hatching

class test_hatch(Scene):
    def construct(self):
        mob1 = Star().scale(2)
        # 1 hatch object creates parallel lines
        # 2 of them create rectangles
        hatch1 = Hatch_lines(mob1, angle=PI / 6, stroke_width=2)
        hatch1.add_updater(lambda mob: mob.become(Hatch_lines(mob1, angle=PI / 6, stroke_width=2)))
        hatch2 = Hatch_lines(mob1, angle=PI / 6 + PI / 2, offset=0.5, stroke_width=2)
        hatch2.add_updater(lambda mob: mob.become(Hatch_lines(mob1, angle=PI / 6 + PI / 2, offset=0.5, stroke_width=2)))

        self.add(hatch1,hatch2,mob1)
        self.play(Transform(mob1,Triangle()),run_time=2)
        self.wait()
        self.play(Transform(mob1, Circle()), run_time=2)
        self.wait()
        self.play(Transform(mob1,  Star().scale(2)), run_time=2)
        self.wait()

hatching

Dashed lines

class test_dash(Scene):
    def construct(self):
        mob1 = Round_Corners(Square().scale(3),radius=0.8).shift(DOWN*0)
        vt = ValueTracker(0)
        dash1 = Dashed_line_mobject(mob1,num_dashes=36,dashed_ratio=0.5,dash_offset=0)
        def dash_updater(mob):
            offset = vt.get_value()%1
            dshgrp = mob.generate_dash_mobjects(
                **mob.generate_dash_pattern_dash_distributed(36, dash_ratio=0.5, offset=offset)
            )
            mob['dashes'].become(dshgrp)
        dash1.add_updater(dash_updater)

        self.add(dash1)
        self.play(vt.animate.set_value(2),run_time=6)
        self.wait(0.5)

hatching

rounded corners

class Test_round(Scene):
    def construct(self):
        mob1 = RegularPolygon(n=4,radius=1.5,color=PINK).rotate(PI/4)
        mob2 = Triangle(radius=1.5,color=TEAL)
        crbase = Rectangle(height=0.5,width=3)
        mob3 = Union(crbase.copy().rotate(PI/4),crbase.copy().rotate(-PI/4),color=BLUE)
        mob4 = Circle(radius=1.3)
        mob2.shift(2.5*UP)
        mob3.shift(2.5*DOWN)
        mob1.shift(2.5*LEFT)
        mob4.shift(2.5*RIGHT)

        mob1 = Round_Corners(mob1, 0.25)
        mob2 = Round_Corners(mob2, 0.25)
        mob3 = Round_Corners(mob3, 0.25)
        self.add(mob1,mob2,mob3,mob4))

rounded_corners

cut off corners

class Test_chamfer(Scene):
    def construct(self):
        mob1 = RegularPolygon(n=4,radius=1.5,color=PINK).rotate(PI/4)
        mob2 = Triangle(radius=1.5,color=TEAL)
        crbase = Rectangle(height=0.5,width=3)
        mob3 = Union(crbase.copy().rotate(PI/4),crbase.copy().rotate(-PI/4),color=BLUE)
        mob4 = Circle(radius=1.3)
        mob2.shift(2.5*UP)
        mob3.shift(2.5*DOWN)
        mob1.shift(2.5*LEFT)
        mob4.shift(2.5*RIGHT)

        mob1 = Chamfer_Corners(mob1, 0.25)
        mob2 = Chamfer_Corners(mob2,0.25)
        mob3 = Chamfer_Corners(mob3, 0.25)
        self.add(mob1,mob2,mob3,mob4)

cutoff_corners

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

manim-CAD_Drawing_Utils-0.0.4.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

manim_CAD_Drawing_Utils-0.0.4-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file manim-CAD_Drawing_Utils-0.0.4.tar.gz.

File metadata

  • Download URL: manim-CAD_Drawing_Utils-0.0.4.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.9 Windows/10

File hashes

Hashes for manim-CAD_Drawing_Utils-0.0.4.tar.gz
Algorithm Hash digest
SHA256 47d64b104c2e3b96d80de77e2f617a2831b936ce0b360c30d9e721c5134efe2a
MD5 7fb04479a238496df768a2b42d0e4262
BLAKE2b-256 62d5378ce3f4a3cae3a1f25fb9a97d1c233b60fcb4cdb1f66baaaa2ccf6495a2

See more details on using hashes here.

File details

Details for the file manim_CAD_Drawing_Utils-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for manim_CAD_Drawing_Utils-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ba58854852e7b1c351c3221d03a0634710eb9eb78c39acdeab6a766b471b5f9c
MD5 938f036997dbafe8ac3b4a1704067cd6
BLAKE2b-256 0e7752f06898d1d72c272535bc3b71ca38ebdff36bdd8351652fbe5a68dd119d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page