More Colors Animate Shader Toy.
# on a 40 x 40 grid # define a draw(x,y) function that # returns the color at x,y # colors = is a list [r,g,b], each value ranging from 0 to 255 # and a global time variable t that tics up 1/10th of a second import random import math def draw(x, y, t): height = 40 tail_length = 10 # Seed randomness for consistent behavior per column random.seed(x) # Determine stream cycle duration (when head moves from top to fully offscreen) speed = random.uniform(0.5, 1.5) stream_duration = (height + tail_length + random.randint(0, 20)) / speed # extra randomness to avoid sync # The number of complete stream cycles since time 0 cycle = int(t // stream_duration) # Each cycle gets a new offset random.seed(x + cycle * 1000) # reseed for variation in new stream offset = random.uniform(-tail_length, height) # allow it to start offscreen speed = random.uniform(0.5, 1.5) # fresh speed each time # Position of the stream head in current cycle t_in_cycle = t % stream_duration head = offset + t_in_cycle * speed # Calculate the distance from head distance = head - y u = random.random() if 0 <= distance <= tail_length: # Trail with fading green brightness = 1.0 - distance / tail_length g = int(255 * brightness/2) * u return (0, g, 0) elif -1 <= distance < 0: # Bright leading character return (180 * u, 255 * u, 100 * u) else: # Background return (0, 0, 0)
submit code
play
pause
(first submit code, then hit play)