import math from pixel import Pixel COLOR_A = (0.0, 0.7, 0.8) COLOR_B = (0.8, 0.0, 0.7) HEIGHT = 6.0 RADIUS = 1. def distance(a: tuple, b: tuple) -> float: if len(a) != len(b): raise TypeError("Mismatching dimentional vector passed") dist = 0 for i in range(len(a)): d = b[i] - a[i] dist += d * d return dist ** 0.5 def get_col(uv: tuple) -> tuple: uv = tuple(math.floor(x) for x in uv) return COLOR_A if ((uv[0] + uv[1]) % 2) == 0.0 else COLOR_B def main(pixel: Pixel, resolution: tuple, frag_coord: tuple, time: float): # https://www.shadertoy.com/view/lsyyDK uv = [ x * HEIGHT for x in (frag_coord[0] / resolution[1], frag_coord[1] / resolution[1]) ] direction = int(time) % 2 shift = math.floor(uv[1 - direction]) shift = 2.0 * (shift % 2) - 1.0 uv[direction] += shift * time dist = 1.0 - distance((0.0, 0.0), tuple((x % 1.0) - 0.5 for x in uv)) / RADIUS col = tuple(x * dist for x in get_col(uv)) pixel.background_color.set( *col )