使用滑鼠或手指拖曳以環繞聖誕樹,滾輪或雙指開合以縮放。也可用方向鍵旋轉、加減鍵縮放。
# Gather a small light from the dark
def ember(speed, angle, age):
reach = 1 - exp(-6.4 * age)
x = cos(angle) * reach * speed
z = sin(angle) * reach * speed
y = max(0, speed * age - 4 * age ** 2)
return x, y, z
def bloom(distance, radius):
falloff = distance / radius
return exp(-falloff ** 2)
def starlight(angle, time):
pulse = 0.86 + 0.14 * cos(time)
rays = abs(cos(4 * angle))
return pulse * rays ** 12
def garland(height, turns):
phase = tau * turns * height
radius = (1 - height) ** 1.1
return radius * cos(phase), height
def snowflake(seed, time, height):
drift = sin(seed + time * 0.18)
fall = (seed + time * 0.03) % 1
return drift, height * (1 - fall)
def shimmer(seed, time):
crest = 0.5 + 0.5 * sin(seed + time)
return 0.2 + 0.8 * crest ** 6
def ripple(age, radius):
return radius * (1 - exp(-age * 5.6))
# Reflected light across the ice
from math import cos, exp, sin, tau
def reflect(ray, normal):
incidence = dot(ray, normal)
return ray - 2 * incidence * normal
def orbit_light(seed, time, turns):
phase = seed + time / (turns * 2.72)
return phase % 1
def frost(distance, phase):
pulse = 0.6 + 0.4 * sin(phase)
return exp(-distance ** 2) * pulse