Skip to content

Commit

Permalink
Update poisson_disk_sampling.py
Browse files Browse the repository at this point in the history
  • Loading branch information
neozhaoliang authored Dec 18, 2022
1 parent 1dde795 commit 675dd87
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions python/taichi/examples/algorithm/poisson_disk_sampling.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
"""
Poisson disk sampling in Taichi, a fancy version.
Based on Yuanming Hu's code: https://github.com/taichi-dev/poisson_disk_sampling
User interface:
1. Click on the window to restart the animation.
2. Press `p` to save screenshot.
"""
import taichi as ti
import taichi.math as tm

ti.init(arch=ti.cpu)
ti.init(arch=ti.gpu)

grid_n = 20
dx = 1 / grid_n
Expand Down Expand Up @@ -138,26 +143,31 @@ def render():
img[i, j] = col


refresh_scene()
gui = ti.ui.Window("Poisson Disk Sampling", res=(window_size, window_size))
canvas = gui.get_canvas()
gui.fps_limit = 10
while gui.running:
gui.get_event(ti.ui.PRESS)
if gui.is_pressed(ti.ui.ESCAPE):
gui.running = False
def main():
refresh_scene()
gui = ti.ui.Window("Poisson Disk Sampling", res=(window_size, window_size))
canvas = gui.get_canvas()
gui.fps_limit = 10
while gui.running:
gui.get_event(ti.ui.PRESS)
if gui.is_pressed(ti.ui.ESCAPE):
gui.running = False

if gui.is_pressed(ti.ui.LMB):
iMouse[None] = gui.get_cursor_pos()
refresh_scene()

if gui.is_pressed("p"):
canvas.set_image(img)
gui.save_image("screenshot.png")

poisson_disk_sample(sample_count[None])
sample_count[None] += 1
compute_distance_field()
render()
canvas.set_image(img)
gui.show()

if gui.is_pressed(ti.ui.LMB):
iMouse[None] = gui.get_cursor_pos()
refresh_scene()

if gui.is_pressed("p"):
canvas.set_image(img)
gui.write_image("screenshot.png")

poisson_disk_sample(sample_count[None])
sample_count[None] += 1
compute_distance_field()
render()
canvas.set_image(img)
gui.show()
if __name__ == "__main__":
main()

0 comments on commit 675dd87

Please sign in to comment.