Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Created July 18, 2017 18:52
Show Gist options
  • Save zeroeth/a77859e5cb694622c72c2421fcffdf33 to your computer and use it in GitHub Desktop.
Save zeroeth/a77859e5cb694622c72c2421fcffdf33 to your computer and use it in GitHub Desktop.
bubble02 animation script (High Quality Zen + Coffeescript)
#!/usr/bin/env coffee
#
# Animation script for HQZ.
# Micah Elizabeth Scott <[email protected]>
# Creative Commons BY-SA license:
# http://creativecommons.org/licenses/by-sa/3.0/
#
# Output: https://youtu.be/j5E9JCgbI0I
# Tool: https://github.com/scanlime/zenphoton/tree/master/hqz
#
plot = require './plot'
arc4rand = require 'arc4rand'
TAU = Math.PI * 2
toRadians = (degrees) -> degrees * (Math.PI / 180.0)
bubble = (frame, opts) ->
rnd = (new arc4rand(opts.seed)).random
# Calculate series coefficients once per frame
series = for i in [1 .. 2]
freq: i
amplitude: rnd(0, 1.0) / i
phase: rnd(0, TAU) + rnd(-0.1, 0.1) * frame
plot opts, (t) ->
# Draw a truncated Fourier series, in polar coordinates
t *= TAU
r = 0
r += s.amplitude * Math.sin(s.freq * (t + s.phase)) for s in series
r = opts.radius + r * opts.radius * opts.modulationDepth
[ opts.x0 + r * Math.cos(t), opts.y0 + r * Math.sin(t) ]
zoomViewport = (width, height, focusX, focusY, zoom) ->
left = focusX
right = width - focusX
top = focusY
bottom = height - focusY
scale = 1.0 - zoom
left = focusX - left * scale
right = focusX + right * scale
top = focusY - top * scale
bottom = focusY + bottom * scale
[ left, top, right - left, bottom - top ]
scene = (frame) ->
resolution: [1920, 1080]
timelimit: 60 * 60
rays: 4000000
seed: frame * 10000
exposure: 0.77
gamma: 1.9
viewport: [0, 0, 1920, 1080]
lights: [
# Ambient light
[ 0.01, [0-1000, 1920+1000], -100, 0, 0, [0, 180], [8000, "K"] ]
].concat [],
# Piecewise rainbow, with naturally fuzzy edges
for nm in [200 .. 1000] by 0.1
y = (nm) -> 1080/2 + 1 * (500-nm)
[ 0.00007, -100, [y(nm), y(nm + 0.1)], 0, 0, 0, nm ]
objects: [].concat [],
# Inner
bubble frame,
material: 0
seed: 'queer'
x0: 1920/2
y0: 1080/2
radius: 500
modulationDepth: 0.25
resolution: 4
# Outer skin
bubble frame,
material: 1
seed: 'queer'
x0: 1920/2
y0: 1080/2
radius: 520
modulationDepth: 0.25
resolution: 4
materials: [
# Inner: Specific material affects pattern of color inside.
[ [0.04, "t"], [0.01, "d"], [0.95, "r"] ]
# Outer: Some spectacular diffuse shimmer, but also let light through
[ [0.5, "d"], [0.5, "t"] ]
]
console.log JSON.stringify scene i for i in [0 .. 300]
#console.log JSON.stringify scene 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment