generated from taichi-dev/voxel-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
58 lines (46 loc) · 1.4 KB
/
main.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
from typing import Any
from scene import Scene
import taichi as ti
from taichi.math import *
scene = Scene(exposure=1)
scene.set_directional_light((1, 1, 1), 0.1, (1, 1, 1))
scene.set_background_color((0.3, 0.4, 0.6))
@ti.func
def pie(r: int, y: int, color=vec3(0.9, 0.3, 0.3)):
for i, k in ti.ndrange((-r, r), (-r, r)):
x = ivec3(i, 0, k)
if x.dot(x) < r * r * 0.6:
scene.set_voxel(vec3(i, y, k), 1, color)
@ti.func
def donut(r: int, y: int, color=vec3(0.3, 0.3, 0.9)):
for i, k in ti.ndrange((-r, r), (-r, r)):
x = ivec3(i, 0, k)
if x.dot(x) >= r * r * 0.5 and x.dot(x) < r * r * 0.8:
scene.set_voxel(vec3(i, y, k), 1, color)
@ti.func
def cloud(offset: int, height: int, depth: int):
r = 5
for i, j, k in ti.ndrange((-r, r), (0, r), (-r, r)):
x = ivec3(i, j, k)
if x.dot(x) < r * r * 0.6:
scene.set_voxel(vec3(i + offset, j+height, k + depth),
1, vec3(0.3, 0.9, 0.3))
@ti.kernel
def initialize_voxels():
n = 30
i = 1
while i + 2 < n:
if i % 2 == 0:
pie(n-i, i)
donut(n-i+2, i+2)
else:
pie(n-i, i, vec3(0.3, 0.3, 0.9))
donut(n-i+2, i+2, vec3(0.9, 0.3, 0.3))
i += 5
cloud(-15, 15, 30)
cloud(-10, 25, -15)
cloud(0, 20, 30)
cloud(10, 8, 20)
cloud(18, 15, -20)
initialize_voxels()
scene.finish()