Skip to content

Instantly share code, notes, and snippets.

View uwezi's full-sized avatar

Uwe Zimmermann uwezi

View GitHub Profile
@uwezi
uwezi / 20240308_pathfinder.py
Last active March 7, 2024 23:23
[more nearest neighbors] Animating the algorithm to find your way through a cloud of points. #manim #isolated_point #distance #nearest
from manim import *
class PathFinder(MovingCameraScene):
def construct(self):
# thanks ChatGPT
def closest_neighbor(given_point, points):
# Convert points to numpy array for efficient calculations
points_array = np.array(points)
# Calculate Euclidean distance between given_point and all points
@uwezi
uwezi / 20240307_nearest.py
Created March 7, 2024 20:14
[nearest neighbors] find the path through a list of points using nearest neighbors. #manim #chatgpt #sorting
# https://discord.com/channels/581738731934056449/1214983872413044786/1214983872413044786
from manim import *
class PathAutoSorted(MovingCameraScene):
def construct(self):
# thanks ChatGPT
def closest_neighbor(given_point, points):
# Convert points to numpy array for efficient calculations
points_array = np.array(points)
@uwezi
uwezi / 20240226_blocks.py
Last active July 29, 2024 16:27
[blocks and roller] Showing two blocks on the slopes of a triangle. #manim #geometry #physics
# https://www.reddit.com/r/manim/comments/1b0mkad/help_making_an_animation_for_a_physics_explainer/
class blocks(Scene):
def construct(self):
height = 5
tri = Polygon(
[-height*np.tan(30*DEGREES),-3,0],
[height*np.tan(60*DEGREES),-3,0],
[0,height-3,0]
)
tri.shift(-tri.get_center()[0]*RIGHT)
@uwezi
uwezi / 20240225_roundtext.py
Last active February 25, 2024 14:21
[text around circle] Placing a text around a circle. #manim #tex #placement
# https://discord.com/channels/581738731934056449/1211276254620155954/1211286899474432051
from manim import *
class roundTex(Scene):
def construct(self):
text = Tex(r"Lorem ipsum uwezi")
radius = 2
circ = Circle(radius=radius)
arclen = 180*DEGREES
text.scale_to_fit_width(arclen*radius).move_to(ORIGIN, aligned_edge=DL) # wrap around upper half only
@uwezi
uwezi / 20240217_abulafia_latex.py
Last active February 17, 2024 11:55
[shape in TeX] Abulafia's smart search routine. #manim #latex #shape
# https://discord.com/channels/581738731934056449/1207779001041551440/1208377356155097092
def search_shape_in_text(text:VMobject, shape:VMobject, index=0):
def get_mobject_key(mobject: Mobject) -> int:
mobject.save_state().center().scale_to_fit_height(1)
r = np.array2string(mobject.points, precision=2,
separator=' ', suppress_small=True, threshold=None)
r = r.replace('-0. ', ' 0. ')
mobject.restore()
return hash(r)
@uwezi
uwezi / 20231018_fontload.py
Last active October 18, 2023 22:00
[Download font II] Downloading a single font file from github. #manim #font #fontspec #latex #xetex #requests #download
class malayalamFont(Scene):
def construct(self):
import requests
import zipfile
import re
import io
from pathlib import Path
a=requests.get("https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/NotoSerifMalayalam/NotoSerifMalayalam-Regular.ttf")
with open("./fonts/NotoSerifMalayalam-Regular.ttf", mode="wb") as file:
file.write(a.content)
@uwezi
uwezi / 20231007_automaton.py
Last active October 7, 2023 08:18
[Tikz state diagram] Another, cleaner state diagram in Tikz. #manim #latex #tikz
class automaton(Scene):
def construct(self):
template = TexTemplate()
template.add_to_preamble(r"\usepackage{tikz}")
template.add_to_preamble(r"\usetikzlibrary{arrows}")
tex = Tex(
r"""[->,>=stealth',node distance=3cm]
\node[circle,draw] (1) {A};
@uwezi
uwezi / 20230916_fontload.py
Last active October 18, 2023 22:01
[Download font] On-the-fly downloading a font for LaTeX. #manim #latex #tex #fontspec #font #download #requests #xetex
class smileyFont(Scene):
def construct(self):
import requests
import zipfile
import re
import io
from pathlib import Path
a=requests.get("https://github.com/atelier-anchor/smiley-sans/releases/download/v1.1.1/smiley-sans-v1.1.1.zip")
z = zipfile.ZipFile(io.BytesIO(a.content))
font_names = [name for name in z.namelist() if re.search('\.ttf$|\.otf$', name)]
@uwezi
uwezi / 20230913_bodeplot.py
Created September 13, 2023 18:23
[Bodeplot] preview of code for a new coordinate system #manim #semilog #plot #numberplane
from __future__ import annotations
from manim import *
from typing import TYPE_CHECKING, Any, Callable, Iterable, Sequence
class semilogx(NumberPlane):
def SIformat(self, value, decimals=0, digits=None, unit=""):
sign = +1
if value < 0:
sign = -1
@uwezi
uwezi / 20230910_radian.py
Last active September 10, 2023 09:35
[radians] Radians on a unit circle. #manim #geometry #math #radian #animation #arc
from manim import *
class radClone(Scene):
def construct(self):
npl = NumberPlane(
y_range=[-1.5,1.5,0.5],
y_length=8,
x_range=[-16/9*1.5,+16/9*1.5,0.5],
x_length=16/9*8
)