Skip to content

Instantly share code, notes, and snippets.

View neozhaoliang's full-sized avatar

Zhao Liang neozhaoliang

View GitHub Profile
@neozhaoliang
neozhaoliang / catacaustic_implicit.py
Last active February 23, 2024 04:22
Caustics in a reflective ring
from sympy import *
x, y, X, Y = symbols("x y X Y")
P = x**2 + y**2 - 1
dx = diff(P, x) # gradient of P
dy = diff(P, y)
curve = Matrix([x, y])
light_source = Matrix([1, 0])
l = curve - light_source # the incident ray
n = Matrix([dx, dy]) # the normal vector
"""
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Simple Hyperbolic tiling animation using taichi
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
import taichi as ti
from taichi.math import *
ti.init(arch=ti.cpu)
@neozhaoliang
neozhaoliang / taichi_circle_packing.py
Last active October 6, 2023 08:01
Given an input image, convert it to a circle packing pattern
import cv2
import cairocffi as cairo
import numpy as np
import taichi as ti
ti.init(arch=ti.cpu)
scale = 5
@neozhaoliang
neozhaoliang / return_probability.py
Created November 29, 2022 10:28
Random walk return probability
# pip install taichi
import taichi as ti
ti.init(arch=ti.gpu)
d = 3
num_rounds = 100000
max_steps = 1000000
ivec = ti.types.vector(d, int)
@neozhaoliang
neozhaoliang / fractal.py
Created November 28, 2022 13:29
cheatsheet 直播示例代码
import taichi as ti
import taichi.math as tm
ti.init(arch=ti.vulkan)
w, h = 800, 640
res = (w, h)
pixels = ti.Vector.field(3, float, shape=res)
window = ti.ui.Window("fractal", res=res)
canvas = window.get_canvas()