GithubHelp home page GithubHelp logo

2021_taichi_course_homework's Introduction

太极图形课S1-沙堆模型

背景简介

对沙堆中心不断投入新的沙粒,每当一个格子的沙粒积攒到4,就会分散到周围四个格子上

成功效果展示

整体结构(Optional)

源代码(49)

import taichi as ti
ti.init(arch=ti.gpu)

res = 500
scale = 5

pixels = ti.Vector.field(3, ti.uint8, shape = [res, res])
sandpile = ti.field(ti.i32, shape = [int(res/scale), int(res/scale)])
iters = 5

@ti.kernel
def throw_sand():
    sandpile[int(res/scale)/2+0.5, int(res/scale)/2+0.5] += 1

@ti.kernel
def render():
    color = 0xE7E0AA
    for i, j in pixels:
        if sandpile[i/5, j/5] == 0:
            pixels[i, j] = [171, 182, 155]
        elif sandpile[i/5, j/5] == 1:
            pixels[i, j] = [234, 0, 118]
        elif sandpile[i/5, j/5] == 2:
            pixels[i, j] = [230, 178, 0]
        elif sandpile[i/5, j/5] == 3:
            pixels[i, j] = [0, 81, 28]

@ti.kernel
def evolve():
    for i, j in sandpile:
        if sandpile[i, j] >= 4:
            sandpile[i + 1, j] += sandpile[i, j] / 4
            sandpile[i - 1, j] += sandpile[i, j] / 4
            sandpile[i, j - 1] += sandpile[i, j] / 4
            sandpile[i, j + 1] += sandpile[i, j] / 4
            sandpile[i, j] = 0

def main():
    gui = ti.GUI("SandPile Model", res)
    while gui.running:
        for j in range(iters):
            throw_sand()
            evolve()
        render()
        gui.set_image(pixels)
        gui.show()

if __name__ == '__main__':
    main()

运行方式

python3 main.py

存在问题

随时间增加,会逐渐失去对称性

错误结果

感谢 **Jack12xl**的帮助,现在这个问题得以解决

改正后结果

代码链接

Code

2021_taichi_course_homework's People

Contributors

darkwuta avatar jack12xl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

jack12xl

2021_taichi_course_homework's Issues

Thanks for your great homework :)

Well done! Thanks for your contribution and we cannot wait to see your next awesome work soon : )

同学你好,你的作业写得太棒啦!恭喜你获得太极图形精心定制的小礼品,请回复你的收货信息(地址+联系电话)到[email protected]。很快,你的太极周边就快马加鞭飞到你身边啦!(注:一定要确保信息完整准确哦~)
同时,如果你正在上太极图形课,也记得在论坛太极图形课作业区留下你的Github链接,让更多人欣赏到你的大作哦!https://forum.taichi.graphics/c/homework/14

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.