forked from taichi-dev/taichi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaichi_logo.py
76 lines (59 loc) · 1.38 KB
/
taichi_logo.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# TODO: this program crashes clang-7 when compiled with ti.x86_64. Why?
import taichi as ti
import cv2
import numpy as np
def Vector2(x, y):
return ti.Vector([x, y])
@ti.func
def inside(p, c, r):
return (p - c).norm_sqr() <= r * r
@ti.func
def inside_taichi(p_):
p = p_
p = Vector2(0.5, 0.5) + (p - Vector2(0.5, 0.5)) * 1.11
ret = -1
if not inside(p, Vector2(0.50, 0.50), 0.55):
if ret == -1:
ret = 0
if not inside(p, Vector2(0.50, 0.50), 0.50):
if ret == -1:
ret = 1
if inside(p, Vector2(0.50, 0.25), 0.09):
if ret == -1:
ret = 1
if inside(p, Vector2(0.50, 0.75), 0.09):
if ret == -1:
ret = 0
if inside(p, Vector2(0.50, 0.25), 0.25):
if ret == -1:
ret = 0
if inside(p, Vector2(0.50, 0.75), 0.25):
if ret == -1:
ret = 1
if p[0] < 0.5:
if ret == -1:
ret = 1
else:
if ret == -1:
ret = 0
return ret
x = ti.var(ti.f32)
n = 512
ti.cfg.use_llvm = True
@ti.layout
def layout():
ti.root.dense(ti.ij, n).place(x)
@ti.kernel
def paint():
for i in range(n * 4):
for j in range(n * 4):
ret = 1.0 - inside_taichi(Vector2(1.0 * i / n / 4, 1.0 * j / n / 4))
x[i // 4, j // 4] += ret / 16
paint()
img = np.empty((n, n), dtype=np.float32)
for i in range(n):
for j in range(n):
img[i, j] = x[j, n - 1 - i]
cv2.imshow('Taichi', img)
cv2.imwrite('taichi.png', img * 255)
cv2.waitKey(0)