Do we had any method put a color with single float32 format?

i’m begginer for taichi language,i just try to run the demo “Fractal” and i try to fullscreen show it

there’s my code:

import taichi as ti

# 假定屏幕分辨率1920*1080

n = 660

# 设定偏移量
pixels = ti.var(dt=ti.f32, shape=(Width, Height))

def complex_sqr(z):
  return ti.Vector([z[0] ** 2 - z[1] ** 2, z[1] * z[0] * 2])

def paint(t: ti.f32):
  for i, j in pixels: # 对于所有像素,并行执行
    if(i>OffW and j>OffH):
        c = ti.Vector([-0.8, ti.sin(t) * 0.2])
        z = ti.Vector([float(i-OffW) / n - 1, float(j-OffH) / n - 0.5]) * 2
        iterations = 0
        while z.norm() < 20 and iterations < 50:
          z = complex_sqr(z) + c
          iterations += 1
        pixels[i, j] = 1 - iterations * 0.02
        pixels[i, j]=1

gui = ti.GUI("Fractal", (Width, Height))
for i in range(1000000):
  paint(i * 0.03)

and it result like this:

there we saw the lower left corner has a distincct white edge,i try to fix it by some code like this

pixels[i, j]=ti.color(r,g,b)

but i can’t find it same method in document,and can’t find the method to implement fullscreen too,any good idea?

We use vectors to represent RGB colors:

pixels[i, j] = ti.Vector([r,g,b])

And replace

pixels = ti.var(dt=ti.f32, shape=(Width, Height))


pixels = ti.Vector(3, dt=ti.f32, shape=(Width, Height))

thanks for your reply,but seems it’s doesn’t work:

[Taichi] mode=release
[Taichi] version 0.6.37, llvm 10.0.0, commit e0ac1d86, win, python 3.8.5
[Taichi] Starting on arch=cuda
[Taichi] materializing...
Traceback (most recent call last):
  File "D:/Infinity/XEngine/HiXEngine", line 39, in <module>
    paint(i * 0.03)
  File "D:\python\Anaconda3\envs\XEngine\lib\site-packages\taichi\lang\", line 574, in wrapped
    return primal(*args, **kwargs)
  File "D:\python\Anaconda3\envs\XEngine\lib\site-packages\taichi\lang\", line 501, in __call__
    self.materialize(key=key, args=args, arg_features=arg_features)
  File "D:\python\Anaconda3\envs\XEngine\lib\site-packages\taichi\lang\", line 370, in materialize
    taichi_kernel = taichi_kernel.define(taichi_ast_generator)
  File "D:\python\Anaconda3\envs\XEngine\lib\site-packages\taichi\lang\", line 367, in taichi_ast_generator
  File "D:/Infinity/XEngine/HiXEngine", line 32, in paint
    pixels[i, j] = 1 - iterations * 0.02
  File "D:\python\Anaconda3\envs\XEngine\lib\site-packages\taichi\lang\", line 235, in assign
    return ti.assign(self, other)
  File "D:\python\Anaconda3\envs\XEngine\lib\site-packages\taichi\lang\", line 136, in wrapped
    return a.element_wise_writeback_binary(imp_foo, b)
  File "D:\python\Anaconda3\envs\XEngine\lib\site-packages\taichi\lang\", line 166, in element_wise_writeback_binary
    raise TaichiSyntaxError(
taichi.lang.exception.TaichiSyntaxError: cannot assign scalar expr to taichi class <class 'taichi.lang.matrix.Matrix'>, maybe you want to use `a.fill(b)` instead?

look like we using Vectors represent RGB is not single float32 format it’s conflict with original fractal arithmetic?
and it still haven’t fullscreen displays with no title bar,do we have an implemented solution?

Maybe we should follow it’s suggestion:

pixels[i, j].fill(1 - iterations * 0.02)


but it can’t put any color i know,isn’t? and it’s doesn’t work,seems it only assign a value with[0,1]

What you want might be this:

r = 1 - iterations * 0.02
g = iterations * 0.02
b = 1
pixels[i, j] = ti.Vector([r, g, b])


i got it , seems like i had cognitive bias with this problem , If we want to put an RGB color with in tachi we must create three dimensional vectors to realize it , and original the tensor compose of one dimensional vector it just grayscale . now I implement a cool effect like this:


1 Like