Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update example to animation #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/blueorange.py
Expand Up @@ -23,4 +23,6 @@ def on_render(self):
self.img[p] = tl.blueorange(1 - iterations * 0.02)


MyAnimation().start()
if __name__ == '__main__':
animation = MyAnimation()
animation.start()
4 changes: 3 additions & 1 deletion examples/export_video.py
Expand Up @@ -18,4 +18,6 @@ def on_render(self):
ts.vec(0, 2, 4)) * 0.5 + 0.5


MyAnimation().start()
if __name__ == '__main__':
animation = MyAnimation()
animation.start()
7 changes: 5 additions & 2 deletions examples/fluid_v1.py
@@ -1,6 +1,7 @@
import taichi as ti

import taichi_glsl as ts
import warnings

ti.init()


Expand Down Expand Up @@ -29,4 +30,6 @@ def on_advance(self):
self.color.update()


MyAnimation().start()
if __name__ == '__main__':
animation = MyAnimation()
animation.start()
9 changes: 6 additions & 3 deletions examples/fluid_v2.py
@@ -1,6 +1,7 @@
import taichi as ti

import taichi_glsl as ts
import warnings

ti.init()


Expand All @@ -27,7 +28,7 @@ def clearDiv(self):
for _ in ti.static(range(5)):
for I in ti.grouped(ti.ndrange(*self.pre.old.shape)):
pa = ts.vgridSumAround(self.pre.old, I)
self.pre.new[I] = (pa - self.div[I] * self.dx**2) * 0.25
self.pre.new[I] = (pa - self.div[I] * self.dx ** 2) * 0.25
self.pre.update()
for I in ti.grouped(ti.ndrange(*self.pre.old.shape)):
grad = ts.vgridGradient(self.div, I) / self.dx
Expand All @@ -51,4 +52,6 @@ def on_advance(self):
self.clearDiv()


MyAnimation().start()
if __name__ == '__main__':
animation = MyAnimation()
animation.start()
8 changes: 5 additions & 3 deletions examples/fractal.py
@@ -1,6 +1,7 @@
import matplotlib.cm as cm
import taichi as ti

import taichi_glsl as tl
import matplotlib.cm as cm

ti.init()

Expand All @@ -16,7 +17,6 @@ def on_init(self, n=512):
@ti.kernel
def on_render(self):
for p in ti.grouped(self.img):
#c = tl.Complex(-0.8, ti.cos(self.iTime) * 0.2)
c = tl.Complex(self.iMouse * 2 - 1)
z = tl.Complex(p / self.n - tl.vec(1, 0.5)) @ 2
iterations = 0
Expand All @@ -26,4 +26,6 @@ def on_render(self):
self.img[p] = 1 - iterations * 0.01


MyAnimation().start()
if __name__ == '__main__':
animation = MyAnimation()
animation.start()
5 changes: 3 additions & 2 deletions examples/old_uv.py
Expand Up @@ -10,5 +10,6 @@ def paint():
image[i, j] = vec(coor.xy, 0.0)


paint()
ti.imshow(image)
if __name__ == '__main__':
paint()
ti.imshow(image)
6 changes: 4 additions & 2 deletions examples/paint_arrow.py
@@ -1,4 +1,5 @@
import taichi as ti

import taichi_glsl as ts

ti.init()
Expand All @@ -15,5 +16,6 @@ def on_init(self):
def on_render(self):
ts.paintArrow(self.img, ts.vec2(0.0), self.iMouse)


MyAnimation().start()
if __name__ == '__main__':
animation = MyAnimation()
animation.start()
6 changes: 4 additions & 2 deletions examples/particles.py
@@ -1,4 +1,5 @@
import taichi as ti

import taichi_glsl as ts

ti.init()
Expand Down Expand Up @@ -41,5 +42,6 @@ def on_advance(self):
for i in self.pos:
self.pos[i] += self.vel[i] * self.dt


MyAnimation().start()
if __name__ == '__main__':
animation = MyAnimation()
animation.start()
39 changes: 21 additions & 18 deletions examples/rand.py
@@ -1,24 +1,27 @@
from taichi_glsl import *
import taichi as ti

res = 512
import taichi_glsl as ts

img = array(float, res, res)
ti.init()


@ti.kernel
def render():
for i, j in img:
img[i, j] *= 0.94
for i in range(200):
# Try comment and uncomment these:
#p = randND(2)
#p = 0.5 + 0.3 * randUnit2D()
p = 0.5 + 0.3 * randSolid2D()
img[int(p * res + 0.5)] = 1
class MyAnimation(ts.Animation):
def on_init(self):
self._resolution = 512
self.img = ts.array(float, self.iResolution, self.iResolution)
@ti.kernel
def on_render(self):
for i, j in self.img:
self.img[i, j] *= 0.94

for i in range(200):
# Try comment and uncomment these:
# p = randND(2)
# p = 0.5 + 0.3 * randUnit2D()
p = 0.5 + 0.3 * ts.randSolid2D()
self.img[int(p * self.iResolution + 0.5)] = 1

gui = ti.GUI('Random')
while not gui.get_event(ti.GUI.ESCAPE):
render()
gui.set_image(img)
gui.show()

if __name__ == '__main__':
animation = MyAnimation()
animation.start()
36 changes: 19 additions & 17 deletions examples/rand3d.py
@@ -1,23 +1,25 @@
from taichi_glsl import *
import taichi as ti

res = 512
from taichi_glsl import ts

img = vec_array(3, float, res, res)

class MyAnimation(ts.Animation):
def on_init(self):
self._resolution = 512
self.img = ts.vec_array(3, float, self.iResolution, self.iResolution)

@ti.kernel
def render():
for i, j in img:
img[i, j] *= 0.94
for i in range(200):
p = 0.5 + 0.3 * randUnit3D()
img[int(shuffle(p, 0, 1) * res + 0.5)][0] = 1
img[int(shuffle(p, 1, 2) * res + 0.5)][1] = 1
img[int(shuffle(p, 2, 0) * res + 0.5)][2] = 1
@ti.kernel
def on_render(self):
for i, j in self.img:
self.img[i, j] *= 0.94

for i in range(200):
p = 0.5 + 0.3 * ts.randUnit3D()
self.img[int(ts.shuffle(p, 0, 1) * self.iResolution + 0.5)][0] = 1
self.img[int(ts.shuffle(p, 1, 2) * self.iResolution + 0.5)][1] = 1
self.img[int(ts.shuffle(p, 2, 0) * self.iResolution + 0.5)][2] = 1

gui = ti.GUI('Random')
while not gui.get_event(ti.GUI.ESCAPE):
render()
gui.set_image(img)
gui.show()

if __name__ == '__main__':
animation = MyAnimation()
animation.start()
7 changes: 5 additions & 2 deletions examples/simple_vortices.py
@@ -1,6 +1,7 @@
import taichi as ti

import taichi_glsl as ts
import warnings

ti.init()


Expand Down Expand Up @@ -42,4 +43,6 @@ def on_advance(self):
self.color.update()


MyAnimation().start()
if __name__ == '__main__':
animation = MyAnimation()
animation.start()