libraryextensions/blender/lib/Cycles.xtl
Cycles.xtl -- arrays to a ray-traced film: a Blender scene for Cycles (path tracing: real reflections, shadows from every light, light scattered in fog) described by X_eTaL arrays. A program works out the scene as tables -- a row a box, a lamp, a vehicle, a puff of steam -- and each function here writes one table into Blender's Python as numbers, one call of the player for a whole group. The player (cy:head) is fixed Python, the same for every film: it reads the numbers and makes the objects, materials and keys, and decides nothing. A film is cy:head, then cy:s_tage, the materials, the groups that wear them, lights, fog, the camera's flight, then cy:s_till, or cy:f_rames and cy:e_ncode; written with bl:w_rite! and run by bp:launcher through bl:r_un!.
Nothing is loaded: every surface is worked out by its material from where it is -- a facade's windows from the wall's own coordinates, a street's puddles from noise, a screen's picture from its face and the time -- so a table of boxes is a city. (cy:r_eel is the one exception: a screen playing a video file.)
Places are meters, z up; times are seconds; angles are degrees; colors are 0 to 255 (sRGB), made linear here; a light's strength is watts. Written for Blender 5.1. Import: "cy:" u_se< "Cycles"
The player
ʰplay1 : Char
ʰplay1 ← ("import bpy, math, os, sys\n" c̲at "from mathutils import Vector\n" c̲at "args = sys.argv[sys.argv.index('--') + 1:]\n" c̲at "out = args[0]\n" c̲at "os.makedirs(out, exist_ok=True)\n" c̲at "bpy.ops.wm.read_factory_settings(use_empty=True)\n" c̲at "bpy.context.preferences.edit.keyframe_new_interpolation_type = 'LINEAR'\n" c̲at "scene = bpy.context.scene\n" c̲at "mats = {}\n" c̲at "models = {}\n" c̲at "rig = {}\n" c̲at "\n" c̲at "def nums(text, k):\n" c̲at " v = [float(t) for t in text.split()]\n" c̲at " return [tuple(v[i:i + k]) for i in range(0, len(v), k)]\n" c̲at "\n" c̲at "def frame(t):\n" c̲at " return 1 + round(t * scene.render.fps)\n" c̲at "\n" c̲at "def gpu():\n" c̲at " p = bpy.context.preferences.addons['cycles'].preferences\n" c̲at " for kind in ('OPTIX', 'CUDA', 'HIP', 'ONEAPI', 'METAL'):\n" c̲at " try:\n" c̲at " p.compute_device_type = kind\n" c̲at " except TypeError:\n" c̲at " continue\n" c̲at " p.get_devices()\n" c̲at " if any(d.type == kind for d in p.devices):\n" c̲at " for d in p.devices:\n" c̲at " d.use = d.type == kind\n" c̲at " return kind\n" c̲at " return ''\n" c̲at "\n" c̲at "def font():\n" c̲at " d = os.getcwd()\n" c̲at " while True:\n" c̲at " p = os.path.join(d, 'work', 'fonts', 'JuliaMono-Black.ttf')\n" c̲at " if os.path.exists(p):\n" c̲at " return bpy.data.fonts.load(p, check_existing=True)\n" c̲at " if os.path.dirname(d) == d:\n" c̲at " return None\n" c̲at " d = os.path.dirname(d)\n" c̲at "\n" c̲at "rig['font'] = font()\n" c̲at "\n")
ʰplay2 : Char
ʰplay2 ← ("def stage(w, h, fps, seconds, samples, device):\n" c̲at " scene.render.engine = 'CYCLES'\n" c̲at " c = scene.cycles\n" c̲at " rig['device'] = gpu() if device == 'GPU' else ''\n" c̲at " c.device = 'GPU' if rig['device'] else 'CPU'\n" c̲at " c.samples = int(samples)\n" c̲at " c.use_adaptive_sampling = True\n" c̲at " c.adaptive_threshold = 0.02\n" c̲at " c.use_denoising = True\n" c̲at " c.max_bounces = 6\n" c̲at " c.diffuse_bounces = 2\n" c̲at " c.glossy_bounces = 4\n" c̲at " c.transmission_bounces = 4\n" c̲at " c.volume_bounces = 1\n" c̲at " c.sample_clamp_indirect = 8.0\n" c̲at " scene.render.use_persistent_data = True\n" c̲at " scene.render.resolution_x, scene.render.resolution_y = int(w), int(h)\n" c̲at " scene.render.resolution_percentage = 100\n" c̲at " scene.render.fps = int(fps)\n" c̲at " scene.frame_start, scene.frame_end = 1, frame(seconds)\n" c̲at " scene.view_settings.view_transform = 'AgX'\n" c̲at "\n" c̲at "def look(name, exposure, shutter):\n" c̲at " try:\n" c̲at " scene.view_settings.look = name\n" c̲at " except TypeError:\n" c̲at " pass\n" c̲at " scene.view_settings.exposure = exposure\n" c̲at " scene.render.use_motion_blur = shutter > 0.0\n" c̲at " scene.render.motion_blur_shutter = max(shutter, 0.01)\n" c̲at "\n" c̲at "def node(nt, kind, **sets):\n" c̲at " n = nt.nodes.new(kind)\n" c̲at " for k, v in sets.items():\n" c̲at " setattr(n, k, v)\n" c̲at " return n\n" c̲at "\n" c̲at "def feed(nt, socket, value):\n" c̲at " if hasattr(value, 'links'):\n" c̲at " nt.links.new(value, socket)\n" c̲at " elif hasattr(socket.default_value, '__len__') and not hasattr(value, '__len__'):\n" c̲at " socket.default_value = (value,) * len(socket.default_value)\n" c̲at " else:\n" c̲at " socket.default_value = value\n" c̲at "\n")
ʰplay3 : Char
ʰplay3 ← ("def calc(nt, op, a, b=None, c=None):\n" c̲at " n = node(nt, 'ShaderNodeMath', operation=op)\n" c̲at " for i, v in enumerate((a, b, c)):\n" c̲at " if v is not None:\n" c̲at " feed(nt, n.inputs[i], v)\n" c̲at " return n.outputs[0]\n" c̲at "\n" c̲at "def blend(nt, f, a, b):\n" c̲at " n = node(nt, 'ShaderNodeMix', data_type='RGBA')\n" c̲at " feed(nt, n.inputs[0], f)\n" c̲at " feed(nt, n.inputs[6], a if hasattr(a, 'links') else tuple(a) + (1.0,))\n" c̲at " feed(nt, n.inputs[7], b if hasattr(b, 'links') else tuple(b) + (1.0,))\n" c̲at " return n.outputs[2]\n" c̲at "\n" c̲at "def step(nt, x, lo, hi):\n" c̲at " n = node(nt, 'ShaderNodeMapRange', interpolation_type='SMOOTHSTEP')\n" c̲at " feed(nt, n.inputs[0], x)\n" c̲at " n.inputs[1].default_value, n.inputs[2].default_value = lo, hi\n" c̲at " return n.outputs[0]\n" c̲at "\n" c̲at "def xyz(nt, v):\n" c̲at " n = node(nt, 'ShaderNodeSeparateXYZ')\n" c̲at " nt.links.new(v, n.inputs[0])\n" c̲at " return n.outputs\n" c̲at "\n" c̲at "def join(nt, x, y, z):\n" c̲at " n = node(nt, 'ShaderNodeCombineXYZ')\n" c̲at " for s, v in zip(n.inputs, (x, y, z)):\n" c̲at " feed(nt, s, v)\n" c̲at " return n.outputs[0]\n" c̲at "\n" c̲at "def noise(nt, v, scale, detail, w=None):\n" c̲at " n = node(nt, 'ShaderNodeTexNoise', noise_dimensions='4D' if w is not None else '3D')\n" c̲at " feed(nt, n.inputs['Vector'], v)\n" c̲at " if w is not None:\n" c̲at " feed(nt, n.inputs['W'], w)\n" c̲at " n.inputs['Scale'].default_value = scale\n" c̲at " n.inputs['Detail'].default_value = detail\n" c̲at " return n.outputs[0]\n" c̲at "\n")
ʰplay4 : Char
ʰplay4 ← ("def dice(nt, v):\n" c̲at " n = node(nt, 'ShaderNodeTexWhiteNoise', noise_dimensions='3D')\n" c̲at " feed(nt, n.inputs['Vector'], v)\n" c̲at " return n.outputs\n" c̲at "\n" c̲at "def clock(nt):\n" c̲at " n = node(nt, 'ShaderNodeValue')\n" c̲at " d = n.outputs[0].driver_add('default_value').driver\n" c̲at " d.type = 'SCRIPTED'\n" c̲at " d.expression = 'frame / %d' % scene.render.fps\n" c̲at " return n.outputs[0]\n" c̲at "\n" c̲at "def fresh(name):\n" c̲at " m = bpy.data.materials.new(name)\n" c̲at " m.use_nodes = True\n" c̲at " nt = m.node_tree\n" c̲at " nt.nodes.clear()\n" c̲at " mats[name] = m\n" c̲at " return m, nt, node(nt, 'ShaderNodeOutputMaterial')\n" c̲at "\n" c̲at "def shell(nt, o):\n" c̲at " p = node(nt, 'ShaderNodeBsdfPrincipled')\n" c̲at " nt.links.new(p.outputs[0], o.inputs['Surface'])\n" c̲at " return p\n" c̲at "\n" c̲at "def surface(name, rgb, roughness, metallic):\n" c̲at " m, nt, o = fresh(name)\n" c̲at " p = shell(nt, o)\n" c̲at " p.inputs['Base Color'].default_value = tuple(rgb) + (1.0,)\n" c̲at " p.inputs['Roughness'].default_value = roughness\n" c̲at " p.inputs['Metallic'].default_value = metallic\n" c̲at "\n" c̲at "def neon(name, rgb, strength):\n" c̲at " m, nt, o = fresh(name)\n" c̲at " e = node(nt, 'ShaderNodeEmission')\n" c̲at " e.inputs['Color'].default_value = tuple(rgb) + (1.0,)\n" c̲at " e.inputs['Strength'].default_value = strength\n" c̲at " nt.links.new(e.outputs[0], o.inputs['Surface'])\n" c̲at "\n" c̲at "def facade(name, wall, lit_a, lit_b, cell, lit, glow):\n" c̲at " m, nt, o = fresh(name)\n" c̲at " g = node(nt, 'ShaderNodeNewGeometry')\n" c̲at " px, py, pz = xyz(nt, g.outputs['Position'])\n" c̲at " nx, ny, nz = xyz(nt, g.outputs['True Normal'])\n" c̲at " ax = calc(nt, 'GREATER_THAN', calc(nt, 'ABSOLUTE', nx), 0.5)\n" c̲at " roof = calc(nt, 'GREATER_THAN', calc(nt, 'ABSOLUTE', nz), 0.5)\n" c̲at " u = calc(nt, 'ADD', px, calc(nt, 'MULTIPLY', ax, calc(nt, 'SUBTRACT', py, px)))\n" c̲at " depth = calc(nt, 'ADD', py, calc(nt, 'MULTIPLY', ax, calc(nt, 'SUBTRACT', px, py)))\n" c̲at " cu = calc(nt, 'DIVIDE', u, cell[0])\n" c̲at " cv = calc(nt, 'DIVIDE', pz, cell[1])\n" c̲at " iu, iv = calc(nt, 'FLOOR', cu), calc(nt, 'FLOOR', cv)\n" c̲at " fu, fv = calc(nt, 'FRACT', cu), calc(nt, 'FRACT', cv)\n" c̲at " side = calc(nt, 'ADD', calc(nt, 'ROUND', calc(nt, 'MULTIPLY', depth, 2.0)), calc(nt, 'MULTIPLY', ax, 977.0))\n" c̲at " pane = calc(nt, 'MULTIPLY', calc(nt, 'MULTIPLY', calc(nt, 'GREATER_THAN', fu, 0.14), calc(nt, 'LESS_THAN', fu, 0.86)), calc(nt, 'MULTIPLY', calc(nt, 'GREATER_THAN', fv, 0.3), calc(nt, 'LESS_THAN', fv, 0.88)))\n" c̲at " pane = calc(nt, 'MULTIPLY', pane, calc(nt, 'SUBTRACT', 1.0, roof))\n" c̲at " r = dice(nt, join(nt, iu, iv, side))\n" c̲at " floor = dice(nt, join(nt, 0.0, iv, side))\n" c̲at " chance = calc(nt, 'ADD', lit, calc(nt, 'MULTIPLY', calc(nt, 'SUBTRACT', floor[0], 0.5), 0.5))\n" c̲at " on = calc(nt, 'MULTIPLY', pane, calc(nt, 'LESS_THAN', r[0], chance))\n" c̲at " cr, cg, cb = xyz(nt, r[1])\n" c̲at " grime = noise(nt, join(nt, calc(nt, 'MULTIPLY', px, 0.6), calc(nt, 'MULTIPLY', py, 0.6), calc(nt, 'MULTIPLY', pz, 0.08)), 1.0, 4.0)\n" c̲at " wallc = blend(nt, grime, [0.45 * x for x in wall], [1.25 * x for x in wall])\n" c̲at " p = shell(nt, o)\n" c̲at " feed(nt, p.inputs['Base Color'], blend(nt, pane, wallc, (0.012, 0.014, 0.02)))\n" c̲at " feed(nt, p.inputs['Roughness'], calc(nt, 'SUBTRACT', calc(nt, 'ADD', 0.45, calc(nt, 'MULTIPLY', grime, 0.4)), calc(nt, 'MULTIPLY', pane, 0.6)))\n" c̲at " feed(nt, p.inputs['Emission Color'], blend(nt, cg, lit_a, lit_b))\n" c̲at " feed(nt, p.inputs['Emission Strength'], calc(nt, 'MULTIPLY', on, calc(nt, 'MULTIPLY', glow, calc(nt, 'ADD', 0.25, cb))))\n" c̲at " b = node(nt, 'ShaderNodeBump')\n" c̲at " b.inputs['Strength'].default_value = 0.3\n" c̲at " feed(nt, b.inputs['Height'], calc(nt, 'SUBTRACT', calc(nt, 'MULTIPLY', grime, 0.05), calc(nt, 'MULTIPLY', pane, 0.08)))\n" c̲at " nt.links.new(b.outputs[0], p.inputs['Normal'])\n" c̲at "\n")
ʰplay5 : Char
ʰplay5 ← ("def wet(name, rgb, puddles, size, ripple):\n" c̲at " m, nt, o = fresh(name)\n" c̲at " g = node(nt, 'ShaderNodeNewGeometry')\n" c̲at " pos = g.outputs['Position']\n" c̲at " big = noise(nt, pos, 1.0 / size, 3.0)\n" c̲at " th = 0.5 + (0.5 - puddles) * 0.5\n" c̲at " pool = step(nt, big, th - 0.03, th + 0.03)\n" c̲at " fine = noise(nt, pos, 9.0, 6.0)\n" c̲at " grit = noise(nt, pos, 60.0, 2.0)\n" c̲at " rain = noise(nt, pos, 14.0, 1.0, calc(nt, 'MULTIPLY', clock(nt), 2.5))\n" c̲at " p = shell(nt, o)\n" c̲at " dry = blend(nt, fine, [0.5 * x for x in rgb], [1.3 * x for x in rgb])\n" c̲at " feed(nt, p.inputs['Base Color'], blend(nt, pool, dry, [0.25 * x for x in rgb]))\n" c̲at " rough = calc(nt, 'ADD', 0.22, calc(nt, 'MULTIPLY', fine, 0.3))\n" c̲at " feed(nt, p.inputs['Roughness'], calc(nt, 'ADD', 0.015, calc(nt, 'MULTIPLY', calc(nt, 'SUBTRACT', 1.0, pool), rough)))\n" c̲at " b = node(nt, 'ShaderNodeBump')\n" c̲at " b.inputs['Strength'].default_value = 0.5\n" c̲at " b.inputs['Distance'].default_value = 0.02\n" c̲at " dryh = calc(nt, 'MULTIPLY', calc(nt, 'SUBTRACT', 1.0, pool), calc(nt, 'ADD', grit, calc(nt, 'MULTIPLY', fine, 2.0)))\n" c̲at " feed(nt, b.inputs['Height'], calc(nt, 'ADD', dryh, calc(nt, 'MULTIPLY', pool, calc(nt, 'MULTIPLY', rain, ripple))))\n" c̲at " nt.links.new(b.outputs[0], p.inputs['Normal'])\n" c̲at "\n" c̲at "def screen(name, kind, a, b, speed, strength):\n" c̲at " m, nt, o = fresh(name)\n" c̲at " uv = node(nt, 'ShaderNodeUVMap')\n" c̲at " u, v, _ = xyz(nt, uv.outputs[0])\n" c̲at " t = calc(nt, 'MULTIPLY', clock(nt), speed)\n" c̲at " if kind == 'bars':\n" c̲at " f = step(nt, calc(nt, 'SINE', calc(nt, 'MULTIPLY', calc(nt, 'ADD', calc(nt, 'MULTIPLY', v, 5.0), t), 6.2832)), -0.2, 0.2)\n" c̲at " level = calc(nt, 'ADD', 0.35, calc(nt, 'MULTIPLY', f, 0.65))\n" c̲at " elif kind == 'rings':\n" c̲at " du, dv = calc(nt, 'SUBTRACT', u, 0.5), calc(nt, 'SUBTRACT', v, 0.5)\n" c̲at " d = calc(nt, 'SQRT', calc(nt, 'ADD', calc(nt, 'MULTIPLY', du, du), calc(nt, 'MULTIPLY', dv, dv)))\n" c̲at " f = step(nt, calc(nt, 'SINE', calc(nt, 'MULTIPLY', calc(nt, 'SUBTRACT', calc(nt, 'MULTIPLY', d, 7.0), t), 6.2832)), -0.3, 0.3)\n" c̲at " level = calc(nt, 'ADD', 0.3, calc(nt, 'MULTIPLY', f, 0.7))\n" c̲at " elif kind == 'rain':\n" c̲at " col = calc(nt, 'FLOOR', calc(nt, 'MULTIPLY', u, 28.0))\n" c̲at " r = dice(nt, join(nt, col, 3.0, 7.0))\n" c̲at " _, r2, r3 = xyz(nt, r[1])\n" c̲at " fall = calc(nt, 'FRACT', calc(nt, 'ADD', calc(nt, 'ADD', calc(nt, 'MULTIPLY', v, 1.5), calc(nt, 'MULTIPLY', t, calc(nt, 'ADD', 0.4, r2))), r3))\n" c̲at " cell = calc(nt, 'FLOOR', calc(nt, 'MULTIPLY', v, 44.0))\n" c̲at " glyph = dice(nt, join(nt, col, cell, calc(nt, 'FLOOR', calc(nt, 'MULTIPLY', t, 6.0))))\n" c̲at " f = calc(nt, 'POWER', fall, 6.0)\n" c̲at " level = calc(nt, 'MULTIPLY', calc(nt, 'POWER', fall, 3.0), calc(nt, 'ADD', 0.3, glyph[0]))\n" c̲at " else:\n" c̲at " cu, cv = calc(nt, 'FLOOR', calc(nt, 'MULTIPLY', u, 6.0)), calc(nt, 'FLOOR', calc(nt, 'MULTIPLY', v, 4.0))\n" c̲at " r = dice(nt, join(nt, cu, cv, calc(nt, 'FLOOR', t)))\n" c̲at " f = r[0]\n" c̲at " _, r2, _ = xyz(nt, r[1])\n" c̲at " level = calc(nt, 'ADD', 0.15, calc(nt, 'MULTIPLY', r2, 0.85))\n" c̲at " lines = calc(nt, 'ADD', 0.8, calc(nt, 'MULTIPLY', 0.2, calc(nt, 'SINE', calc(nt, 'MULTIPLY', v, 400.0))))\n" c̲at " p = shell(nt, o)\n" c̲at " p.inputs['Base Color'].default_value = (0.01, 0.01, 0.012, 1.0)\n" c̲at " p.inputs['Roughness'].default_value = 0.15\n" c̲at " feed(nt, p.inputs['Emission Color'], blend(nt, f, a, b))\n" c̲at " feed(nt, p.inputs['Emission Strength'], calc(nt, 'MULTIPLY', strength, calc(nt, 'MULTIPLY', level, lines)))\n" c̲at "\n")
ʰplay6 : Char
ʰplay6 ← ("def media(folder):\n" c̲at " rig['media'] = folder\n" c̲at "\n" c̲at "def reel(name, path, strength):\n" c̲at " file = os.path.abspath(os.path.join(rig.get('media', ''), path))\n" c̲at " if not os.path.exists(file):\n" c̲at " rig['missing'] = rig.get('missing', 0) + 1\n" c̲at " return screen(name, 'tiles', (1.0, 0.2, 0.4), (0.2, 0.6, 1.0), 1.0, strength)\n" c̲at " rig['played'] = rig.get('played', 0) + 1\n" c̲at " m, nt, o = fresh(name)\n" c̲at " img = bpy.data.images.load(file, check_existing=True)\n" c̲at " t = node(nt, 'ShaderNodeTexImage', image=img)\n" c̲at " if img.source == 'MOVIE':\n" c̲at " t.image_user.frame_duration = max(1, img.frame_duration)\n" c̲at " t.image_user.use_cyclic = True\n" c̲at " t.image_user.use_auto_refresh = True\n" c̲at " p = shell(nt, o)\n" c̲at " p.inputs['Base Color'].default_value = (0.01, 0.01, 0.012, 1.0)\n" c̲at " p.inputs['Roughness'].default_value = 0.15\n" c̲at " nt.links.new(t.outputs[0], p.inputs['Emission Color'])\n" c̲at " p.inputs['Emission Strength'].default_value = strength\n" c̲at "\n" c̲at "def slides(name, stem, count, hold, strength):\n" c̲at " reel(name, stem + '.webm', strength)\n" c̲at "\n" c̲at "def place(o, into):\n" c̲at " (models[into] if into else scene.collection).objects.link(o)\n" c̲at " return o\n" c̲at "\n" c̲at "def boxes(name, rows, material, into=''):\n" c̲at " verts, faces = [], []\n" c̲at " for r in rows:\n" c̲at " ca, sa = math.cos(math.radians(r[6])), math.sin(math.radians(r[6]))\n" c̲at " k = len(verts)\n" c̲at " for i in range(8):\n" c̲at " x, y, z = ((i & 1) - 0.5) * r[3], ((i >> 1 & 1) - 0.5) * r[4], ((i >> 2) - 0.5) * r[5]\n" c̲at " verts.append((r[0] + x * ca - y * sa, r[1] + x * sa + y * ca, r[2] + z))\n" c̲at " faces += [tuple(k + i for i in f) for f in ((0, 1, 5, 4), (3, 2, 6, 7), (1, 3, 7, 5), (2, 0, 4, 6), (4, 5, 7, 6), (0, 2, 3, 1))]\n" c̲at " m = bpy.data.meshes.new(name)\n" c̲at " m.from_pydata(verts, [], faces)\n" c̲at " uv = m.uv_layers.new(name='UVMap')\n" c̲at " for i, d in enumerate(uv.data):\n" c̲at " d.uv = ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0))[i % 4]\n" c̲at " m.update()\n" c̲at " m.materials.append(mats[material])\n" c̲at " return place(bpy.data.objects.new(name, m), into)\n" c̲at "\n" c̲at "def sign(name, body, at, size, turn, stack, material):\n" c̲at " c = bpy.data.curves.new(name, type='FONT')\n" c̲at " c.body = chr(10).join(body) if stack else body\n" c̲at " c.size = size\n" c̲at " c.align_x = 'CENTER'\n" c̲at " c.align_y = 'TOP' if stack else 'CENTER'\n" c̲at " c.extrude = 0.06 * size\n" c̲at " c.space_line = 0.85\n" c̲at " if rig.get('font'):\n" c̲at " c.font = rig['font']\n" c̲at " c.materials.append(mats[material])\n" c̲at " o = place(bpy.data.objects.new(name, c), '')\n" c̲at " o.location = at\n" c̲at " o.rotation_euler = (math.pi / 2, 0.0, math.radians(turn))\n" c̲at "\n")
ʰplay7 : Char
ʰplay7 ← ("def model(name):\n" c̲at " models[name] = bpy.data.collections.new(name)\n" c̲at "\n" c̲at "def fleet(name, kind, rows):\n" c̲at " for i, r in enumerate(rows):\n" c̲at " o = place(bpy.data.objects.new('%s %d' % (name, i + 1), None), '')\n" c̲at " o.instance_type = 'COLLECTION'\n" c̲at " o.instance_collection = models[kind]\n" c̲at " o.rotation_euler = (0.0, 0.0, math.atan2(r[4] - r[1], r[3] - r[0]))\n" c̲at " for f, at in ((scene.frame_start, r[0:3]), (scene.frame_end, r[3:6])):\n" c̲at " o.location = at\n" c̲at " o.keyframe_insert('location', frame=f)\n" c̲at "\n" c̲at "def lamps(name, rows):\n" c̲at " for i, r in enumerate(rows):\n" c̲at " d = bpy.data.lights.new(name, type='POINT')\n" c̲at " d.color, d.energy, d.shadow_soft_size = r[3:6], r[6], r[7]\n" c̲at " place(bpy.data.objects.new('%s %d' % (name, i + 1), d), '').location = r[0:3]\n" c̲at "\n" c̲at "def spots(name, rows):\n" c̲at " for i, r in enumerate(rows):\n" c̲at " d = bpy.data.lights.new(name, type='SPOT')\n" c̲at " d.color, d.energy, d.spot_size, d.spot_blend, d.shadow_soft_size = r[6:9], r[9], math.radians(r[10]), 0.4, 0.15\n" c̲at " o = place(bpy.data.objects.new('%s %d' % (name, i + 1), d), '')\n" c̲at " o.location = r[0:3]\n" c̲at " o.rotation_euler = (Vector(r[3:6]) - Vector(r[0:3])).to_track_quat('-Z', 'Y').to_euler()\n" c̲at "\n" c̲at "def sky(horizon, zenith, strength):\n" c̲at " w = bpy.data.worlds.new('sky')\n" c̲at " w.use_nodes = True\n" c̲at " nt = w.node_tree\n" c̲at " nt.nodes.clear()\n" c̲at " g = node(nt, 'ShaderNodeNewGeometry')\n" c̲at " _, _, z = xyz(nt, g.outputs['Incoming'])\n" c̲at " b = node(nt, 'ShaderNodeBackground')\n" c̲at " feed(nt, b.inputs['Color'], blend(nt, step(nt, calc(nt, 'ABSOLUTE', z), 0.0, 0.6), horizon, zenith))\n" c̲at " b.inputs['Strength'].default_value = strength\n" c̲at " nt.links.new(b.outputs[0], node(nt, 'ShaderNodeOutputWorld').inputs['Surface'])\n" c̲at " scene.world = w\n" c̲at "\n")
ʰplay8 : Char
ʰplay8 ← ("def fog(name, rows, rgb, density, forward):\n" c̲at " m, nt, o = fresh(name)\n" c̲at " s = node(nt, 'ShaderNodeVolumeScatter')\n" c̲at " s.inputs['Color'].default_value = tuple(rgb) + (1.0,)\n" c̲at " s.inputs['Density'].default_value = density\n" c̲at " s.inputs['Anisotropy'].default_value = forward\n" c̲at " nt.links.new(s.outputs[0], o.inputs['Volume'])\n" c̲at " boxes(name, [tuple(r) + (0.0,) for r in rows], name)\n" c̲at "\n" c̲at "def steam(name, rows, rgb, density, speed):\n" c̲at " m, nt, o = fresh(name)\n" c̲at " tc = node(nt, 'ShaderNodeTexCoord')\n" c̲at " lx, ly, lz = xyz(nt, tc.outputs['Object'])\n" c̲at " g = node(nt, 'ShaderNodeNewGeometry')\n" c̲at " px, py, pz = xyz(nt, g.outputs['Position'])\n" c̲at " t = clock(nt)\n" c̲at " puff = noise(nt, join(nt, px, py, calc(nt, 'SUBTRACT', pz, calc(nt, 'MULTIPLY', t, speed))), 0.9, 4.0, calc(nt, 'MULTIPLY', t, 0.25))\n" c̲at " rad = calc(nt, 'SQRT', calc(nt, 'ADD', calc(nt, 'MULTIPLY', lx, lx), calc(nt, 'MULTIPLY', ly, ly)))\n" c̲at " up = calc(nt, 'ADD', lz, 0.5)\n" c̲at " wide = calc(nt, 'ADD', 0.12, calc(nt, 'MULTIPLY', up, 0.38))\n" c̲at " core = calc(nt, 'SUBTRACT', 1.0, step(nt, calc(nt, 'DIVIDE', rad, wide), 0.3, 1.0))\n" c̲at " fade = calc(nt, 'MULTIPLY', step(nt, up, 0.0, 0.08), calc(nt, 'SUBTRACT', 1.0, step(nt, up, 0.35, 1.0)))\n" c̲at " d = calc(nt, 'MULTIPLY', calc(nt, 'MULTIPLY', core, fade), calc(nt, 'MULTIPLY', density, step(nt, puff, 0.38, 0.7)))\n" c̲at " s = node(nt, 'ShaderNodeVolumeScatter')\n" c̲at " s.inputs['Color'].default_value = tuple(rgb) + (1.0,)\n" c̲at " s.inputs['Anisotropy'].default_value = 0.3\n" c̲at " nt.links.new(d, s.inputs['Density'])\n" c̲at " nt.links.new(s.outputs[0], o.inputs['Volume'])\n" c̲at " for i, r in enumerate(rows):\n" c̲at " b = boxes('%s %d' % (name, i + 1), [(0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0)], name)\n" c̲at " b.location, b.scale = r[0:3], r[3:6]\n" c̲at "\n" c̲at "def along(times, points, t):\n" c̲at " n = len(times)\n" c̲at " i = max(0, min(n - 2, max(k for k in range(n) if times[k] <= t or k == 0)))\n" c̲at " u = min(1.0, max(0.0, (t - times[i]) / (times[i + 1] - times[i])))\n" c̲at " p0, p1, p2, p3 = (Vector(points[max(0, min(n - 1, i + d))]) for d in (-1, 0, 1, 2))\n" c̲at " return 0.5 * (2 * p1 + (p2 - p0) * u + (2 * p0 - 5 * p1 + 4 * p2 - p3) * u * u + (3 * p1 - p0 - 3 * p2 + p3) * u ** 3)\n" c̲at "\n" c̲at "def fly(times, eyes, aims, lens, fstop):\n" c̲at " cam = place(bpy.data.objects.new('camera', bpy.data.cameras.new('camera')), '')\n" c̲at " aim = place(bpy.data.objects.new('aim', None), '')\n" c̲at " cam.data.lens = lens\n" c̲at " cam.data.clip_start, cam.data.clip_end = 0.1, 5000.0\n" c̲at " scene.camera = cam\n" c̲at " look = cam.constraints.new('TRACK_TO')\n" c̲at " look.target, look.track_axis, look.up_axis = aim, 'TRACK_NEGATIVE_Z', 'UP_Y'\n" c̲at " if fstop > 0.0:\n" c̲at " cam.data.dof.use_dof = True\n" c̲at " cam.data.dof.focus_object = aim\n" c̲at " cam.data.dof.aperture_fstop = fstop\n" c̲at " for f in range(scene.frame_start - 1, scene.frame_end + 2):\n" c̲at " t = (f - 1) / scene.render.fps\n" c̲at " cam.location, aim.location = along(times, eyes, t), along(times, aims, t)\n" c̲at " cam.keyframe_insert('location', frame=f)\n" c̲at " aim.keyframe_insert('location', frame=f)\n" c̲at "\n")
ʰplay9 : Char
ʰplay9 ← ("def bloom(threshold, strength, size):\n" c̲at " g = bpy.data.node_groups.new('bloom', 'CompositorNodeTree')\n" c̲at " g.interface.new_socket(name='Image', in_out='OUTPUT', socket_type='NodeSocketColor')\n" c̲at " src, glare, end = g.nodes.new('CompositorNodeRLayers'), g.nodes.new('CompositorNodeGlare'), g.nodes.new('NodeGroupOutput')\n" c̲at " glare.inputs['Type'].default_value = 'Bloom'\n" c̲at " glare.inputs['Threshold'].default_value = threshold\n" c̲at " glare.inputs['Strength'].default_value = strength\n" c̲at " glare.inputs['Size'].default_value = size\n" c̲at " g.links.new(src.outputs['Image'], glare.inputs['Image'])\n" c̲at " g.links.new(glare.outputs['Image'], end.inputs[0])\n" c̲at " scene.compositing_node_group = g\n" c̲at " scene.render.use_compositing = True\n" c̲at "\n" c̲at "def png(path):\n" c̲at " scene.render.image_settings.media_type = 'IMAGE'\n" c̲at " scene.render.image_settings.file_format = 'PNG'\n" c̲at " scene.render.filepath = path\n" c̲at "\n" c̲at "def still(file, seconds):\n" c̲at " scene.frame_set(frame(seconds))\n" c̲at " png(os.path.join(out, file))\n" c̲at " bpy.ops.render.render(write_still=True)\n" c̲at "\n" c̲at "def frames(folder, first, last):\n" c̲at " keep = scene.frame_start, scene.frame_end\n" c̲at " if last > 0:\n" c̲at " scene.frame_start, scene.frame_end = int(first), int(last)\n" c̲at " png(os.path.join(out, folder, ''))\n" c̲at " scene.render.use_overwrite = False\n" c̲at " bpy.ops.render.render(animation=True)\n" c̲at " scene.frame_start, scene.frame_end = keep\n" c̲at "\n" c̲at "def encode(folder, file):\n" c̲at " d = os.path.join(out, folder)\n" c̲at " names = sorted(n for n in os.listdir(d) if n.endswith('.png'))\n" c̲at " e = bpy.data.scenes.new('encode')\n" c̲at " r = e.render\n" c̲at " r.resolution_x, r.resolution_y, r.resolution_percentage = scene.render.resolution_x, scene.render.resolution_y, 100\n" c̲at " r.fps = scene.render.fps\n" c̲at " e.view_settings.view_transform = 'Standard'\n" c̲at " s = e.sequence_editor_create().strips.new_image('frames', os.path.join(d, names[0]), 1, 1)\n" c̲at " for n in names[1:]:\n" c̲at " s.elements.append(n)\n" c̲at " e.frame_start, e.frame_end = 1, len(names)\n" c̲at " r.image_settings.media_type = 'VIDEO'\n" c̲at " r.image_settings.file_format = 'FFMPEG'\n" c̲at " r.ffmpeg.format, r.ffmpeg.codec, r.ffmpeg.constant_rate_factor = 'MPEG4', 'H264', 'HIGH'\n" c̲at " r.filepath = os.path.join(out, file)\n" c̲at " bpy.ops.render.render(animation=True, scene='encode')\n" c̲at "\n")
ʰplay10 : Char
ʰplay10 ← ("def report():\n" c̲at " kinds = {}\n" c̲at " for o in scene.objects:\n" c̲at " kinds[o.type] = kinds.get(o.type, 0) + 1\n" c̲at " with open(os.path.join(out, 'report.txt'), 'w') as f:\n" c̲at " r = scene.render\n" c̲at " f.write('%s, %d by %d, %d frames at %d a second, %d samples' % (r.engine, r.resolution_x, r.resolution_y, scene.frame_end, r.fps, scene.cycles.samples) + chr(10))\n" c̲at " f.write('objects: ' + ', '.join('%d %s' % (kinds[k], k.lower()) for k in sorted(kinds)) + chr(10))\n" c̲at " f.write('faces: %d' % sum(len(o.data.polygons) for o in scene.objects if o.type == 'MESH') + chr(10))\n" c̲at " f.write('materials: ' + ' '.join(sorted(mats)) + chr(10))\n" c̲at " f.write('models: ' + ' '.join(sorted(models)) + chr(10))\n" c̲at " f.write('pictures: %d played, %d missing' % (rig.get('played', 0), rig.get('missing', 0)) + chr(10))\n" c̲at " print('cycles device: %s' % (rig.get('device') or 'CPU'))\n")
ˡhead : Char
cy:head: the player, the start of every script: an empty scene, the
output directory (the first argument after "--", made), and the
functions the calls below use -- stage, look, sky and bloom; the
materials (surface, neon, facade, wet, screen, reel, slides), each a graph of
shader nodes built here; boxes (one mesh a group, each face mapped
for a screen), sign, model and fleet; lamps and spots; fog and
steam; fly (the camera keyed every frame along a curve through its
eyes); still, frames, encode and report. Its letters are in JuliaMono
Black when work/fonts has it (just font), else Blender's own.
ˡhead ← ʰplay1 c̲at ʰplay2 c̲at ʰplay3 c̲at ʰplay4 c̲at ʰplay5 c̲at ʰplay6 c̲at ʰplay7 c̲at ʰplay8 c̲at ʰplay9 c̲at ʰplay10
Numbers and text into Python
ʰn̲ums : Any c => (a, b) -> c -> Char
ʰn̲ums ← { (v, k) z → "nums('" c̲at (f̲ormat r̲avel v) c̲at "', " c̲at (f̲ormat k) c̲at ")" }
ʰq̲uoteIn : Int -> Char -> Char
ʰq̲uoteIn ← { q t → 0 = t̲ally t ? ⎕U̲CHAR q c̲at q c ← ⎕U̲CS t e ← (c = q) ∨ c = 92 k ← (1 + e) r̲eplicate r̲ange t̲ally c m ← ((1 + e) r̲eplicate e) ∧ k ≠ 0 c̲at -1 d̲rop k (⎕U̲CHAR q) c̲at (⎕U̲CHAR (92 × m) + (1 − m) × (1 + e) r̲eplicate c) c̲at ⎕U̲CHAR q }
ˡl̲inear : Num a => a -> Float
cy:l_inear color: a color's channels, 0 to 255 (sRGB), as the linear values, 0 to 1, that Blender's materials and lights take
"cy:" u̲se< "Cycles"
ᶜʸl̲inear 0 255 0.0 1.0
ˡl̲inear ← { c → ((f̲loat c) ÷ 255.0) ^ 2.2 }
The picture
ˡs̲tage : Any f => (a, b, c, d, e, Char) -> f -> Char
(width, height, fps, seconds, samples, device) cy:s_tage 0: Python setting Cycles, the picture's size, the frame rate, the film's length and how many samples each pixel takes at most (noise is removed after: 24 show a scene, 64 to 128 finish it); device is "GPU" (the graphics card when Cycles finds one it can use -- Metal, OptiX, CUDA, HIP, oneAPI -- else the processor) or "CPU". The film look (AgX), so bright lights roll off as a camera's do. First, before anything else.
"cy:" u̲se< "Cycles"
(640, 360, 30, 6.0, 24, "GPU") ᶜʸs̲tage 0 stage(640, 360, 30, 6.0, 24, 'GPU')
ˡs̲tage ← { (w, h, fps, secs, samples, device) z → "stage(" c̲at (f̲ormat w) c̲at ", " c̲at (f̲ormat h) c̲at ", " c̲at (f̲ormat fps) c̲at ", " c̲at (f̲ormat secs) c̲at ", " c̲at (f̲ormat samples) c̲at ", " c̲at (ʰq̲uote device) c̲at ")\n" }
ˡl̲ook : Any c => (Char, a, b) -> c -> Char
(look, exposure, shutter) cy:l_ook 0: Python setting the look (one of Blender's AgX looks by name, "AgX - Punchy" for more contrast and color; "None" for none), the exposure in stops (0 as rendered) and motion blur: the shutter is open that part of a frame (0.5 as a film camera; 0 for no blur)
ˡl̲ook ← { (name, exposure, shutter) z → "look(" c̲at (ʰq̲uote name) c̲at ", " c̲at (f̲ormat exposure) c̲at ", " c̲at (f̲ormat shutter) c̲at ")\n" }
ˡs̲ky : (Num a, Num b, Any d) => (a, b, c) -> d -> Char
(horizon, zenith, strength) cy:s_ky 0: Python making the sky: one color at the horizon blending into another overhead, that bright (1 as given; a night sky's colors are near black)
ˡs̲ky ← { (horizon, zenith, strength) z → "sky(" c̲at (ʰr̲gb horizon) c̲at ", " c̲at (ʰr̲gb zenith) c̲at ", " c̲at (f̲ormat strength) c̲at ")\n" }
ˡb̲loom : Any d => (a, b, c) -> d -> Char
(threshold, strength, size) cy:b_loom 0: Python making bright things bleed light into the picture round them, as a lens does: what is brighter than the threshold (1 is white) glows, that strongly (0 to 1), that wide (0 to 1)
ˡb̲loom ← { (threshold, strength, size) z → "bloom(" c̲at (f̲ormat threshold) c̲at ", " c̲at (f̲ormat strength) c̲at ", " c̲at (f̲ormat size) c̲at ")\n" }
Materials
ˡs̲urface : (Num a, Any d) => (Char, a, b, c) -> d -> Char
(name, color, roughness, metallic) cy:s_urface 0: Python making a plain material: its color, how rough (0 a mirror, 1 chalk) and how metallic (0 or 1)
"cy:" u̲se< "Cycles"
("steel", 255 255 255, 0.3, 1.0) ᶜʸs̲urface 0 surface('steel', nums('1.0 1.0 1.0', 3)[0], 0.3, 1.0)
ˡs̲urface ← { (name, rgb, roughness, metallic) z → "surface(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰr̲gb rgb) c̲at ", " c̲at (f̲ormat roughness) c̲at ", " c̲at (f̲ormat metallic) c̲at ")\n" }
ˡn̲eon : (Num a, Any c) => (Char, a, b) -> c -> Char
(name, color, strength) cy:n_eon 0: Python making a material that only gives off light, that strongly (1 its color as given; 5 to 10 a sign that lights the street)
ˡn̲eon ← { (name, rgb, strength) z → "neon(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰr̲gb rgb) c̲at ", " c̲at (f̲ormat strength) c̲at ")\n" }
ˡf̲acade : (Num a, Num b, Num c, Num d, Any g) => (Char, a, b, c, d, e, f) -> g -> Char
(name, wall, lit a, lit b, cell, lit, glow) cy:f_acade 0: Python making a building's skin, worked out from where each point of a wall is: the wall is cut into cells (cell: a window's bay and a floor's height, meters), each cell a dark glass pane in a wall of the wall's color, weathered; a share of the panes (lit, 0 to 1, more on some floors than others) are lit rooms, each a color between lit a and lit b and its own brightness, glowing that strongly. Roofs have no windows. For boxes that stand upright and do not move.
ˡf̲acade ← { (name, wall, a, b, cell, lit, glow) z → "facade(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰr̲gb wall) c̲at ", " c̲at (ʰr̲gb a) c̲at ", " c̲at (ʰr̲gb b) c̲at ", " c̲at (ʰt̲uple cell) c̲at ", " c̲at (f̲ormat lit) c̲at ", " c̲at (f̲ormat glow) c̲at ")\n" }
ˡw̲et : (Num a, Any e) => (Char, a, b, c, d) -> e -> Char
(name, color, puddles, size, ripple) cy:w_et 0: Python making wet ground: rough where it is only damp, a mirror where water stands -- puddles is the share under water (0 to 1), size how wide a puddle is (meters), ripple how much rain disturbs the water (0 still)
ˡw̲et ← { (name, rgb, puddles, size, ripple) z → "wet(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰr̲gb rgb) c̲at ", " c̲at (f̲ormat puddles) c̲at ", " c̲at (f̲ormat size) c̲at ", " c̲at (f̲ormat ripple) c̲at ")\n" }
ˡs̲creen : (Num a, Num b, Any e) => (Char, Char, a, b, c, d) -> e -> Char
(name, kind, a, b, speed, strength) cy:s_creen 0: Python making a screen that plays a moving picture in two colors, worked out from the time, on each face of a box: kind is "bars" (stripes rolling up), "rings" (rings spreading from the middle), "rain" (columns of falling glyphs) or "tiles" (a mosaic that changes); speed is cycles a second; it glows that strongly
ˡs̲creen ← { (name, kind, a, b, speed, strength) z → "screen(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰq̲uote kind) c̲at ", " c̲at (ʰr̲gb a) c̲at ", " c̲at (ʰr̲gb b) c̲at ", " c̲at (f̲ormat speed) c̲at ", " c̲at (f̲ormat strength) c̲at ")\n" }
ˡm̲edia : Char -> Char
cy:m_edia folder: Python saying where the files that cy:r_eel and cy:s_lides name are: a folder, from where the player runs. Before them.
"cy:" u̲se< "Cycles"
ᶜʸm̲edia "media" media('media')
ˡm̲edia ← { folder → "media(" c̲at (ʰq̲uote folder) c̲at ")\n" }
ˡr̲eel : Any b => (Char, Char, a) -> b -> Char
(name, file, strength) cy:r_eel 0: Python making a screen that plays a video file (or shows a picture) from the media folder, looping, on each face of a box, glowing that strongly (1 the picture as it is). When the file is not there the screen plays tiles in its place, and the report counts it missing.
ˡr̲eel ← { (name, path, strength) z → "reel(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰq̲uote path) c̲at ", " c̲at (f̲ormat strength) c̲at ")\n" }
ˡs̲lides : Any d => (Char, Char, a, b, c) -> d -> Char
(name, stem, count, hold, strength) cy:s_lides 0: Python making a screen that shows still pictures in turn, each hold seconds, fading into the next: STEM-1.jpg to STEM-count.jpg in the media folder. A player that draws live shows the stills (cheaper than a video); Blender's plays STEM.webm, the same slides made a video.
"cy:" u̲se< "Cycles"
("ads", "art", 16, 4.0, 1.5) ᶜʸs̲lides 0 slides('ads', 'art', 16, 4.0, 1.5)
ˡs̲lides ← { (name, stem, count, hold, strength) z → "slides(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰq̲uote stem) c̲at ", " c̲at (f̲ormat count) c̲at ", " c̲at (f̲ormat hold) c̲at ", " c̲at (f̲ormat strength) c̲at ")\n" }
Things
ˡb̲oxes : (Num a, Any b) => (Char, a, Char) -> b -> Char
(name, table, material) cy:b_oxes 0: Python making a group of boxes as one object NAME wearing the material: a row a box -- x y z (its middle), w d h (its size) and its turn about the upright axis. A tower h tall standing on the ground has its middle at h / 2.
"cy:" u̲se< "Cycles"
("tower", 1 7 r̲eshape 0 0 50 20 20 100 0, "glass") ᶜʸb̲oxes 0 boxes('tower', nums('0.0 0.0 50.0 20.0 20.0 100.0 0.0', 7), 'glass')
ˡb̲oxes ← { (name, t, material) z → "boxes(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((f̲loat t, 7) ʰn̲ums 0) c̲at ", " c̲at (ʰq̲uote material) c̲at ")\n" }
ˡs̲ign : (Num a, Any e) => (Char, Char, a, b, c, d, Char) -> e -> Char
(name, text, place, size, turn, stack, material) cy:s_ign 0: Python making a sign of solid letters that tall, standing upright, its middle at place (x y z), turned about the upright axis (0 faces -y), wearing the material (cy:n_eon); stack 1 writes the letters one below another, hanging from place
ˡs̲ign ← { (name, body, at, size, turn, stack, material) z → "sign(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰq̲uote body) c̲at ", " c̲at (ʰt̲uple at) c̲at ", " c̲at (f̲ormat size) c̲at ", " c̲at (f̲ormat turn) c̲at ", " c̲at (f̲ormat stack) c̲at ", " c̲at (ʰq̲uote material) c̲at ")\n" }
ˡm̲odel : Char -> Char
cy:m_odel name: Python starting a model: a thing made once and shown many times (a vehicle); its parts are cy:p_arts, about its own middle, its front along x
ˡm̲odel ← { name → "model(" c̲at (ʰq̲uote name) c̲at ")\n" }
ˡp̲arts : (Num a, Any b) => (Char, a, Char, Char) -> b -> Char
(name, table, material, model) cy:p_arts 0: Python making boxes, as cy:b_oxes, as a part of the model
ˡp̲arts ← { (name, t, material, model) z → "boxes(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((f̲loat t, 7) ʰn̲ums 0) c̲at ", " c̲at (ʰq̲uote material) c̲at ", " c̲at (ʰq̲uote model) c̲at ")\n" }
ˡf̲leet : (Num a, Any b) => (Char, Char, a) -> b -> Char
(name, model, table) cy:f_leet 0: Python showing the model once a row of the table, each moving at an even speed through the whole film: from x y z (at the start) to x y z (at the end), facing the way it goes
ˡf̲leet ← { (name, model, t) z → "fleet(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰq̲uote model) c̲at ", " c̲at ((f̲loat t, 6) ʰn̲ums 0) c̲at ")\n" }
Light and air
ˡl̲amps : (Num a, Any b) => (Char, a) -> b -> Char
(name, table) cy:l_amps 0: Python making lamps that shine all round, a row each: x y z, r g b, its strength (watts) and its radius (meters: a larger lamp casts softer shadows)
ˡl̲amps ← { (name, t) z → p ← (3 t̲ake₂ f̲loat t) c̲at₂ (ˡl̲inear 3 t̲ake₂ 3 d̲rop₂ t) c̲at₂ 6 d̲rop₂ f̲loat t "lamps(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((p, 8) ʰn̲ums 0) c̲at ")\n" }
ˡs̲pots : (Num a, Any b) => (Char, a) -> b -> Char
(name, table) cy:s_pots 0: Python making spotlights, a row each: at x y z, aimed at x y z, r g b, its strength (watts) and the cone's angle
ˡs̲pots ← { (name, t) z → p ← (6 t̲ake₂ f̲loat t) c̲at₂ (ˡl̲inear 3 t̲ake₂ 6 d̲rop₂ t) c̲at₂ 9 d̲rop₂ f̲loat t "spots(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((p, 11) ʰn̲ums 0) c̲at ")\n" }
ˡf̲og : (Num a, Num b, Any e) => (Char, a, b, c, d) -> e -> Char
(name, table, color, density, forward) cy:f_og 0: Python filling boxes with even haze that scatters light, so lamps and signs glow in the air and far things fade: a row a box, x y z (its middle), w d h; density is how much is scattered a meter (0.001 a clear night, 0.01 thick); forward (0 to 1) is how much goes on the way it was going
ˡf̲og ← { (name, t, rgb, density, forward) z → "fog(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((f̲loat t, 6) ʰn̲ums 0) c̲at ", " c̲at (ʰr̲gb rgb) c̲at ", " c̲at (f̲ormat density) c̲at ", " c̲at (f̲ormat forward) c̲at ")\n" }
ˡs̲team : (Num a, Num b, Any e) => (Char, a, b, c, d) -> e -> Char
(name, table, color, density, speed) cy:s_team 0: Python making plumes of steam, a row each: x y z (its middle) and w d h, the box the plume fills -- thin at the bottom's middle, wider and fainter as it rises, billowing, climbing speed meters a second
ˡs̲team ← { (name, t, rgb, density, speed) z → "steam(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((f̲loat t, 6) ʰn̲ums 0) c̲at ", " c̲at (ʰr̲gb rgb) c̲at ", " c̲at (f̲ormat density) c̲at ", " c̲at (f̲ormat speed) c̲at ")\n" }
The camera
ˡf̲ly : (Num a, Num b, Num c, Any f) => (a, b, c, d, e) -> f -> Char
(times, eyes, aims, lens, fstop) cy:f_ly 0: Python flying the camera: at each time (k seconds) it is at an eye (k by 3) looking at an aim (k by 3), and between them it goes along a smooth curve through the eyes, looking along a smooth curve through the aims; lens is its focal length in mm (24 wide, 50 as an eye); it is focused on the aim with an aperture of fstop (1.4 blurs what is nearer and farther, 8 little; 0 keeps everything sharp)
ˡf̲ly ← { (ts, e, a, lens, fstop) z → "fly(" c̲at ((f̲loat ts, t̲ally ts) ʰn̲ums 0) c̲at "[0], " c̲at ((f̲loat e, 3) ʰn̲ums 0) c̲at ", " c̲at ((f̲loat a, 3) ʰn̲ums 0) c̲at ", " c̲at (f̲ormat lens) c̲at ", " c̲at (f̲ormat fstop) c̲at ")\n" }
Rendering
ˡs̲till : Any b => (Char, a) -> b -> Char
(file, seconds) cy:s_till 0: Python rendering the frame at that time to out/FILE (PNG)
"cy:" u̲se< "Cycles"
("street.png", 5.5) ᶜʸs̲till 0 still('street.png', 5.5)
ˡs̲till ← { (file, secs) z → "still(" c̲at (ʰq̲uote file) c̲at ", " c̲at (f̲ormat secs) c̲at ")\n" }
ˡf̲rames : Any c => (Char, a, b) -> c -> Char
(folder, first, last) cy:f_rames 0: Python rendering the frames from first to last (0 0 for the whole film) to out/FOLDER, a PNG each (0001.png ...). A frame already there is not rendered again, so a long render may be stopped and run again, or run a part at a time.
ˡf̲rames ← { (folder, first, last) z → "frames(" c̲at (ʰq̲uote folder) c̲at ", " c̲at (f̲ormat first) c̲at ", " c̲at (f̲ormat last) c̲at ")\n" }
ˡe̲ncode : Any a => (Char, Char) -> a -> Char
(folder, file) cy:e_ncode 0: Python making the video out/FILE (MP4, H.264) of the frames in out/FOLDER, in order, at the film's rate
ˡe̲ncode ← { (folder, file) z → "encode(" c̲at (ʰq̲uote folder) c̲at ", " c̲at (ʰq̲uote file) c̲at ")\n" }