Skip to content

Vaida12345/Swift-Manim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift-Manim

A Swift wrapper to Manim.

This package uses the engine of ManimCE and PythonKit for Python interoperation.

To use this package, please make sure you have ManimCE installed.

Gallery

Examples of using Manim.

Moving Dots

video

try await withManim { scene in
    let dot1 = Dot(color: .blue)
    let dot2 = Dot(color: .green)
    
    scene.arrange(dot1, dot2, direction: .right)
    
    let line = Line(from: dot1.center, to: dot2.center, color: .red)
    line.moveTo(start: dot1.track(\.center), end: dot2.track(\.center))
    
    scene.add(line, dot1, dot2)
    
    let x = dot1.track(\.x)
    let y = dot2.track(\.y)
    
     withAnimation {
        x += 4
    }
    
    withAnimation(in: .parallel) {
        x.become(-4)
        y += 2
    }
} configuration: {
    $0.quality = .high
}

NumberLine

video

@ValueTracker var value = 0.0
let number = DecimalNumber($value, format: .precision(fractionLength: 4))
let dot = Dot()
let numberLine = NumberLine(range: Range(0...4))
scene.add(VStack(numberLine, number), dot)

dot.move(to: numberLine.convert(number: $value))
withAnimation {
    $value.become(.pi)
}

scene.sleep()
withAnimation {
    $value.become(0)
}

More Examples

See Gallery

Getting Started

Swift-Manim uses Swift Package Manager as its build tool. If you want to import in your own project, it's as simple as adding a dependencies clause to your Package.swift:

dependencies: [
    .package(url: "https://github.com/Vaida12345/Swift-Manim.git", branch: "main")
]

and then adding the appropriate module to your target dependencies.

.product(name: "Manim", package: "Swift-Manim"),

Using Xcode Package support

You can add this framework as a dependency to your Xcode project by clicking File -> Swift Packages -> Add Package Dependency. The package is located at:

https://github.com/Vaida12345/Swift-Manim.git

Setup Environment

Swift-Manim uses Python ManimCE as its engine, hence it is essential to setup Python and let Swift-Manim know where to look.

Please follow this guide to setup your environment.

Documentation

This package uses DocC for documentation. Most shapes and methods come with sample code and example picture / video. View on Github Pages

Credits

  • ManimCE: The underlying engine. This Swift package is simply a wrapper for this engine.
  • PythonKit: This package offers interoperation between Swift and Python, allowing you to run Python code in Swift.

About

Experimental Swift wrapper for Manim

Topics

Resources

Stars

Watchers

Forks

Languages