generated from taichi-dev/voxel-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (47 loc) · 2.32 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
from scene import Scene
import taichi as ti
from taichi.math import *
scene = Scene(voxel_edges=0.0, exposure=2)
scene.set_directional_light((1, 1, 1), 0.2, (0.8, 0.8, 0.8))
scene.set_background_color((0.3, 0.3, 0.9))
scene.set_floor(-1.0, (0.6, 0.6, 0.6))
SCALE=4
colors={1:vec3(255/255, 242/255, 54/255),2:vec3(255/255, 202/255, 46/255),3:vec3(237/255, 28/255, 36/255),
4:vec3(51/255, 51/255, 51/255),5:vec3(255/255, 127/255, 47/255)}
pixels=[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 4, 1, 1, 1, 1, 2, 0, 0, 0],
[0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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scene.set_voxel(vec3(jj, -ii, z), 1, color)
for n in range(22*22):
i,j=n%22,n//22
pixel=pixels[i][j]
color=colors.get(pixel,vec3(0.9,0.9,0.9))
i-=10.5
j-=10.5
if pixel !=0:
create_pixel(i,j,color)
scene.finish()