-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
44 lines (32 loc) · 769 Bytes
/
utils.py
File metadata and controls
44 lines (32 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import taichi as ti
FLUID = 0
AIR = 1
SOLID = 2
# util functions
@ti.pyfunc
def clamp(x, a, b):
return max(a, min(b, x))
@ti.pyfunc
def vec2(x, y):
return ti.Vector([x, y])
@ti.pyfunc
def vec3(x, y, z):
return ti.Vector([x, y, z])
# color map
@ti.data_oriented
class ColorMap:
# reference: https://gitee.com/citadel2020/taichi_demos/blob/master/mgpcgflip/mgpcgflip.py
def __init__(self, h, wl, wr, c):
self.h = h
self.wl = wl
self.wr = wr
self.c = c
def clamp(self, x):
return clamp(x, 0.0, 1.0)
def map(self, x):
w = 0.0
if x < self.c:
w = self.wl
else:
w = self.wr
return self.clamp((w - abs(self.clamp(x) - self.c)) / w * self.h)