sourceextensions/blender/lib/Cycles.xtl

1⍝│ Cycles.xtl -- arrays to a ray-traced film: a Blender scene for Cycles 2⍝│ (path tracing: real reflections, shadows from every light, light 3⍝│ scattered in fog) described by X_eTaL arrays. A program works out the 4⍝│ scene as tables -- a row a box, a lamp, a vehicle, a puff of steam -- 5⍝│ and each function here writes one table into Blender's Python as 6⍝│ numbers, one call of the player for a whole group. The player 7⍝│ (cy:head) is fixed Python, the same for every film: it reads the 8⍝│ numbers and makes the objects, materials and keys, and decides 9⍝│ nothing. A film is cy:head, then cy:s_tage, the materials, the groups 10⍝│ that wear them, lights, fog, the camera's flight, then cy:s_till, 11⍝│ or cy:f_rames and cy:e_ncode; written with bl:w_rite! and run by 12⍝│ bp:launcher through bl:r_un!. 13⍝│ 14⍝│ Nothing is loaded: every surface is worked out by its material from 15⍝│ where it is -- a facade's windows from the wall's own coordinates, a 16⍝│ street's puddles from noise, a screen's picture from its face and 17⍝│ the time -- so a table of boxes is a city. (cy:r_eel is the one 18⍝│ exception: a screen playing a video file.) 19⍝│ 20⍝│ Places are meters, z up; times are seconds; angles are degrees; 21⍝│ colors are 0 to 255 (sRGB), made linear here; a light's strength is 22⍝│ watts. Written for Blender 5.1. 23⍝│ Import: "cy:" u_se< "Cycles" 24 25⍝━━ The player 26 27⍝ the player, in parts (one expression nests too deep): the start 28ʰplay1 ← ("import bpy, math, os, sys\n" c̲at 29 "from mathutils import Vector\n" c̲at 30 "args = sys.argv[sys.argv.index('--') + 1:]\n" c̲at 31 "out = args[0]\n" c̲at 32 "os.makedirs(out, exist_ok=True)\n" c̲at 33 "bpy.ops.wm.read_factory_settings(use_empty=True)\n" c̲at 34 "bpy.context.preferences.edit.keyframe_new_interpolation_type = 'LINEAR'\n" c̲at 35 "scene = bpy.context.scene\n" c̲at 36 "mats = {}\n" c̲at 37 "models = {}\n" c̲at 38 "rig = {}\n" c̲at 39 "\n" c̲at 40 "def nums(text, k):\n" c̲at 41 " v = [float(t) for t in text.split()]\n" c̲at 42 " return [tuple(v[i:i + k]) for i in range(0, len(v), k)]\n" c̲at 43 "\n" c̲at 44 "def frame(t):\n" c̲at 45 " return 1 + round(t * scene.render.fps)\n" c̲at 46 "\n" c̲at 47 "def gpu():\n" c̲at 48 " p = bpy.context.preferences.addons['cycles'].preferences\n" c̲at 49 " for kind in ('OPTIX', 'CUDA', 'HIP', 'ONEAPI', 'METAL'):\n" c̲at 50 " try:\n" c̲at 51 " p.compute_device_type = kind\n" c̲at 52 " except TypeError:\n" c̲at 53 " continue\n" c̲at 54 " p.get_devices()\n" c̲at 55 " if any(d.type == kind for d in p.devices):\n" c̲at 56 " for d in p.devices:\n" c̲at 57 " d.use = d.type == kind\n" c̲at 58 " return kind\n" c̲at 59 " return ''\n" c̲at 60 "\n" c̲at 61 "def font():\n" c̲at 62 " d = os.getcwd()\n" c̲at 63 " while True:\n" c̲at 64 " p = os.path.join(d, 'work', 'fonts', 'JuliaMono-Black.ttf')\n" c̲at 65 " if os.path.exists(p):\n" c̲at 66 " return bpy.data.fonts.load(p, check_existing=True)\n" c̲at 67 " if os.path.dirname(d) == d:\n" c̲at 68 " return None\n" c̲at 69 " d = os.path.dirname(d)\n" c̲at 70 "\n" c̲at 71 "rig['font'] = font()\n" c̲at 72 "\n") 73 74⍝ the player, part 2: stage and after 75ʰplay2 ← ("def stage(w, h, fps, seconds, samples, device):\n" c̲at 76 " scene.render.engine = 'CYCLES'\n" c̲at 77 " c = scene.cycles\n" c̲at 78 " rig['device'] = gpu() if device == 'GPU' else ''\n" c̲at 79 " c.device = 'GPU' if rig['device'] else 'CPU'\n" c̲at 80 " c.samples = int(samples)\n" c̲at 81 " c.use_adaptive_sampling = True\n" c̲at 82 " c.adaptive_threshold = 0.02\n" c̲at 83 " c.use_denoising = True\n" c̲at 84 " c.max_bounces = 6\n" c̲at 85 " c.diffuse_bounces = 2\n" c̲at 86 " c.glossy_bounces = 4\n" c̲at 87 " c.transmission_bounces = 4\n" c̲at 88 " c.volume_bounces = 1\n" c̲at 89 " c.sample_clamp_indirect = 8.0\n" c̲at 90 " scene.render.use_persistent_data = True\n" c̲at 91 " scene.render.resolution_x, scene.render.resolution_y = int(w), int(h)\n" c̲at 92 " scene.render.resolution_percentage = 100\n" c̲at 93 " scene.render.fps = int(fps)\n" c̲at 94 " scene.frame_start, scene.frame_end = 1, frame(seconds)\n" c̲at 95 " scene.view_settings.view_transform = 'AgX'\n" c̲at 96 "\n" c̲at 97 "def look(name, exposure, shutter):\n" c̲at 98 " try:\n" c̲at 99 " scene.view_settings.look = name\n" c̲at 100 " except TypeError:\n" c̲at 101 " pass\n" c̲at 102 " scene.view_settings.exposure = exposure\n" c̲at 103 " scene.render.use_motion_blur = shutter > 0.0\n" c̲at 104 " scene.render.motion_blur_shutter = max(shutter, 0.01)\n" c̲at 105 "\n" c̲at 106 "def node(nt, kind, **sets):\n" c̲at 107 " n = nt.nodes.new(kind)\n" c̲at 108 " for k, v in sets.items():\n" c̲at 109 " setattr(n, k, v)\n" c̲at 110 " return n\n" c̲at 111 "\n" c̲at 112 "def feed(nt, socket, value):\n" c̲at 113 " if hasattr(value, 'links'):\n" c̲at 114 " nt.links.new(value, socket)\n" c̲at 115 " elif hasattr(socket.default_value, '__len__') and not hasattr(value, '__len__'):\n" c̲at 116 " socket.default_value = (value,) * len(socket.default_value)\n" c̲at 117 " else:\n" c̲at 118 " socket.default_value = value\n" c̲at 119 "\n") 120 121⍝ the player, part 3: calc and after 122ʰplay3 ← ("def calc(nt, op, a, b=None, c=None):\n" c̲at 123 " n = node(nt, 'ShaderNodeMath', operation=op)\n" c̲at 124 " for i, v in enumerate((a, b, c)):\n" c̲at 125 " if v is not None:\n" c̲at 126 " feed(nt, n.inputs[i], v)\n" c̲at 127 " return n.outputs[0]\n" c̲at 128 "\n" c̲at 129 "def blend(nt, f, a, b):\n" c̲at 130 " n = node(nt, 'ShaderNodeMix', data_type='RGBA')\n" c̲at 131 " feed(nt, n.inputs[0], f)\n" c̲at 132 " feed(nt, n.inputs[6], a if hasattr(a, 'links') else tuple(a) + (1.0,))\n" c̲at 133 " feed(nt, n.inputs[7], b if hasattr(b, 'links') else tuple(b) + (1.0,))\n" c̲at 134 " return n.outputs[2]\n" c̲at 135 "\n" c̲at 136 "def step(nt, x, lo, hi):\n" c̲at 137 " n = node(nt, 'ShaderNodeMapRange', interpolation_type='SMOOTHSTEP')\n" c̲at 138 " feed(nt, n.inputs[0], x)\n" c̲at 139 " n.inputs[1].default_value, n.inputs[2].default_value = lo, hi\n" c̲at 140 " return n.outputs[0]\n" c̲at 141 "\n" c̲at 142 "def xyz(nt, v):\n" c̲at 143 " n = node(nt, 'ShaderNodeSeparateXYZ')\n" c̲at 144 " nt.links.new(v, n.inputs[0])\n" c̲at 145 " return n.outputs\n" c̲at 146 "\n" c̲at 147 "def join(nt, x, y, z):\n" c̲at 148 " n = node(nt, 'ShaderNodeCombineXYZ')\n" c̲at 149 " for s, v in zip(n.inputs, (x, y, z)):\n" c̲at 150 " feed(nt, s, v)\n" c̲at 151 " return n.outputs[0]\n" c̲at 152 "\n" c̲at 153 "def noise(nt, v, scale, detail, w=None):\n" c̲at 154 " n = node(nt, 'ShaderNodeTexNoise', noise_dimensions='4D' if w is not None else '3D')\n" c̲at 155 " feed(nt, n.inputs['Vector'], v)\n" c̲at 156 " if w is not None:\n" c̲at 157 " feed(nt, n.inputs['W'], w)\n" c̲at 158 " n.inputs['Scale'].default_value = scale\n" c̲at 159 " n.inputs['Detail'].default_value = detail\n" c̲at 160 " return n.outputs[0]\n" c̲at 161 "\n") 162 163⍝ the player, part 4: dice and after 164ʰplay4 ← ("def dice(nt, v):\n" c̲at 165 " n = node(nt, 'ShaderNodeTexWhiteNoise', noise_dimensions='3D')\n" c̲at 166 " feed(nt, n.inputs['Vector'], v)\n" c̲at 167 " return n.outputs\n" c̲at 168 "\n" c̲at 169 "def clock(nt):\n" c̲at 170 " n = node(nt, 'ShaderNodeValue')\n" c̲at 171 " d = n.outputs[0].driver_add('default_value').driver\n" c̲at 172 " d.type = 'SCRIPTED'\n" c̲at 173 " d.expression = 'frame / %d' % scene.render.fps\n" c̲at 174 " return n.outputs[0]\n" c̲at 175 "\n" c̲at 176 "def fresh(name):\n" c̲at 177 " m = bpy.data.materials.new(name)\n" c̲at 178 " m.use_nodes = True\n" c̲at 179 " nt = m.node_tree\n" c̲at 180 " nt.nodes.clear()\n" c̲at 181 " mats[name] = m\n" c̲at 182 " return m, nt, node(nt, 'ShaderNodeOutputMaterial')\n" c̲at 183 "\n" c̲at 184 "def shell(nt, o):\n" c̲at 185 " p = node(nt, 'ShaderNodeBsdfPrincipled')\n" c̲at 186 " nt.links.new(p.outputs[0], o.inputs['Surface'])\n" c̲at 187 " return p\n" c̲at 188 "\n" c̲at 189 "def surface(name, rgb, roughness, metallic):\n" c̲at 190 " m, nt, o = fresh(name)\n" c̲at 191 " p = shell(nt, o)\n" c̲at 192 " p.inputs['Base Color'].default_value = tuple(rgb) + (1.0,)\n" c̲at 193 " p.inputs['Roughness'].default_value = roughness\n" c̲at 194 " p.inputs['Metallic'].default_value = metallic\n" c̲at 195 "\n" c̲at 196 "def neon(name, rgb, strength):\n" c̲at 197 " m, nt, o = fresh(name)\n" c̲at 198 " e = node(nt, 'ShaderNodeEmission')\n" c̲at 199 " e.inputs['Color'].default_value = tuple(rgb) + (1.0,)\n" c̲at 200 " e.inputs['Strength'].default_value = strength\n" c̲at 201 " nt.links.new(e.outputs[0], o.inputs['Surface'])\n" c̲at 202 "\n" c̲at 203 "def facade(name, wall, lit_a, lit_b, cell, lit, glow):\n" c̲at 204 " m, nt, o = fresh(name)\n" c̲at 205 " g = node(nt, 'ShaderNodeNewGeometry')\n" c̲at 206 " px, py, pz = xyz(nt, g.outputs['Position'])\n" c̲at 207 " nx, ny, nz = xyz(nt, g.outputs['True Normal'])\n" c̲at 208 " ax = calc(nt, 'GREATER_THAN', calc(nt, 'ABSOLUTE', nx), 0.5)\n" c̲at 209 " roof = calc(nt, 'GREATER_THAN', calc(nt, 'ABSOLUTE', nz), 0.5)\n" c̲at 210 " u = calc(nt, 'ADD', px, calc(nt, 'MULTIPLY', ax, calc(nt, 'SUBTRACT', py, px)))\n" c̲at 211 " depth = calc(nt, 'ADD', py, calc(nt, 'MULTIPLY', ax, calc(nt, 'SUBTRACT', px, py)))\n" c̲at 212 " cu = calc(nt, 'DIVIDE', u, cell[0])\n" c̲at 213 " cv = calc(nt, 'DIVIDE', pz, cell[1])\n" c̲at 214 " iu, iv = calc(nt, 'FLOOR', cu), calc(nt, 'FLOOR', cv)\n" c̲at 215 " fu, fv = calc(nt, 'FRACT', cu), calc(nt, 'FRACT', cv)\n" c̲at 216 " side = calc(nt, 'ADD', calc(nt, 'ROUND', calc(nt, 'MULTIPLY', depth, 2.0)), calc(nt, 'MULTIPLY', ax, 977.0))\n" c̲at 217 " 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 218 " pane = calc(nt, 'MULTIPLY', pane, calc(nt, 'SUBTRACT', 1.0, roof))\n" c̲at 219 " r = dice(nt, join(nt, iu, iv, side))\n" c̲at 220 " floor = dice(nt, join(nt, 0.0, iv, side))\n" c̲at 221 " chance = calc(nt, 'ADD', lit, calc(nt, 'MULTIPLY', calc(nt, 'SUBTRACT', floor[0], 0.5), 0.5))\n" c̲at 222 " on = calc(nt, 'MULTIPLY', pane, calc(nt, 'LESS_THAN', r[0], chance))\n" c̲at 223 " cr, cg, cb = xyz(nt, r[1])\n" c̲at 224 " 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 225 " wallc = blend(nt, grime, [0.45 * x for x in wall], [1.25 * x for x in wall])\n" c̲at 226 " p = shell(nt, o)\n" c̲at 227 " feed(nt, p.inputs['Base Color'], blend(nt, pane, wallc, (0.012, 0.014, 0.02)))\n" c̲at 228 " 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 229 " feed(nt, p.inputs['Emission Color'], blend(nt, cg, lit_a, lit_b))\n" c̲at 230 " feed(nt, p.inputs['Emission Strength'], calc(nt, 'MULTIPLY', on, calc(nt, 'MULTIPLY', glow, calc(nt, 'ADD', 0.25, cb))))\n" c̲at 231 " b = node(nt, 'ShaderNodeBump')\n" c̲at 232 " b.inputs['Strength'].default_value = 0.3\n" c̲at 233 " feed(nt, b.inputs['Height'], calc(nt, 'SUBTRACT', calc(nt, 'MULTIPLY', grime, 0.05), calc(nt, 'MULTIPLY', pane, 0.08)))\n" c̲at 234 " nt.links.new(b.outputs[0], p.inputs['Normal'])\n" c̲at 235 "\n") 236 237⍝ the player, part 5: wet and after 238ʰplay5 ← ("def wet(name, rgb, puddles, size, ripple):\n" c̲at 239 " m, nt, o = fresh(name)\n" c̲at 240 " g = node(nt, 'ShaderNodeNewGeometry')\n" c̲at 241 " pos = g.outputs['Position']\n" c̲at 242 " big = noise(nt, pos, 1.0 / size, 3.0)\n" c̲at 243 " th = 0.5 + (0.5 - puddles) * 0.5\n" c̲at 244 " pool = step(nt, big, th - 0.03, th + 0.03)\n" c̲at 245 " fine = noise(nt, pos, 9.0, 6.0)\n" c̲at 246 " grit = noise(nt, pos, 60.0, 2.0)\n" c̲at 247 " rain = noise(nt, pos, 14.0, 1.0, calc(nt, 'MULTIPLY', clock(nt), 2.5))\n" c̲at 248 " p = shell(nt, o)\n" c̲at 249 " dry = blend(nt, fine, [0.5 * x for x in rgb], [1.3 * x for x in rgb])\n" c̲at 250 " feed(nt, p.inputs['Base Color'], blend(nt, pool, dry, [0.25 * x for x in rgb]))\n" c̲at 251 " rough = calc(nt, 'ADD', 0.22, calc(nt, 'MULTIPLY', fine, 0.3))\n" c̲at 252 " feed(nt, p.inputs['Roughness'], calc(nt, 'ADD', 0.015, calc(nt, 'MULTIPLY', calc(nt, 'SUBTRACT', 1.0, pool), rough)))\n" c̲at 253 " b = node(nt, 'ShaderNodeBump')\n" c̲at 254 " b.inputs['Strength'].default_value = 0.5\n" c̲at 255 " b.inputs['Distance'].default_value = 0.02\n" c̲at 256 " dryh = calc(nt, 'MULTIPLY', calc(nt, 'SUBTRACT', 1.0, pool), calc(nt, 'ADD', grit, calc(nt, 'MULTIPLY', fine, 2.0)))\n" c̲at 257 " feed(nt, b.inputs['Height'], calc(nt, 'ADD', dryh, calc(nt, 'MULTIPLY', pool, calc(nt, 'MULTIPLY', rain, ripple))))\n" c̲at 258 " nt.links.new(b.outputs[0], p.inputs['Normal'])\n" c̲at 259 "\n" c̲at 260 "def screen(name, kind, a, b, speed, strength):\n" c̲at 261 " m, nt, o = fresh(name)\n" c̲at 262 " uv = node(nt, 'ShaderNodeUVMap')\n" c̲at 263 " u, v, _ = xyz(nt, uv.outputs[0])\n" c̲at 264 " t = calc(nt, 'MULTIPLY', clock(nt), speed)\n" c̲at 265 " if kind == 'bars':\n" c̲at 266 " 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 267 " level = calc(nt, 'ADD', 0.35, calc(nt, 'MULTIPLY', f, 0.65))\n" c̲at 268 " elif kind == 'rings':\n" c̲at 269 " du, dv = calc(nt, 'SUBTRACT', u, 0.5), calc(nt, 'SUBTRACT', v, 0.5)\n" c̲at 270 " d = calc(nt, 'SQRT', calc(nt, 'ADD', calc(nt, 'MULTIPLY', du, du), calc(nt, 'MULTIPLY', dv, dv)))\n" c̲at 271 " 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 272 " level = calc(nt, 'ADD', 0.3, calc(nt, 'MULTIPLY', f, 0.7))\n" c̲at 273 " elif kind == 'rain':\n" c̲at 274 " col = calc(nt, 'FLOOR', calc(nt, 'MULTIPLY', u, 28.0))\n" c̲at 275 " r = dice(nt, join(nt, col, 3.0, 7.0))\n" c̲at 276 " _, r2, r3 = xyz(nt, r[1])\n" c̲at 277 " 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 278 " cell = calc(nt, 'FLOOR', calc(nt, 'MULTIPLY', v, 44.0))\n" c̲at 279 " glyph = dice(nt, join(nt, col, cell, calc(nt, 'FLOOR', calc(nt, 'MULTIPLY', t, 6.0))))\n" c̲at 280 " f = calc(nt, 'POWER', fall, 6.0)\n" c̲at 281 " level = calc(nt, 'MULTIPLY', calc(nt, 'POWER', fall, 3.0), calc(nt, 'ADD', 0.3, glyph[0]))\n" c̲at 282 " else:\n" c̲at 283 " cu, cv = calc(nt, 'FLOOR', calc(nt, 'MULTIPLY', u, 6.0)), calc(nt, 'FLOOR', calc(nt, 'MULTIPLY', v, 4.0))\n" c̲at 284 " r = dice(nt, join(nt, cu, cv, calc(nt, 'FLOOR', t)))\n" c̲at 285 " f = r[0]\n" c̲at 286 " _, r2, _ = xyz(nt, r[1])\n" c̲at 287 " level = calc(nt, 'ADD', 0.15, calc(nt, 'MULTIPLY', r2, 0.85))\n" c̲at 288 " lines = calc(nt, 'ADD', 0.8, calc(nt, 'MULTIPLY', 0.2, calc(nt, 'SINE', calc(nt, 'MULTIPLY', v, 400.0))))\n" c̲at 289 " p = shell(nt, o)\n" c̲at 290 " p.inputs['Base Color'].default_value = (0.01, 0.01, 0.012, 1.0)\n" c̲at 291 " p.inputs['Roughness'].default_value = 0.15\n" c̲at 292 " feed(nt, p.inputs['Emission Color'], blend(nt, f, a, b))\n" c̲at 293 " feed(nt, p.inputs['Emission Strength'], calc(nt, 'MULTIPLY', strength, calc(nt, 'MULTIPLY', level, lines)))\n" c̲at 294 "\n") 295 296⍝ the player, part 6: reel and after 297ʰplay6 ← ("def media(folder):\n" c̲at 298 " rig['media'] = folder\n" c̲at 299 "\n" c̲at 300 "def reel(name, path, strength):\n" c̲at 301 " file = os.path.abspath(os.path.join(rig.get('media', ''), path))\n" c̲at 302 " if not os.path.exists(file):\n" c̲at 303 " rig['missing'] = rig.get('missing', 0) + 1\n" c̲at 304 " return screen(name, 'tiles', (1.0, 0.2, 0.4), (0.2, 0.6, 1.0), 1.0, strength)\n" c̲at 305 " rig['played'] = rig.get('played', 0) + 1\n" c̲at 306 " m, nt, o = fresh(name)\n" c̲at 307 " img = bpy.data.images.load(file, check_existing=True)\n" c̲at 308 " t = node(nt, 'ShaderNodeTexImage', image=img)\n" c̲at 309 " if img.source == 'MOVIE':\n" c̲at 310 " t.image_user.frame_duration = max(1, img.frame_duration)\n" c̲at 311 " t.image_user.use_cyclic = True\n" c̲at 312 " t.image_user.use_auto_refresh = True\n" c̲at 313 " p = shell(nt, o)\n" c̲at 314 " p.inputs['Base Color'].default_value = (0.01, 0.01, 0.012, 1.0)\n" c̲at 315 " p.inputs['Roughness'].default_value = 0.15\n" c̲at 316 " nt.links.new(t.outputs[0], p.inputs['Emission Color'])\n" c̲at 317 " p.inputs['Emission Strength'].default_value = strength\n" c̲at 318 "\n" c̲at 319 "def slides(name, stem, count, hold, strength):\n" c̲at 320 " reel(name, stem + '.webm', strength)\n" c̲at 321 "\n" c̲at 322 "def place(o, into):\n" c̲at 323 " (models[into] if into else scene.collection).objects.link(o)\n" c̲at 324 " return o\n" c̲at 325 "\n" c̲at 326 "def boxes(name, rows, material, into=''):\n" c̲at 327 " verts, faces = [], []\n" c̲at 328 " for r in rows:\n" c̲at 329 " ca, sa = math.cos(math.radians(r[6])), math.sin(math.radians(r[6]))\n" c̲at 330 " k = len(verts)\n" c̲at 331 " for i in range(8):\n" c̲at 332 " 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 333 " verts.append((r[0] + x * ca - y * sa, r[1] + x * sa + y * ca, r[2] + z))\n" c̲at 334 " 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 335 " m = bpy.data.meshes.new(name)\n" c̲at 336 " m.from_pydata(verts, [], faces)\n" c̲at 337 " uv = m.uv_layers.new(name='UVMap')\n" c̲at 338 " for i, d in enumerate(uv.data):\n" c̲at 339 " d.uv = ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0))[i % 4]\n" c̲at 340 " m.update()\n" c̲at 341 " m.materials.append(mats[material])\n" c̲at 342 " return place(bpy.data.objects.new(name, m), into)\n" c̲at 343 "\n" c̲at 344 "def sign(name, body, at, size, turn, stack, material):\n" c̲at 345 " c = bpy.data.curves.new(name, type='FONT')\n" c̲at 346 " c.body = chr(10).join(body) if stack else body\n" c̲at 347 " c.size = size\n" c̲at 348 " c.align_x = 'CENTER'\n" c̲at 349 " c.align_y = 'TOP' if stack else 'CENTER'\n" c̲at 350 " c.extrude = 0.06 * size\n" c̲at 351 " c.space_line = 0.85\n" c̲at 352 " if rig.get('font'):\n" c̲at 353 " c.font = rig['font']\n" c̲at 354 " c.materials.append(mats[material])\n" c̲at 355 " o = place(bpy.data.objects.new(name, c), '')\n" c̲at 356 " o.location = at\n" c̲at 357 " o.rotation_euler = (math.pi / 2, 0.0, math.radians(turn))\n" c̲at 358 "\n") 359 360⍝ the player, part 7: model and after 361ʰplay7 ← ("def model(name):\n" c̲at 362 " models[name] = bpy.data.collections.new(name)\n" c̲at 363 "\n" c̲at 364 "def fleet(name, kind, rows):\n" c̲at 365 " for i, r in enumerate(rows):\n" c̲at 366 " o = place(bpy.data.objects.new('%s %d' % (name, i + 1), None), '')\n" c̲at 367 " o.instance_type = 'COLLECTION'\n" c̲at 368 " o.instance_collection = models[kind]\n" c̲at 369 " o.rotation_euler = (0.0, 0.0, math.atan2(r[4] - r[1], r[3] - r[0]))\n" c̲at 370 " for f, at in ((scene.frame_start, r[0:3]), (scene.frame_end, r[3:6])):\n" c̲at 371 " o.location = at\n" c̲at 372 " o.keyframe_insert('location', frame=f)\n" c̲at 373 "\n" c̲at 374 "def lamps(name, rows):\n" c̲at 375 " for i, r in enumerate(rows):\n" c̲at 376 " d = bpy.data.lights.new(name, type='POINT')\n" c̲at 377 " d.color, d.energy, d.shadow_soft_size = r[3:6], r[6], r[7]\n" c̲at 378 " place(bpy.data.objects.new('%s %d' % (name, i + 1), d), '').location = r[0:3]\n" c̲at 379 "\n" c̲at 380 "def spots(name, rows):\n" c̲at 381 " for i, r in enumerate(rows):\n" c̲at 382 " d = bpy.data.lights.new(name, type='SPOT')\n" c̲at 383 " 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 384 " o = place(bpy.data.objects.new('%s %d' % (name, i + 1), d), '')\n" c̲at 385 " o.location = r[0:3]\n" c̲at 386 " o.rotation_euler = (Vector(r[3:6]) - Vector(r[0:3])).to_track_quat('-Z', 'Y').to_euler()\n" c̲at 387 "\n" c̲at 388 "def sky(horizon, zenith, strength):\n" c̲at 389 " w = bpy.data.worlds.new('sky')\n" c̲at 390 " w.use_nodes = True\n" c̲at 391 " nt = w.node_tree\n" c̲at 392 " nt.nodes.clear()\n" c̲at 393 " g = node(nt, 'ShaderNodeNewGeometry')\n" c̲at 394 " _, _, z = xyz(nt, g.outputs['Incoming'])\n" c̲at 395 " b = node(nt, 'ShaderNodeBackground')\n" c̲at 396 " feed(nt, b.inputs['Color'], blend(nt, step(nt, calc(nt, 'ABSOLUTE', z), 0.0, 0.6), horizon, zenith))\n" c̲at 397 " b.inputs['Strength'].default_value = strength\n" c̲at 398 " nt.links.new(b.outputs[0], node(nt, 'ShaderNodeOutputWorld').inputs['Surface'])\n" c̲at 399 " scene.world = w\n" c̲at 400 "\n") 401 402⍝ the player, part 8: fog and after 403ʰplay8 ← ("def fog(name, rows, rgb, density, forward):\n" c̲at 404 " m, nt, o = fresh(name)\n" c̲at 405 " s = node(nt, 'ShaderNodeVolumeScatter')\n" c̲at 406 " s.inputs['Color'].default_value = tuple(rgb) + (1.0,)\n" c̲at 407 " s.inputs['Density'].default_value = density\n" c̲at 408 " s.inputs['Anisotropy'].default_value = forward\n" c̲at 409 " nt.links.new(s.outputs[0], o.inputs['Volume'])\n" c̲at 410 " boxes(name, [tuple(r) + (0.0,) for r in rows], name)\n" c̲at 411 "\n" c̲at 412 "def steam(name, rows, rgb, density, speed):\n" c̲at 413 " m, nt, o = fresh(name)\n" c̲at 414 " tc = node(nt, 'ShaderNodeTexCoord')\n" c̲at 415 " lx, ly, lz = xyz(nt, tc.outputs['Object'])\n" c̲at 416 " g = node(nt, 'ShaderNodeNewGeometry')\n" c̲at 417 " px, py, pz = xyz(nt, g.outputs['Position'])\n" c̲at 418 " t = clock(nt)\n" c̲at 419 " 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 420 " rad = calc(nt, 'SQRT', calc(nt, 'ADD', calc(nt, 'MULTIPLY', lx, lx), calc(nt, 'MULTIPLY', ly, ly)))\n" c̲at 421 " up = calc(nt, 'ADD', lz, 0.5)\n" c̲at 422 " wide = calc(nt, 'ADD', 0.12, calc(nt, 'MULTIPLY', up, 0.38))\n" c̲at 423 " core = calc(nt, 'SUBTRACT', 1.0, step(nt, calc(nt, 'DIVIDE', rad, wide), 0.3, 1.0))\n" c̲at 424 " 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 425 " d = calc(nt, 'MULTIPLY', calc(nt, 'MULTIPLY', core, fade), calc(nt, 'MULTIPLY', density, step(nt, puff, 0.38, 0.7)))\n" c̲at 426 " s = node(nt, 'ShaderNodeVolumeScatter')\n" c̲at 427 " s.inputs['Color'].default_value = tuple(rgb) + (1.0,)\n" c̲at 428 " s.inputs['Anisotropy'].default_value = 0.3\n" c̲at 429 " nt.links.new(d, s.inputs['Density'])\n" c̲at 430 " nt.links.new(s.outputs[0], o.inputs['Volume'])\n" c̲at 431 " for i, r in enumerate(rows):\n" c̲at 432 " 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 433 " b.location, b.scale = r[0:3], r[3:6]\n" c̲at 434 "\n" c̲at 435 "def along(times, points, t):\n" c̲at 436 " n = len(times)\n" c̲at 437 " i = max(0, min(n - 2, max(k for k in range(n) if times[k] <= t or k == 0)))\n" c̲at 438 " u = min(1.0, max(0.0, (t - times[i]) / (times[i + 1] - times[i])))\n" c̲at 439 " p0, p1, p2, p3 = (Vector(points[max(0, min(n - 1, i + d))]) for d in (-1, 0, 1, 2))\n" c̲at 440 " 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 441 "\n" c̲at 442 "def fly(times, eyes, aims, lens, fstop):\n" c̲at 443 " cam = place(bpy.data.objects.new('camera', bpy.data.cameras.new('camera')), '')\n" c̲at 444 " aim = place(bpy.data.objects.new('aim', None), '')\n" c̲at 445 " cam.data.lens = lens\n" c̲at 446 " cam.data.clip_start, cam.data.clip_end = 0.1, 5000.0\n" c̲at 447 " scene.camera = cam\n" c̲at 448 " look = cam.constraints.new('TRACK_TO')\n" c̲at 449 " look.target, look.track_axis, look.up_axis = aim, 'TRACK_NEGATIVE_Z', 'UP_Y'\n" c̲at 450 " if fstop > 0.0:\n" c̲at 451 " cam.data.dof.use_dof = True\n" c̲at 452 " cam.data.dof.focus_object = aim\n" c̲at 453 " cam.data.dof.aperture_fstop = fstop\n" c̲at 454 " for f in range(scene.frame_start - 1, scene.frame_end + 2):\n" c̲at 455 " t = (f - 1) / scene.render.fps\n" c̲at 456 " cam.location, aim.location = along(times, eyes, t), along(times, aims, t)\n" c̲at 457 " cam.keyframe_insert('location', frame=f)\n" c̲at 458 " aim.keyframe_insert('location', frame=f)\n" c̲at 459 "\n") 460 461⍝ the player, part 9: bloom and after 462ʰplay9 ← ("def bloom(threshold, strength, size):\n" c̲at 463 " g = bpy.data.node_groups.new('bloom', 'CompositorNodeTree')\n" c̲at 464 " g.interface.new_socket(name='Image', in_out='OUTPUT', socket_type='NodeSocketColor')\n" c̲at 465 " src, glare, end = g.nodes.new('CompositorNodeRLayers'), g.nodes.new('CompositorNodeGlare'), g.nodes.new('NodeGroupOutput')\n" c̲at 466 " glare.inputs['Type'].default_value = 'Bloom'\n" c̲at 467 " glare.inputs['Threshold'].default_value = threshold\n" c̲at 468 " glare.inputs['Strength'].default_value = strength\n" c̲at 469 " glare.inputs['Size'].default_value = size\n" c̲at 470 " g.links.new(src.outputs['Image'], glare.inputs['Image'])\n" c̲at 471 " g.links.new(glare.outputs['Image'], end.inputs[0])\n" c̲at 472 " scene.compositing_node_group = g\n" c̲at 473 " scene.render.use_compositing = True\n" c̲at 474 "\n" c̲at 475 "def png(path):\n" c̲at 476 " scene.render.image_settings.media_type = 'IMAGE'\n" c̲at 477 " scene.render.image_settings.file_format = 'PNG'\n" c̲at 478 " scene.render.filepath = path\n" c̲at 479 "\n" c̲at 480 "def still(file, seconds):\n" c̲at 481 " scene.frame_set(frame(seconds))\n" c̲at 482 " png(os.path.join(out, file))\n" c̲at 483 " bpy.ops.render.render(write_still=True)\n" c̲at 484 "\n" c̲at 485 "def frames(folder, first, last):\n" c̲at 486 " keep = scene.frame_start, scene.frame_end\n" c̲at 487 " if last > 0:\n" c̲at 488 " scene.frame_start, scene.frame_end = int(first), int(last)\n" c̲at 489 " png(os.path.join(out, folder, ''))\n" c̲at 490 " scene.render.use_overwrite = False\n" c̲at 491 " bpy.ops.render.render(animation=True)\n" c̲at 492 " scene.frame_start, scene.frame_end = keep\n" c̲at 493 "\n" c̲at 494 "def encode(folder, file):\n" c̲at 495 " d = os.path.join(out, folder)\n" c̲at 496 " names = sorted(n for n in os.listdir(d) if n.endswith('.png'))\n" c̲at 497 " e = bpy.data.scenes.new('encode')\n" c̲at 498 " r = e.render\n" c̲at 499 " r.resolution_x, r.resolution_y, r.resolution_percentage = scene.render.resolution_x, scene.render.resolution_y, 100\n" c̲at 500 " r.fps = scene.render.fps\n" c̲at 501 " e.view_settings.view_transform = 'Standard'\n" c̲at 502 " s = e.sequence_editor_create().strips.new_image('frames', os.path.join(d, names[0]), 1, 1)\n" c̲at 503 " for n in names[1:]:\n" c̲at 504 " s.elements.append(n)\n" c̲at 505 " e.frame_start, e.frame_end = 1, len(names)\n" c̲at 506 " r.image_settings.media_type = 'VIDEO'\n" c̲at 507 " r.image_settings.file_format = 'FFMPEG'\n" c̲at 508 " r.ffmpeg.format, r.ffmpeg.codec, r.ffmpeg.constant_rate_factor = 'MPEG4', 'H264', 'HIGH'\n" c̲at 509 " r.filepath = os.path.join(out, file)\n" c̲at 510 " bpy.ops.render.render(animation=True, scene='encode')\n" c̲at 511 "\n") 512 513⍝ the player, part 10: report and after 514ʰplay10 ← ("def report():\n" c̲at 515 " kinds = {}\n" c̲at 516 " for o in scene.objects:\n" c̲at 517 " kinds[o.type] = kinds.get(o.type, 0) + 1\n" c̲at 518 " with open(os.path.join(out, 'report.txt'), 'w') as f:\n" c̲at 519 " r = scene.render\n" c̲at 520 " 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 521 " f.write('objects: ' + ', '.join('%d %s' % (kinds[k], k.lower()) for k in sorted(kinds)) + chr(10))\n" c̲at 522 " f.write('faces: %d' % sum(len(o.data.polygons) for o in scene.objects if o.type == 'MESH') + chr(10))\n" c̲at 523 " f.write('materials: ' + ' '.join(sorted(mats)) + chr(10))\n" c̲at 524 " f.write('models: ' + ' '.join(sorted(models)) + chr(10))\n" c̲at 525 " f.write('pictures: %d played, %d missing' % (rig.get('played', 0), rig.get('missing', 0)) + chr(10))\n" c̲at 526 " print('cycles device: %s' % (rig.get('device') or 'CPU'))\n") 527 528⍝│ cy:head: the player, the start of every script: an empty scene, the 529⍝│ output directory (the first argument after "--", made), and the 530⍝│ functions the calls below use -- stage, look, sky and bloom; the 531⍝│ materials (surface, neon, facade, wet, screen, reel, slides), each a graph of 532⍝│ shader nodes built here; boxes (one mesh a group, each face mapped 533⍝│ for a screen), sign, model and fleet; lamps and spots; fog and 534⍝│ steam; fly (the camera keyed every frame along a curve through its 535⍝│ eyes); still, frames, encode and report. Its letters are in JuliaMono 536⍝│ Black when work/fonts has it (just font), else Blender's own. 537ˡ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 538 539⍝━━ Numbers and text into Python 540 541⍝ (values, k) h:n_ums 0: the values as Python reading them k to a row 542ʰn̲ums ← { (v, k) z → "nums('" c̲at (f̲ormat r̲avel v) c̲at "', " c̲at (f̲ormat k) c̲at ")" } 543 544⍝ q h:q_uoteIn text: the text in quotes (the character code q), each 545⍝ such quote and backslash in it written with a backslash before it 546⍝ (ASCII text): a Python string (as Video.xtl's) 547ʰq̲uoteIn ← { q t → 548 0 = t̲ally t ? ⎕U̲CHAR q c̲at q 549 c ← ⎕U̲CS t 550 e ← (c = q) ∨ c = 92 551 k ← (1 + e) r̲eplicate r̲ange t̲ally c 552 m ← ((1 + e) r̲eplicate e) ∧ k ≠ 0 c̲at -1 d̲rop k 553 (⎕U̲CHAR q) c̲at (⎕U̲CHAR (92 × m) + (1 − m) × (1 + e) r̲eplicate c) c̲at ⎕U̲CHAR q 554} 555 556⍝ a Python string: the text in single quotes 557ʰq̲uote ← { t → 39 ʰq̲uoteIn t } 558 559⍝ a color (0 to 255) as a Python tuple, linear 560ʰr̲gb ← { c → ((ˡl̲inear c, 3) ʰn̲ums 0) c̲at "[0]" } 561 562⍝ a few numbers as a Python tuple 563ʰt̲uple ← { v → ((f̲loat v, t̲ally v) ʰn̲ums 0) c̲at "[0]" } 564 565⍝│ cy:l_inear color: a color's channels, 0 to 255 (sRGB), as the linear 566⍝│ values, 0 to 1, that Blender's materials and lights take 567⍝│ >> "cy:" u_se< "Cycles" 568⍝│ >> cy:l_inear 0 255 569⍝│ 0.0 1.0 570ˡl̲inear ← { c → ((f̲loat c) ÷ 255.0) ^ 2.2 } 571 572⍝━━ The picture 573 574⍝│ (width, height, fps, seconds, samples, device) cy:s_tage 0: Python 575⍝│ setting Cycles, the picture's size, the frame rate, the film's 576⍝│ length and how many samples each pixel takes at most (noise is 577⍝│ removed after: 24 show a scene, 64 to 128 finish it); device is 578⍝│ "GPU" (the graphics card when Cycles finds one it can use -- Metal, 579⍝│ OptiX, CUDA, HIP, oneAPI -- else the processor) or "CPU". The film 580⍝│ look (AgX), so bright lights roll off as a camera's do. First, 581⍝│ before anything else. 582⍝│ >> "cy:" u_se< "Cycles" 583⍝│ >> (640, 360, 30, 6.0, 24, "GPU") cy:s_tage 0 584⍝│ stage(640, 360, 30, 6.0, 24, 'GPU') 585ˡs̲tage ← { (w, h, fps, secs, samples, device) z → 586 "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" 587} 588 589⍝│ (look, exposure, shutter) cy:l_ook 0: Python setting the look (one of 590⍝│ Blender's AgX looks by name, "AgX - Punchy" for more contrast and 591⍝│ color; "None" for none), the exposure in stops (0 as rendered) and 592⍝│ motion blur: the shutter is open that part of a frame (0.5 as a film 593⍝│ camera; 0 for no blur) 594ˡl̲ook ← { (name, exposure, shutter) z → 595 "look(" c̲at (ʰq̲uote name) c̲at ", " c̲at (f̲ormat exposure) c̲at ", " c̲at (f̲ormat shutter) c̲at ")\n" 596} 597 598⍝│ (horizon, zenith, strength) cy:s_ky 0: Python making the sky: one 599⍝│ color at the horizon blending into another overhead, that bright (1 600⍝│ as given; a night sky's colors are near black) 601ˡs̲ky ← { (horizon, zenith, strength) z → 602 "sky(" c̲at (ʰr̲gb horizon) c̲at ", " c̲at (ʰr̲gb zenith) c̲at ", " c̲at (f̲ormat strength) c̲at ")\n" 603} 604 605⍝│ (threshold, strength, size) cy:b_loom 0: Python making bright things 606⍝│ bleed light into the picture round them, as a lens does: what is 607⍝│ brighter than the threshold (1 is white) glows, that strongly (0 to 608⍝│ 1), that wide (0 to 1) 609ˡb̲loom ← { (threshold, strength, size) z → 610 "bloom(" c̲at (f̲ormat threshold) c̲at ", " c̲at (f̲ormat strength) c̲at ", " c̲at (f̲ormat size) c̲at ")\n" 611} 612 613⍝━━ Materials 614 615⍝│ A material is made by name, before the groups that wear it. 616 617⍝│ (name, color, roughness, metallic) cy:s_urface 0: Python making a 618⍝│ plain material: its color, how rough (0 a mirror, 1 chalk) and how 619⍝│ metallic (0 or 1) 620⍝│ >> "cy:" u_se< "Cycles" 621⍝│ >> ("steel", 255 255 255, 0.3, 1.0) cy:s_urface 0 622⍝│ surface('steel', nums('1.0 1.0 1.0', 3)[0], 0.3, 1.0) 623ˡs̲urface ← { (name, rgb, roughness, metallic) z → 624 "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" 625} 626 627⍝│ (name, color, strength) cy:n_eon 0: Python making a material that 628⍝│ only gives off light, that strongly (1 its color as given; 5 to 10 a 629⍝│ sign that lights the street) 630ˡn̲eon ← { (name, rgb, strength) z → 631 "neon(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰr̲gb rgb) c̲at ", " c̲at (f̲ormat strength) c̲at ")\n" 632} 633 634⍝│ (name, wall, lit a, lit b, cell, lit, glow) cy:f_acade 0: Python 635⍝│ making a building's skin, worked out from where each point of a wall 636⍝│ is: the wall is cut into cells (cell: a window's bay and a floor's 637⍝│ height, meters), each cell a dark glass pane in a wall of the wall's 638⍝│ color, weathered; a share of the panes (lit, 0 to 1, more on some 639⍝│ floors than others) are lit rooms, each a color between lit a and lit 640⍝│ b and its own brightness, glowing that strongly. Roofs have no 641⍝│ windows. For boxes that stand upright and do not move. 642ˡf̲acade ← { (name, wall, a, b, cell, lit, glow) z → 643 "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" 644} 645 646⍝│ (name, color, puddles, size, ripple) cy:w_et 0: Python making wet 647⍝│ ground: rough where it is only damp, a mirror where water stands -- 648⍝│ puddles is the share under water (0 to 1), size how wide a puddle is 649⍝│ (meters), ripple how much rain disturbs the water (0 still) 650ˡw̲et ← { (name, rgb, puddles, size, ripple) z → 651 "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" 652} 653 654⍝│ (name, kind, a, b, speed, strength) cy:s_creen 0: Python making a 655⍝│ screen that plays a moving picture in two colors, worked out from 656⍝│ the time, on each face of a box: kind is "bars" (stripes rolling 657⍝│ up), "rings" (rings spreading from the middle), "rain" (columns of 658⍝│ falling glyphs) or "tiles" (a mosaic that changes); speed is cycles 659⍝│ a second; it glows that strongly 660ˡs̲creen ← { (name, kind, a, b, speed, strength) z → 661 "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" 662} 663 664⍝│ cy:m_edia folder: Python saying where the files that cy:r_eel and 665⍝│ cy:s_lides name are: a folder, from where the player runs. Before 666⍝│ them. 667⍝│ >> "cy:" u_se< "Cycles" 668⍝│ >> cy:m_edia "media" 669⍝│ media('media') 670ˡm̲edia ← { folder → "media(" c̲at (ʰq̲uote folder) c̲at ")\n" } 671 672⍝│ (name, file, strength) cy:r_eel 0: Python making a screen that plays 673⍝│ a video file (or shows a picture) from the media folder, looping, on 674⍝│ each face of a box, glowing that strongly (1 the picture as it is). 675⍝│ When the file is not there the screen plays tiles in its place, and 676⍝│ the report counts it missing. 677ˡr̲eel ← { (name, path, strength) z → 678 "reel(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰq̲uote path) c̲at ", " c̲at (f̲ormat strength) c̲at ")\n" 679} 680 681⍝│ (name, stem, count, hold, strength) cy:s_lides 0: Python making a 682⍝│ screen that shows still pictures in turn, each hold seconds, fading 683⍝│ into the next: STEM-1.jpg to STEM-count.jpg in the media folder. A 684⍝│ player that draws live shows the stills (cheaper than a video); 685⍝│ Blender's plays STEM.webm, the same slides made a video. 686⍝│ >> "cy:" u_se< "Cycles" 687⍝│ >> ("ads", "art", 16, 4.0, 1.5) cy:s_lides 0 688⍝│ slides('ads', 'art', 16, 4.0, 1.5) 689ˡs̲lides ← { (name, stem, count, hold, strength) z → 690 "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" 691} 692 693⍝━━ Things 694 695⍝│ (name, table, material) cy:b_oxes 0: Python making a group of boxes 696⍝│ as one object NAME wearing the material: a row a box -- x y z (its 697⍝│ middle), w d h (its size) and its turn about the upright axis. A 698⍝│ tower h tall standing on the ground has its middle at h / 2. 699⍝│ >> "cy:" u_se< "Cycles" 700⍝│ >> ("tower", 1 7 r_eshape 0 0 50 20 20 100 0, "glass") cy:b_oxes 0 701⍝│ boxes('tower', nums('0.0 0.0 50.0 20.0 20.0 100.0 0.0', 7), 'glass') 702ˡb̲oxes ← { (name, t, material) z → 703 "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" 704} 705 706⍝│ (name, text, place, size, turn, stack, material) cy:s_ign 0: Python 707⍝│ making a sign of solid letters that tall, standing upright, its 708⍝│ middle at place (x y z), turned about the upright axis (0 faces -y), 709⍝│ wearing the material (cy:n_eon); stack 1 writes the letters one 710⍝│ below another, hanging from place 711ˡs̲ign ← { (name, body, at, size, turn, stack, material) z → 712 "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" 713} 714 715⍝│ cy:m_odel name: Python starting a model: a thing made once and shown 716⍝│ many times (a vehicle); its parts are cy:p_arts, about its own 717⍝│ middle, its front along x 718ˡm̲odel ← { name → "model(" c̲at (ʰq̲uote name) c̲at ")\n" } 719 720⍝│ (name, table, material, model) cy:p_arts 0: Python making boxes, as 721⍝│ cy:b_oxes, as a part of the model 722ˡp̲arts ← { (name, t, material, model) z → 723 "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" 724} 725 726⍝│ (name, model, table) cy:f_leet 0: Python showing the model once a row 727⍝│ of the table, each moving at an even speed through the whole film: 728⍝│ from x y z (at the start) to x y z (at the end), facing the way it 729⍝│ goes 730ˡf̲leet ← { (name, model, t) z → 731 "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" 732} 733 734⍝━━ Light and air 735 736⍝│ (name, table) cy:l_amps 0: Python making lamps that shine all round, 737⍝│ a row each: x y z, r g b, its strength (watts) and its radius 738⍝│ (meters: a larger lamp casts softer shadows) 739ˡl̲amps ← { (name, t) z → 740 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 741 "lamps(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((p, 8) ʰn̲ums 0) c̲at ")\n" 742} 743 744⍝│ (name, table) cy:s_pots 0: Python making spotlights, a row each: at 745⍝│ x y z, aimed at x y z, r g b, its strength (watts) and the cone's 746⍝│ angle 747ˡs̲pots ← { (name, t) z → 748 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 749 "spots(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((p, 11) ʰn̲ums 0) c̲at ")\n" 750} 751 752⍝│ (name, table, color, density, forward) cy:f_og 0: Python filling 753⍝│ boxes with even haze that scatters light, so lamps and signs glow in 754⍝│ the air and far things fade: a row a box, x y z (its middle), w d h; 755⍝│ density is how much is scattered a meter (0.001 a clear night, 0.01 756⍝│ thick); forward (0 to 1) is how much goes on the way it was going 757ˡf̲og ← { (name, t, rgb, density, forward) z → 758 "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" 759} 760 761⍝│ (name, table, color, density, speed) cy:s_team 0: Python making 762⍝│ plumes of steam, a row each: x y z (its middle) and w d h, the box 763⍝│ the plume fills -- thin at the bottom's middle, wider and fainter as 764⍝│ it rises, billowing, climbing speed meters a second 765ˡs̲team ← { (name, t, rgb, density, speed) z → 766 "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" 767} 768 769⍝━━ The camera 770 771⍝│ (times, eyes, aims, lens, fstop) cy:f_ly 0: Python flying the camera: 772⍝│ at each time (k seconds) it is at an eye (k by 3) looking at an aim 773⍝│ (k by 3), and between them it goes along a smooth curve through the 774⍝│ eyes, looking along a smooth curve through the aims; lens is its 775⍝│ focal length in mm (24 wide, 50 as an eye); it is focused on the aim 776⍝│ with an aperture of fstop (1.4 blurs what is nearer and farther, 8 777⍝│ little; 0 keeps everything sharp) 778ˡf̲ly ← { (ts, e, a, lens, fstop) z → 779 "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" 780} 781 782⍝━━ Rendering 783 784⍝│ (file, seconds) cy:s_till 0: Python rendering the frame at that time 785⍝│ to out/FILE (PNG) 786⍝│ >> "cy:" u_se< "Cycles" 787⍝│ >> ("street.png", 5.5) cy:s_till 0 788⍝│ still('street.png', 5.5) 789ˡs̲till ← { (file, secs) z → "still(" c̲at (ʰq̲uote file) c̲at ", " c̲at (f̲ormat secs) c̲at ")\n" } 790 791⍝│ (folder, first, last) cy:f_rames 0: Python rendering the frames from 792⍝│ first to last (0 0 for the whole film) to out/FOLDER, a PNG each 793⍝│ (0001.png ...). A frame already there is not rendered again, so a 794⍝│ long render may be stopped and run again, or run a part at a time. 795ˡf̲rames ← { (folder, first, last) z → 796 "frames(" c̲at (ʰq̲uote folder) c̲at ", " c̲at (f̲ormat first) c̲at ", " c̲at (f̲ormat last) c̲at ")\n" 797} 798 799⍝│ (folder, file) cy:e_ncode 0: Python making the video out/FILE (MP4, 800⍝│ H.264) of the frames in out/FOLDER, in order, at the film's rate 801ˡe̲ncode ← { (folder, file) z → "encode(" c̲at (ʰq̲uote folder) c̲at ", " c̲at (ʰq̲uote file) c̲at ")\n" } 802 803⍝│ cy:report: Python writing out/report.txt -- the renderer, the 804⍝│ picture's size, frames, rate and samples; how many objects of each 805⍝│ kind; the faces; the materials and the models, by name -- what a 806⍝│ test checks 807ˡreport ← "report()\n"