sourceextensions/blender/lib/Video.xtl

1⍝│ Video.xtl -- arrays to video: an animated Blender scene described by 2⍝│ X_eTaL arrays. Every object's place, size, color, the seconds it is 3⍝│ shown, every key it moves to, the camera's path and the captions are 4⍝│ arrays a program works out; each function here writes them into 5⍝│ Blender's Python as numbers, one call of the player for a whole 6⍝│ group. The player (vd:head) is fixed Python, the same for every 7⍝│ video: it reads the numbers and makes the objects and keys, and 8⍝│ decides nothing. A video is vd:head, then vd:s_tage, the groups, their 9⍝│ spans, keys and tints, the camera, the captions, then vd:r_ender (or 10⍝│ vd:s_tills), written with bl:w_rite! and run by bp:launcher through 11⍝│ bl:r_un!. 12⍝│ 13⍝│ For explainer videos: the picture's size is any (vd:landscape, 1920 14⍝│ by 1080, or vd:shorts, 1080 by 1920, upright); vd:f_it places the 15⍝│ camera so a region fills either; vd:r_etime remaps a scene's own 16⍝│ seconds to the video's (slow motion, time-lapse); vd:g_lows keys how 17⍝│ strongly things glow from data; vd:c_ards are title cards; captions 18⍝│ and cards are sized to the picture and wrapped to its width; and 19⍝│ vd:c_ues and vd:s_rt write the cue sheet and the subtitles (.srt) of 20⍝│ the same captions, to record narration against. 21⍝│ 22⍝│ The look: flat colors that glow (emission only), on a near-black 23⍝│ sky, the Standard view (colors as given); text in JuliaMono Black 24⍝│ (work/fonts, just font), facing the camera; captions on a dark 25⍝│ plate near the bottom of the picture. Places are meters, z up; 26⍝│ times are seconds; colors are 0 to 255 (sRGB), made linear here. 27⍝│ Written for Blender 5.1. 28⍝│ Import: "vd:" u_se< "Video" 29 30⍝━━ The player 31 32⍝ the player, in parts (one expression nests too deep): the start, nums, 33⍝ frame, the font, glow 34ʰplayBase ← ("import bpy, math, os, sys, textwrap\n" c̲at 35 "args = sys.argv[sys.argv.index('--') + 1:]\n" c̲at 36 "out = args[0]\n" c̲at 37 "os.makedirs(out, exist_ok=True)\n" c̲at 38 "bpy.ops.wm.read_factory_settings(use_empty=True)\n" c̲at 39 "bpy.context.preferences.edit.keyframe_new_interpolation_type = 'BEZIER'\n" c̲at 40 "scene = bpy.context.scene\n" c̲at 41 "scene.render.fps = 30\n" c̲at 42 "groups = {}\n" c̲at 43 "rig = {}\n" c̲at 44 "\n" c̲at 45 "def nums(text, k):\n" c̲at 46 " v = [float(t) for t in text.split()]\n" c̲at 47 " return [tuple(v[i:i + k]) for i in range(0, len(v), k)]\n" c̲at 48 "\n" c̲at 49 "def frame(t):\n" c̲at 50 " return 1 + round(t * scene.render.fps)\n" c̲at 51 "\n" c̲at 52 "def font():\n" c̲at 53 " d = os.getcwd()\n" c̲at 54 " while True:\n" c̲at 55 " p = os.path.join(d, 'work', 'fonts', 'JuliaMono-Black.ttf')\n" c̲at 56 " if os.path.exists(p):\n" c̲at 57 " return bpy.data.fonts.load(p, check_existing=True)\n" c̲at 58 " if os.path.dirname(d) == d:\n" c̲at 59 " return None\n" c̲at 60 " d = os.path.dirname(d)\n" c̲at 61 "\n" c̲at 62 "FONT = font()\n" c̲at 63 "ADVANCE = 0.33\n" c̲at 64 "\n" c̲at 65 "def glow(name, rgb, strength=1.0, alpha=1.0):\n" c̲at 66 " m = bpy.data.materials.new(name)\n" c̲at 67 " m.use_nodes = True\n" c̲at 68 " nt = m.node_tree\n" c̲at 69 " for n in list(nt.nodes):\n" c̲at 70 " nt.nodes.remove(n)\n" c̲at 71 " e = nt.nodes.new('ShaderNodeEmission')\n" c̲at 72 " e.name = 'glow'\n" c̲at 73 " e.inputs['Color'].default_value = tuple(rgb) + (1.0,)\n" c̲at 74 " e.inputs['Strength'].default_value = strength\n" c̲at 75 " o = nt.nodes.new('ShaderNodeOutputMaterial')\n" c̲at 76 " if alpha < 1.0:\n" c̲at 77 " tr = nt.nodes.new('ShaderNodeBsdfTransparent')\n" c̲at 78 " mx = nt.nodes.new('ShaderNodeMixShader')\n" c̲at 79 " mx.inputs[0].default_value = alpha\n" c̲at 80 " nt.links.new(tr.outputs[0], mx.inputs[1])\n" c̲at 81 " nt.links.new(e.outputs[0], mx.inputs[2])\n" c̲at 82 " nt.links.new(mx.outputs[0], o.inputs[0])\n" c̲at 83 " m.surface_render_method = 'BLENDED'\n" c̲at 84 " else:\n" c̲at 85 " nt.links.new(e.outputs[0], o.inputs[0])\n" c̲at 86 " return m\n" c̲at 87 "\n") 88 89⍝ the player, continued: stage and after 90ʰplayStage ← ("def stage(w, h, fps, seconds, sky, lens):\n" c̲at 91 " scene.render.engine = 'BLENDER_EEVEE'\n" c̲at 92 " scene.eevee.taa_render_samples = 16\n" c̲at 93 " scene.view_settings.view_transform = 'Standard'\n" c̲at 94 " scene.render.resolution_x, scene.render.resolution_y = int(w), int(h)\n" c̲at 95 " scene.render.resolution_percentage = 100\n" c̲at 96 " scene.render.fps = int(fps)\n" c̲at 97 " scene.frame_start, scene.frame_end = 1, frame(seconds)\n" c̲at 98 " world = bpy.data.worlds.new('sky')\n" c̲at 99 " world.use_nodes = True\n" c̲at 100 " world.node_tree.nodes['Background'].inputs['Color'].default_value = tuple(sky) + (1.0,)\n" c̲at 101 " scene.world = world\n" c̲at 102 " cam = bpy.data.objects.new('camera', bpy.data.cameras.new('camera'))\n" c̲at 103 " cam.data.lens = lens\n" c̲at 104 " cam.data.clip_start = 0.001\n" c̲at 105 " cam.data.clip_end = 5000.0\n" c̲at 106 " scene.collection.objects.link(cam)\n" c̲at 107 " scene.camera = cam\n" c̲at 108 " aim = bpy.data.objects.new('aim', None)\n" c̲at 109 " scene.collection.objects.link(aim)\n" c̲at 110 " look = cam.constraints.new('TRACK_TO')\n" c̲at 111 " look.target = aim\n" c̲at 112 " look.track_axis = 'TRACK_NEGATIVE_Z'\n" c̲at 113 " look.up_axis = 'UP_Y'\n" c̲at 114 " rig['camera'], rig['aim'] = cam, aim\n" c̲at 115 "\n" c̲at 116 "def cube_mesh():\n" c̲at 117 " v = [(x, y, z) for z in (-0.5, 0.5) for y in (-0.5, 0.5) for x in (-0.5, 0.5)]\n" c̲at 118 " f = [(0, 2, 3, 1), (4, 5, 7, 6), (0, 1, 5, 4), (2, 6, 7, 3), (0, 4, 6, 2), (1, 3, 7, 5)]\n" c̲at 119 " m = bpy.data.meshes.new('cube')\n" c̲at 120 " m.from_pydata(v, [], f)\n" c̲at 121 " m.update()\n" c̲at 122 " return m\n" c̲at 123 "\n" c̲at 124 "def boxes(name, rows, style):\n" c̲at 125 " base = cube_mesh()\n" c̲at 126 " made = []\n" c̲at 127 " for i, r in enumerate(rows):\n" c̲at 128 " n = '%s %d' % (name, i + 1)\n" c̲at 129 " o = bpy.data.objects.new(n, base.copy())\n" c̲at 130 " scene.collection.objects.link(o)\n" c̲at 131 " o.location = r[0:3]\n" c̲at 132 " o.scale = r[3:6]\n" c̲at 133 " o.data.materials.append(glow(n, r[6:9], r[9], 0.18 if style == 'glass' else 1.0))\n" c̲at 134 " if style == 'wire':\n" c̲at 135 " w = o.modifiers.new('wire', 'WIREFRAME')\n" c̲at 136 " w.thickness = 0.03 / max(r[3:6])\n" c̲at 137 " w.use_relative_offset = False\n" c̲at 138 " made.append(o)\n" c̲at 139 " groups[name] = made\n" c̲at 140 "\n") 141 142⍝ the player, continued: lines 143ʰplayLines ← ("def lines(name, rows):\n" c̲at 144 " made = []\n" c̲at 145 " for i, r in enumerate(rows):\n" c̲at 146 " n = '%s %d' % (name, i + 1)\n" c̲at 147 " cu = bpy.data.curves.new(n, type='CURVE')\n" c̲at 148 " cu.dimensions = '3D'\n" c̲at 149 " cu.bevel_depth = r[9]\n" c̲at 150 " sp = cu.splines.new('POLY')\n" c̲at 151 " sp.points.add(1)\n" c̲at 152 " sp.points[0].co = tuple(r[0:3]) + (1.0,)\n" c̲at 153 " sp.points[1].co = tuple(r[3:6]) + (1.0,)\n" c̲at 154 " o = bpy.data.objects.new(n, cu)\n" c̲at 155 " scene.collection.objects.link(o)\n" c̲at 156 " o.data.materials.append(glow(n, r[6:9], 2.0))\n" c̲at 157 " made.append(o)\n" c̲at 158 " groups[name] = made\n" c̲at 159 "\n") 160 161⍝ the player, continued: text and after 162ʰplayText ← ("def text(n, body, size, rgb):\n" c̲at 163 " c = bpy.data.curves.new(n, type='FONT')\n" c̲at 164 " c.body = body\n" c̲at 165 " c.size = size\n" c̲at 166 " c.align_x = 'CENTER'\n" c̲at 167 " c.align_y = 'CENTER'\n" c̲at 168 " if FONT:\n" c̲at 169 " c.font = FONT\n" c̲at 170 " o = bpy.data.objects.new(n, c)\n" c̲at 171 " scene.collection.objects.link(o)\n" c̲at 172 " o.data.materials.append(glow(n, rgb))\n" c̲at 173 " return o\n" c̲at 174 "\n" c̲at 175 "def labels(name, bodies, rows):\n" c̲at 176 " made = []\n" c̲at 177 " for i, (body, r) in enumerate(zip(bodies.split('|'), rows)):\n" c̲at 178 " o = text('%s %d' % (name, i + 1), body, r[3], r[4:7])\n" c̲at 179 " o.location = r[0:3]\n" c̲at 180 " t = o.constraints.new('TRACK_TO')\n" c̲at 181 " t.target = rig['camera']\n" c̲at 182 " t.track_axis = 'TRACK_Z'\n" c̲at 183 " t.up_axis = 'UP_Y'\n" c̲at 184 " made.append(o)\n" c̲at 185 " groups[name] = made\n" c̲at 186 "\n" c̲at 187 "def view(d):\n" c̲at 188 " f = rig['camera'].data.view_frame(scene=scene)\n" c̲at 189 " k = d / -f[0].z\n" c̲at 190 " return max(abs(v.x) for v in f) * k, max(abs(v.y) for v in f) * k\n" c̲at 191 "\n" c̲at 192 "def wrap(body, size, width):\n" c̲at 193 " return textwrap.fill(body, max(1, int(width / (ADVANCE * size))), break_on_hyphens=False)\n" c̲at 194 "\n" c̲at 195 "def captions(bodies, rows):\n" c̲at 196 " d = 0.05\n" c̲at 197 " hw, hh = view(d)\n" c̲at 198 " size = 0.16 * min(hw, hh)\n" c̲at 199 " line = size\n" c̲at 200 " cam = rig['camera']\n" c̲at 201 " for i, (body, r) in enumerate(zip(bodies.split('|'), rows)):\n" c̲at 202 " body = wrap(body, size, 1.7 * hw)\n" c̲at 203 " n = body.count('\\n')\n" c̲at 204 " o = text('caption %d' % (i + 1), body, size, r[2:5])\n" c̲at 205 " o.data.align_y = 'TOP_BASELINE'\n" c̲at 206 " o.parent = cam\n" c̲at 207 " o.location = (0.0, -0.86 * hh + n * line, -d)\n" c̲at 208 " p = bpy.data.objects.new('plate %d' % (i + 1), cube_mesh())\n" c̲at 209 " scene.collection.objects.link(p)\n" c̲at 210 " p.parent = cam\n" c̲at 211 " p.location = (0.0, -0.86 * hh + 0.35 * size + 0.5 * n * line, -d * 1.002)\n" c̲at 212 " p.scale = (ADVANCE * size * max(len(x) for x in body.split('\\n')) + 1.4 * size, 1.6 * size + n * line, 0.0001)\n" c̲at 213 " p.data.materials.append(glow('plate %d' % (i + 1), (0.0, 0.0, 0.0), 1.0, 0.72))\n" c̲at 214 " for x in (o, p):\n" c̲at 215 " span(x, r[0], r[1])\n" c̲at 216 "\n" c̲at 217 "def cards(titles, subs, rows):\n" c̲at 218 " d = 0.05\n" c̲at 219 " hw, hh = view(d)\n" c̲at 220 " u = min(hw, hh)\n" c̲at 221 " cam = rig['camera']\n" c̲at 222 " made = []\n" c̲at 223 " for i, (title, sub, r) in enumerate(zip(titles.split('|'), subs.split('|'), rows)):\n" c̲at 224 " p = bpy.data.objects.new('card %d' % (i + 1), cube_mesh())\n" c̲at 225 " scene.collection.objects.link(p)\n" c̲at 226 " p.location = (0.0, 0.0, -d * 1.004)\n" c̲at 227 " p.scale = (2.2 * hw, 2.2 * hh, 0.0001)\n" c̲at 228 " p.data.materials.append(glow('card %d' % (i + 1), r[5:8]))\n" c̲at 229 " parts = [p]\n" c̲at 230 " for j, (body, size, y) in enumerate(((title, 0.34 * u, 0.15 * u), (sub, 0.15 * u, -0.3 * u))):\n" c̲at 231 " if body:\n" c̲at 232 " o = text('card %d %s' % (i + 1, 'title' if j == 0 else 'subtitle'), wrap(body, size, 1.8 * hw), size, r[2:5])\n" c̲at 233 " o.location = (0.0, y, -d)\n" c̲at 234 " parts.append(o)\n" c̲at 235 " for x in parts:\n" c̲at 236 " x.parent = cam\n" c̲at 237 " span(x, r[0], r[1])\n" c̲at 238 " made.append(p)\n" c̲at 239 " groups['cards'] = made\n" c̲at 240 "\n") 241 242⍝ the player, continued: span and after 243ʰplayKeys ← ("def span(o, a, b):\n" c̲at 244 " keys = {1: True, frame(a): False, frame(b) + 1: True} if a > 0 else {1: False, frame(b) + 1: True}\n" c̲at 245 " for f in sorted(keys):\n" c̲at 246 " o.hide_render = keys[f]\n" c̲at 247 " o.keyframe_insert('hide_render', frame=f)\n" c̲at 248 "\n" c̲at 249 "def shown(name, rows):\n" c̲at 250 " for o, r in zip(groups[name], rows):\n" c̲at 251 " span(o, r[0], r[1])\n" c̲at 252 "\n" c̲at 253 "def moves(name, times, rows):\n" c̲at 254 " for o, r in zip(groups[name], rows):\n" c̲at 255 " for j, t in enumerate(times):\n" c̲at 256 " o.location = r[6 * j:6 * j + 3]\n" c̲at 257 " o.scale = r[6 * j + 3:6 * j + 6]\n" c̲at 258 " o.keyframe_insert('location', frame=frame(t))\n" c̲at 259 " o.keyframe_insert('scale', frame=frame(t))\n" c̲at 260 "\n" c̲at 261 "def moves_each(name, times, rows):\n" c̲at 262 " for o, ts, r in zip(groups[name], times, rows):\n" c̲at 263 " for j, t in enumerate(ts):\n" c̲at 264 " o.location = r[6 * j:6 * j + 3]\n" c̲at 265 " o.scale = r[6 * j + 3:6 * j + 6]\n" c̲at 266 " o.keyframe_insert('location', frame=frame(t))\n" c̲at 267 " o.keyframe_insert('scale', frame=frame(t))\n" c̲at 268 "\n" c̲at 269 "def tints(name, times, rows):\n" c̲at 270 " for o, r in zip(groups[name], rows):\n" c̲at 271 " s = o.data.materials[0].node_tree.nodes['glow'].inputs['Color']\n" c̲at 272 " for j, t in enumerate(times):\n" c̲at 273 " s.default_value = tuple(r[3 * j:3 * j + 3]) + (1.0,)\n" c̲at 274 " s.keyframe_insert('default_value', frame=frame(t))\n" c̲at 275 "\n" c̲at 276 "def glows(name, times, rows):\n" c̲at 277 " for o, ts, r in zip(groups[name], times, rows):\n" c̲at 278 " s = o.data.materials[0].node_tree.nodes['glow'].inputs['Strength']\n" c̲at 279 " for t, g in zip(ts, r):\n" c̲at 280 " s.default_value = g\n" c̲at 281 " s.keyframe_insert('default_value', frame=frame(t))\n" c̲at 282 "\n" c̲at 283 "def camera(times, eyes, aims):\n" c̲at 284 " for t, e, a in zip(times, eyes, aims):\n" c̲at 285 " rig['camera'].location = e\n" c̲at 286 " rig['camera'].keyframe_insert('location', frame=frame(t))\n" c̲at 287 " rig['aim'].location = a\n" c̲at 288 " rig['aim'].keyframe_insert('location', frame=frame(t))\n" c̲at 289 "\n") 290 291⍝ the player, continued: grid and after 292ʰplayGrid ← ("def grid(name, origin, u, v, shape, colors, order, gap):\n" c̲at 293 " n, m = int(shape[0]), int(shape[1])\n" c̲at 294 " k = n * m\n" c̲at 295 " corners = ((gap, gap), (1 - gap, gap), (1 - gap, 1 - gap), (gap, 1 - gap))\n" c̲at 296 " co = []\n" c̲at 297 " for i in range(n):\n" c̲at 298 " for j in range(m):\n" c̲at 299 " for a, b in corners:\n" c̲at 300 " co.extend(origin[c] + (i + a) * u[c] + (j + b) * v[c] for c in range(3))\n" c̲at 301 " me = bpy.data.meshes.new(name)\n" c̲at 302 " me.vertices.add(4 * k)\n" c̲at 303 " me.vertices.foreach_set('co', co)\n" c̲at 304 " me.loops.add(4 * k)\n" c̲at 305 " me.loops.foreach_set('vertex_index', list(range(4 * k)))\n" c̲at 306 " me.polygons.add(k)\n" c̲at 307 " me.polygons.foreach_set('loop_start', list(range(0, 4 * k, 4)))\n" c̲at 308 " me.update()\n" c̲at 309 " col = me.color_attributes.new('rgb', 'FLOAT_COLOR', 'CORNER')\n" c̲at 310 " rgba = []\n" c̲at 311 " for c in colors:\n" c̲at 312 " rgba.extend((tuple((x / 255.0) ** 2.2 for x in c) + (1.0,)) * 4)\n" c̲at 313 " col.data.foreach_set('color', rgba)\n" c̲at 314 " when = me.attributes.new('order', 'FLOAT', 'CORNER')\n" c̲at 315 " when.data.foreach_set('value', [t[0] / 1000.0 - 0.001 for t in order for _ in range(4)])\n" c̲at 316 " o = bpy.data.objects.new(name, me)\n" c̲at 317 " scene.collection.objects.link(o)\n" c̲at 318 " m = bpy.data.materials.new(name)\n" c̲at 319 " m.use_nodes = True\n" c̲at 320 " nt = m.node_tree\n" c̲at 321 " for x in list(nt.nodes):\n" c̲at 322 " nt.nodes.remove(x)\n" c̲at 323 " a = nt.nodes.new('ShaderNodeAttribute')\n" c̲at 324 " a.attribute_name = 'rgb'\n" c̲at 325 " w = nt.nodes.new('ShaderNodeAttribute')\n" c̲at 326 " w.attribute_name = 'order'\n" c̲at 327 " now = nt.nodes.new('ShaderNodeValue')\n" c̲at 328 " now.name = 'now'\n" c̲at 329 " lt = nt.nodes.new('ShaderNodeMath')\n" c̲at 330 " lt.operation = 'LESS_THAN'\n" c̲at 331 " e = nt.nodes.new('ShaderNodeEmission')\n" c̲at 332 " tr = nt.nodes.new('ShaderNodeBsdfTransparent')\n" c̲at 333 " mx = nt.nodes.new('ShaderNodeMixShader')\n" c̲at 334 " out_ = nt.nodes.new('ShaderNodeOutputMaterial')\n" c̲at 335 " nt.links.new(a.outputs['Color'], e.inputs['Color'])\n" c̲at 336 " nt.links.new(w.outputs['Fac'], lt.inputs[0])\n" c̲at 337 " nt.links.new(now.outputs[0], lt.inputs[1])\n" c̲at 338 " nt.links.new(lt.outputs[0], mx.inputs[0])\n" c̲at 339 " nt.links.new(tr.outputs[0], mx.inputs[1])\n" c̲at 340 " nt.links.new(e.outputs[0], mx.inputs[2])\n" c̲at 341 " nt.links.new(mx.outputs[0], out_.inputs[0])\n" c̲at 342 " m.surface_render_method = 'BLENDED'\n" c̲at 343 " me.materials.append(m)\n" c̲at 344 " s = now.outputs[0]\n" c̲at 345 " bpy.context.preferences.edit.keyframe_new_interpolation_type = 'LINEAR'\n" c̲at 346 " for f in (scene.frame_start, scene.frame_end):\n" c̲at 347 " s.default_value = (f - 1) / scene.render.fps\n" c̲at 348 " s.keyframe_insert('default_value', frame=f)\n" c̲at 349 " bpy.context.preferences.edit.keyframe_new_interpolation_type = 'BEZIER'\n" c̲at 350 " groups[name] = [o]\n" c̲at 351 "\n") 352 353⍝ the player, continued: stills and after 354ʰplayOutput ← ("def stills(times, prefix):\n" c̲at 355 " scene.render.image_settings.media_type = 'IMAGE'\n" c̲at 356 " scene.render.image_settings.file_format = 'PNG'\n" c̲at 357 " for i, t in enumerate(times):\n" c̲at 358 " scene.frame_set(frame(t))\n" c̲at 359 " scene.render.filepath = os.path.join(out, '%s-%d.png' % (prefix, i + 1))\n" c̲at 360 " bpy.ops.render.render(write_still=True)\n" c̲at 361 "\n" c̲at 362 "def video(file):\n" c̲at 363 " scene.render.image_settings.media_type = 'VIDEO'\n" c̲at 364 " scene.render.image_settings.file_format = 'FFMPEG'\n" c̲at 365 " scene.render.ffmpeg.format = 'MPEG4'\n" c̲at 366 " scene.render.ffmpeg.codec = 'H264'\n" c̲at 367 " scene.render.ffmpeg.constant_rate_factor = 'HIGH'\n" c̲at 368 " scene.render.filepath = os.path.join(out, file)\n" c̲at 369 " bpy.ops.render.render(animation=True)\n" c̲at 370 "\n" c̲at 371 "def animated(x):\n" c̲at 372 " return bool(x and x.animation_data and x.animation_data.action)\n" c̲at 373 "\n" c̲at 374 "def report():\n" c̲at 375 " with open(os.path.join(out, 'report.txt'), 'w') as f:\n" c̲at 376 " f.write('frames %d to %d at %d a second\\n' % (scene.frame_start, scene.frame_end, scene.render.fps))\n" c̲at 377 " for name in sorted(groups):\n" c̲at 378 " os_ = groups[name]\n" c̲at 379 " keyed = sum(1 for o in os_ if animated(o) or any(m and animated(m.node_tree) for m in getattr(o.data, 'materials', [])))\n" c̲at 380 " f.write('%s: %d objects, %d keyed\\n' % (name, len(os_), keyed))\n" c̲at 381 "\n") 382 383⍝ the player, continued: steps, readouts, pictures 384ʰplaySteps ← ("def steps(name, path, rows):\n" c̲at 385 " made = groups[name]\n" c̲at 386 " last = {}\n" c̲at 387 " for r in rows:\n" c̲at 388 " i = int(r[0]) - 1\n" c̲at 389 " o = made[i]\n" c̲at 390 " f = frame(r[1])\n" c̲at 391 " v = r[2] if path == 'glow' else r[2:5]\n" c̲at 392 " if path == 'glow':\n" c̲at 393 " o, attr = o.data.materials[0].node_tree.nodes['glow'].inputs['Strength'], 'default_value'\n" c̲at 394 " else:\n" c̲at 395 " attr = path\n" c̲at 396 " if i in last and last[i][0] < f - 1:\n" c̲at 397 " setattr(o, attr, last[i][1])\n" c̲at 398 " o.keyframe_insert(attr, frame=f - 1)\n" c̲at 399 " setattr(o, attr, v)\n" c̲at 400 " o.keyframe_insert(attr, frame=f)\n" c̲at 401 " last[i] = (f, v)\n" c̲at 402 "\n" c̲at 403 "def readout(name, row, bodies, times):\n" c̲at 404 " d = 0.05\n" c̲at 405 " hw, hh = view(d)\n" c̲at 406 " o = text(name, '', row[2] * min(hw, hh), row[3:6])\n" c̲at 407 " o.parent = rig['camera']\n" c̲at 408 " o.location = (row[0] * hw, row[1] * hh, -d)\n" c̲at 409 " fs = [frame(t) for t in times]\n" c̲at 410 " bodies = bodies.split('|')\n" c̲at 411 " def show(sc, *rest):\n" c̲at 412 " body = ''\n" c̲at 413 " for f, b in zip(fs, bodies):\n" c̲at 414 " if f > sc.frame_current:\n" c̲at 415 " break\n" c̲at 416 " body = b\n" c̲at 417 " if o.data.body != body:\n" c̲at 418 " o.data.body = body\n" c̲at 419 " bpy.app.handlers.frame_change_pre.append(show)\n" c̲at 420 " groups[name] = [o]\n" c̲at 421 "\n" c̲at 422 "def picture(name, path, row):\n" c̲at 423 " img = bpy.data.images.load(os.path.abspath(path))\n" c̲at 424 " w = row[3]\n" c̲at 425 " h = w * img.size[1] / img.size[0]\n" c̲at 426 " me = bpy.data.meshes.new(name)\n" c̲at 427 " me.from_pydata([(-w / 2, 0, -h / 2), (w / 2, 0, -h / 2), (w / 2, 0, h / 2), (-w / 2, 0, h / 2)], [], [(0, 1, 2, 3)])\n" c̲at 428 " uv = me.uv_layers.new()\n" c̲at 429 " for i, c in enumerate(((0, 0), (1, 0), (1, 1), (0, 1))):\n" c̲at 430 " uv.data[i].uv = c\n" c̲at 431 " o = bpy.data.objects.new(name, me)\n" c̲at 432 " scene.collection.objects.link(o)\n" c̲at 433 " o.location = row[0:3]\n" c̲at 434 " m = glow(name, (1.0, 1.0, 1.0))\n" c̲at 435 " t = m.node_tree.nodes.new('ShaderNodeTexImage')\n" c̲at 436 " t.image = img\n" c̲at 437 " m.node_tree.links.new(t.outputs['Color'], m.node_tree.nodes['glow'].inputs['Color'])\n" c̲at 438 " me.materials.append(m)\n" c̲at 439 " groups[name] = [o]\n" c̲at 440 "\n") 441 442⍝│ vd:head: the inner script's start, the player: an empty scene, the 443⍝│ output directory (the first argument after "--"), keys eased in and 444⍝│ out (Bezier), and the functions the calls below use -- stage, boxes, 445⍝│ lines, labels, captions, cards, shown, moves, tints, glows, camera, 446⍝│ grid, steps, readout, picture, stills, video, report. Fixed text: what a video shows is all in the numbers after it. 447ˡhead ← ʰplayBase c̲at ʰplayStage c̲at ʰplayLines c̲at ʰplayText c̲at ʰplayKeys c̲at ʰplayGrid c̲at ʰplaySteps c̲at ʰplayOutput 448 449⍝━━ Numbers and text into Python 450 451⍝ (values, k) h:n_ums 0: the values as Python reading them k to a row 452ʰn̲ums ← { (v, k) z → "nums('" c̲at (f̲ormat r̲avel v) c̲at "', " c̲at (f̲ormat k) c̲at ")" } 453 454⍝ q h:q_uoteIn text: the text in quotes (the character code q), each 455⍝ such quote and backslash in it written with a backslash before it 456⍝ (ASCII text): a Python or TOML string 457ʰq̲uoteIn ← { q t → 458 0 = t̲ally t ? ⎕U̲CHAR q c̲at q 459 c ← ⎕U̲CS t 460 e ← (c = q) ∨ c = 92 461 k ← (1 + e) r̲eplicate r̲ange t̲ally c 462 m ← ((1 + e) r̲eplicate e) ∧ k ≠ 0 c̲at -1 d̲rop k 463 (⎕U̲CHAR q) c̲at (⎕U̲CHAR (92 × m) + (1 − m) × (1 + e) r̲eplicate c) c̲at ⎕U̲CHAR q 464} 465 466⍝ a Python string: the text in single quotes 467ʰq̲uote ← { t → 39 ʰq̲uoteIn t } 468 469⍝ one value as text with d digits after the point, rounded 470ʰo̲ne ← { d x → 471 k ← 10 ^ d 472 n ← f̲loor 0.5 + (f̲loat k) × a̲bs x 473 s ← (x < 0.0) ∧ n > 0 474 (s t̲ake "-") c̲at (f̲ormat n d̲iv k) c̲at ((d > 0) t̲ake ".") c̲at 1 d̲rop f̲ormat k + n m̲od k 475} 476 477⍝ two boxed texts joined by | 478ʰj̲oin ← { a b → e̲nclose (d̲isclose a) c̲at "|" c̲at d̲isclose b } 479 480⍝│ d vd:f_ixed values: the values as text, each with d digits after the 481⍝│ point (none and no point for 0), rounded, separated by | -- the labels of vd:l_abels 482⍝│ >> "vd:" u_se< "Video" 483⍝│ >> 2 vd:f_ixed 0.75 -1.0 0.125 -0.004 484⍝│ 0.75|-1.00|0.13|0.00 485⍝│ >> 0 vd:f_ixed 1.0 -1.0 44.0 486⍝│ 1|-1|44 487ˡf̲ixed ← { d v → d̲isclose 'ʰj̲oin r̲/ '{ x → d ʰo̲ne x } m̲ap r̲avel v } 488 489⍝━━ Colors 490 491⍝│ vd:l_inear rgb: colors written 0 to 255 (sRGB, a row of red green blue 492⍝│ each, any number of rows) as Blender's linear 0 to 1 493⍝│ >> "vd:" u_se< "Video" 494⍝│ >> vd:l_inear 255 128 0 495⍝│ 1.0 0.2195197180748679 0.0 496ˡl̲inear ← { c → ((f̲loat c) ÷ 255.0) ^ 2.2 } 497 498⍝ a channel's share of the light (sRGB to linear, WCAG's way) 499ʰc̲hannel ← { c → 500 s ← (f̲loat c) ÷ 255.0 501 m ← f̲loat s ≤ 0.04045 502 (m × s ÷ 12.92) + (1.0 − m) × ((s + 0.055) ÷ 1.055) ^ 2.4 503} 504 505⍝│ vd:l_uminance rgb: how bright a color (0 to 255, sRGB) is, 0 to 1 506⍝│ (WCAG's relative luminance) 507ˡl̲uminance ← { c → '+ r̲/ 0.2126 0.7152 0.0722 × ʰc̲hannel c } 508 509⍝│ a vd:c_ontrast b: the contrast of two colors (0 to 255, sRGB), 1 to 510⍝│ 21 (WCAG): text should be 7 or more on its background 511⍝│ >> "vd:" u_se< "Video" 512⍝│ >> f_loor 255 255 255 vd:c_ontrast 0 0 0 513⍝│ 21 514ˡc̲ontrast ← { a b → 515 la ← ˡl̲uminance a 516 lb ← ˡl̲uminance b 517 ((la m̲ax lb) + 0.05) ÷ (la m̲in lb) + 0.05 518} 519 520⍝│ the stops of vd:t_one, low to high: deep blue, cyan, yellow, orange 521⍝│ (0 to 255) 522ˡstops ← 4 3 r̲eshape 43 74 154 47 183 214 255 216 77 255 122 61 523 524⍝│ (values, low, high) vd:t_one 0: a color for each value (n by 3, 0 to 525⍝│ 255): low is deep blue, high orange, through cyan and yellow, mixed 526⍝│ between the stops; values outside are the ends' colors -- how big a 527⍝│ number is, at a glance 528⍝│ >> "vd:" u_se< "Video" 529⍝│ >> (0.0 0.5 1.0, 0.0, 1.0) vd:t_one 0 530⍝│ 43.0 74.0 154.0 531⍝│ 151.0 199.5 145.5 532⍝│ 255.0 122.0 61.0 533ˡt̲one ← { (v, lo, hi) z → 534 x ← 3.0 × 0.0 m̲ax 1.0 m̲in ((f̲loat r̲avel v) − lo) ÷ 0.000000001 m̲ax hi − lo 535 i ← 2 m̲in f̲loor x 536 u ← x − f̲loat i 537 a ← (i + 1) s̲elect f̲loat ˡstops 538 b ← (i + 2) s̲elect f̲loat ˡstops 539 (a × (1.0 − u) 'l̲eft t̲able 1 2 3) + b × u 'l̲eft t̲able 1 2 3 540} 541 542⍝━━ Pictures and time 543 544⍝│ vd:landscape: a YouTube video's picture, 1920 by 1080 (width, height) 545ˡlandscape ← 1920 1080 546 547⍝│ vd:shorts: a YouTube Short's picture, 1080 by 1920, upright 548ˡshorts ← 1080 1920 549 550⍝│ (width, height, lens, w, h) vd:f_it 0: how far from a region w by h 551⍝│ (meters, facing it) a camera with that lens (mm) stands for the 552⍝│ region to just fill a picture width by height (pixels): Blender fits 553⍝│ its 36 mm sensor to the picture's longer side, so the same region 554⍝│ needs the camera further back in a Short 555⍝│ >> "vd:" u_se< "Video" 556⍝│ >> (1920, 1080, 36, 4.0, 1.0) vd:f_it 0 557⍝│ 4.0 558⍝│ >> (1000, 2000, 36, 2.0, 2.0) vd:f_it 0 559⍝│ 4.0 560ˡf̲it ← { (pw, ph, lens, w, h) z → 561 t ← 18.0 ÷ f̲loat lens 562 tw ← t × (f̲loat pw) ÷ f̲loat pw m̲ax ph 563 th ← t × (f̲loat ph) ÷ f̲loat pw m̲ax ph 564 ((0.5 × w) ÷ tw) m̲ax (0.5 × h) ÷ th 565} 566 567⍝│ (map, times) vd:r_etime 0: a scene's own seconds as the video's: 568⍝│ map is k by 2 (k at least 2), a row a pair (scene second, video 569⍝│ second), both increasing; a time between two rows falls between 570⍝│ their video seconds in proportion, one before the first or after the 571⍝│ last on the nearest pair's line. Where the video has more seconds 572⍝│ than the scene it is slow motion, fewer a time-lapse: a scene is 573⍝│ worked out in its own seconds and every time in it -- spans, keys, 574⍝│ the camera, captions -- passed through the map. Times of any shape. 575⍝│ >> "vd:" u_se< "Video" 576⍝│ >> (3 2 r_eshape 0 0 4 8 8 9, 0.0 2.0 4.0 6.0 8.0 10.0) vd:r_etime 0 577⍝│ 0.0 4.0 8.0 8.5 9.0 9.5 578ˡr̲etime ← { (m, t) z → 579 s ← f̲loat 1 s̲elect₂ m 580 v ← f̲loat 2 s̲elect₂ m 581 k ← t̲ally s 582 '{ x → 583 i ← 1 m̲ax (k − 1) m̲in '+ r̲/ s ≤ x 584 (i s̲elect v) + ((x − i s̲elect s) × ((i + 1) s̲elect v) − i s̲elect v) ÷ ((i + 1) s̲elect s) − i s̲elect s 585 } e̲ach f̲loat t 586} 587 588⍝━━ Cues 589 590⍝ the texts between |s, boxed (none may be empty) 591ʰt̲exts ← { t → (n̲ot t = f̲irst "|") p̲artition t } 592 593⍝ two boxed texts as one 594ʰc̲at ← { a b → e̲nclose (d̲isclose a) c̲at d̲isclose b } 595 596⍝ seconds as an SRT time, hh:mm:ss,mmm 597ʰs̲rtTime ← { x → 598 ms ← f̲loor 0.5 + 1000.0 × x 599 (1 d̲rop f̲ormat 100 + ms d̲iv 3600000) c̲at ":" c̲at (1 d̲rop f̲ormat 100 + (ms d̲iv 60000) m̲od 60) c̲at ":" c̲at (1 d̲rop f̲ormat 100 + (ms d̲iv 1000) m̲od 60) c̲at "," c̲at 1 d̲rop f̲ormat 1000 + ms m̲od 1000 600} 601 602⍝│ (texts, table) vd:s_rt 0: the captions as subtitles, an .srt file's 603⍝│ text: one a row of the table, from and to (seconds; more columns, as 604⍝│ vd:c_aptions's colors, are ignored), texts as vd:c_aptions's (none 605⍝│ empty) -- what an editor or YouTube shows under the video, timed to 606⍝│ the narration recorded against it 607⍝│ >> "vd:" u_se< "Video" 608⍝│ >> ("two", 1 2 r_eshape 61.0 3725.5) vd:s_rt 0 609⍝│ 1 610⍝│ 00:01:01,000 --> 01:02:05,500 611⍝│ two 612⍝│ 613ˡs̲rt ← { (texts, t) z → 614 b ← ʰt̲exts texts 615 a ← 1 s̲elect₂ t 616 e ← 2 s̲elect₂ t 617 d̲isclose 'ʰc̲at r̲/ '{ i → (f̲ormat i) c̲at "\n" c̲at (ʰs̲rtTime i s̲elect a) c̲at " --> " c̲at (ʰs̲rtTime i s̲elect e) c̲at "\n" c̲at (d̲isclose i s̲elect b) c̲at "\n\n" } m̲ap r̲ange t̲ally b 618} 619 620⍝│ (texts, table) vd:c_ues 0: the cue sheet of the same captions, as 621⍝│ TOML: a [[cue]] a row -- its number, start and end (seconds) and its 622⍝│ caption -- the scenes to record narration against, read by a program 623⍝│ (arguments as vd:s_rt's) 624⍝│ >> "vd:" u_se< "Video" 625⍝│ >> ("the \"top\"", 1 2 r_eshape 0.0 3.5) vd:c_ues 0 626⍝│ [[cue]] 627⍝│ n = 1 628⍝│ start = 0.000 629⍝│ end = 3.500 630⍝│ caption = "the \"top\"" 631⍝│ 632ˡc̲ues ← { (texts, t) z → 633 b ← ʰt̲exts texts 634 a ← 1 s̲elect₂ t 635 e ← 2 s̲elect₂ t 636 d̲isclose 'ʰc̲at r̲/ '{ i → "[[cue]]\nn = " c̲at (f̲ormat i) c̲at "\nstart = " c̲at (3 ˡf̲ixed i s̲elect a) c̲at "\nend = " c̲at (3 ˡf̲ixed i s̲elect e) c̲at "\ncaption = " c̲at (34 ʰq̲uoteIn d̲isclose i s̲elect b) c̲at "\n\n" } m̲ap r̲ange t̲ally b 637} 638 639⍝━━ The calls 640 641⍝│ (width, height, fps, seconds, sky, lens) vd:s_tage 0: Python setting 642⍝│ the picture's size, the frame rate and the video's length, EEVEE and 643⍝│ the Standard view, the sky's color (0 to 255), and the camera (a lens 644⍝│ of that many mm) looking at an aim; both start at the origin until 645⍝│ vd:c_amera keys them. First, before any group. 646ˡs̲tage ← { (w, h, fps, secs, sky, lens) z → 647 "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 ((ˡl̲inear sky, 3) ʰn̲ums 0) c̲at "[0], " c̲at (f̲ormat lens) c̲at ")\n" 648} 649 650⍝ the Python for a group of boxes in a style 651ʰb̲oxes ← { style (name, t) → 652 "boxes(" c̲at (ʰq̲uote name) c̲at ", " c̲at (((ʰp̲aint t), 10) ʰn̲ums 0) c̲at ", " c̲at (ʰq̲uote style) c̲at ")\n" 653} 654 655⍝ a table's rows x y z w d h r g b strength with the colors made linear 656ʰp̲aint ← { t → 657 (6 t̲ake₂ f̲loat t) c̲at₂ (ˡl̲inear 3 t̲ake₂ 6 d̲rop₂ t) c̲at₂ 10 s̲elect₂ f̲loat t 658} 659 660⍝│ (name, table) vd:b_oxes 0: Python making a group of solid boxes, 661⍝│ objects NAME 1 to NAME n, one a row of the table: x y z (its middle), 662⍝│ w d h (its size), r g b (0 to 255) and how strongly it glows (1 is 663⍝│ its color as given). A bar of height h standing on the floor has its 664⍝│ middle at h / 2; one hanging below it at -h / 2. 665⍝│ >> "vd:" u_se< "Video" 666⍝│ >> ("bar", 1 10 r_eshape 0 0 1 1 1 2 255 255 255 1) vd:b_oxes 0 667⍝│ boxes('bar', nums('0.0 0.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 1.0', 10), 'solid') 668ˡb̲oxes ← { (name, t) z → "solid" ʰb̲oxes (name, t) } 669 670⍝│ (name, table) vd:o_utlines 0: Python making a group of boxes drawn as 671⍝│ their edges only (a wireframe), rows as vd:b_oxes: what a value was 672⍝│ before it went 673ˡo̲utlines ← { (name, t) z → "wire" ʰb̲oxes (name, t) } 674 675⍝│ (name, table) vd:g_lass 0: Python making a group of see-through 676⍝│ boxes, rows as vd:b_oxes: a floor at zero that bars stand on and 677⍝│ hang below 678ˡg̲lass ← { (name, t) z → "glass" ʰb̲oxes (name, t) } 679 680⍝│ (name, table) vd:l_ines 0: Python making a group of straight lines 681⍝│ that glow, one a row of the table: from x y z, to x y z, r g b (0 to 682⍝│ 255) and the line's radius -- a guide from one thing to another 683ˡl̲ines ← { (name, t) z → 684 p ← (6 t̲ake₂ f̲loat t) c̲at₂ (ˡl̲inear 3 t̲ake₂ 6 d̲rop₂ t) c̲at₂ 10 s̲elect₂ f̲loat t 685 "lines(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((p, 10) ʰn̲ums 0) c̲at ")\n" 686} 687 688⍝│ (name, texts, table) vd:l_abels 0: Python making a group of words, 689⍝│ one a row of the table -- x y z (its middle), its height, r g b (0 690⍝│ to 255) -- each turned to face the camera; texts are the words, | between 691⍝│ them (vd:f_ixed writes numbers so) 692ˡl̲abels ← { (name, texts, t) z → 693 p ← (4 t̲ake₂ f̲loat t) c̲at₂ ˡl̲inear 3 t̲ake₂ 4 d̲rop₂ t 694 "labels(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰq̲uote texts) c̲at ", " c̲at ((p, 7) ʰn̲ums 0) c̲at ")\n" 695} 696 697⍝│ (texts, table) vd:c_aptions 0: Python putting captions near the bottom 698⍝│ of the picture, on a dark plate, one a row of the table: from and to 699⍝│ (seconds), r g b (0 to 255); texts as vd:l_abels. Sized to the 700⍝│ picture's shorter side and wrapped to its width, so the same captions 701⍝│ read in a Short (vd:c_ues and vd:s_rt write them for narration) 702ˡc̲aptions ← { (texts, t) z → 703 p ← (2 t̲ake₂ f̲loat t) c̲at₂ ˡl̲inear 2 d̲rop₂ t 704 "captions(" c̲at (ʰq̲uote texts) c̲at ", " c̲at ((p, 5) ʰn̲ums 0) c̲at ")\n" 705} 706 707⍝│ (name, spans) vd:s_hown 0: Python showing each object of the group 708⍝│ only from one second to another, a row of spans each (n by 2); a span 709⍝│ from 0 shows it from the start 710ˡs̲hown ← { (name, s) z → "shown(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((f̲loat s, 2) ʰn̲ums 0) c̲at ")\n" } 711 712⍝│ (name, times, places) vd:m_oves 0: Python keying each object of the 713⍝│ group to its place and size at the times (k seconds): places is n by 714⍝│ k by 6, x y z w d h; between keys they ease from one to the next 715ˡm̲oves ← { (name, ts, p) z → 716 k ← 6 × t̲ally ts 717 "moves(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((f̲loat ts, t̲ally ts) ʰn̲ums 0) c̲at "[0], " c̲at ((f̲loat p, k) ʰn̲ums 0) c̲at ")\n" 718} 719 720⍝│ (name, times, places) vd:m_ovesEach 0: as vd:m_oves, but each object 721⍝│ keyed at times of its own: times is n by k, a row an object -- things 722⍝│ that move one after another 723ˡm̲ovesEach ← { (name, ts, p) z → 724 k ← 2 s̲elect s̲hape ts 725 "moves_each(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((f̲loat ts, k) ʰn̲ums 0) c̲at ", " c̲at ((f̲loat p, 6 × k) ʰn̲ums 0) c̲at ")\n" 726} 727 728⍝│ (name, times, colors) vd:t_ints 0: Python keying each object's color 729⍝│ at the times (k seconds): colors is n by k by 3, 0 to 255 730ˡt̲ints ← { (name, ts, c) z → 731 k ← 3 × t̲ally ts 732 "tints(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((f̲loat ts, t̲ally ts) ʰn̲ums 0) c̲at "[0], " c̲at ((ˡl̲inear c, k) ʰn̲ums 0) c̲at ")\n" 733} 734 735⍝│ (name, times, strengths) vd:g_lows 0: Python keying how strongly 736⍝│ each object of the group glows (1 is its color as given, 0 dark), at 737⍝│ times of its own: times and strengths are n by k, a row an object -- 738⍝│ a value's size or a part's activity as light (a flash when a register 739⍝│ is written, a cell lit as it is reached) 740ˡg̲lows ← { (name, ts, g) z → 741 k ← 2 s̲elect s̲hape ts 742 "glows(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((f̲loat ts, k) ʰn̲ums 0) c̲at ", " c̲at ((f̲loat g, k) ʰn̲ums 0) c̲at ")\n" 743} 744 745⍝│ (titles, subtitles, table) vd:c_ards 0: Python putting title cards in 746⍝│ front of the camera, each filling the picture, one a row of the 747⍝│ table: from and to (seconds), r g b of the words, r g b of the card 748⍝│ (0 to 255); a title big in the middle, its subtitle smaller below, 749⍝│ each wrapped to the picture's width; | between the cards' texts (an 750⍝│ empty subtitle: none) 751ˡc̲ards ← { (titles, subs, t) z → 752 p ← (2 t̲ake₂ f̲loat t) c̲at₂ (ˡl̲inear 3 t̲ake₂ 2 d̲rop₂ t) c̲at₂ ˡl̲inear 3 t̲ake₂ 5 d̲rop₂ t 753 "cards(" c̲at (ʰq̲uote titles) c̲at ", " c̲at (ʰq̲uote subs) c̲at ", " c̲at ((p, 8) ʰn̲ums 0) c̲at ")\n" 754} 755 756⍝│ (times, eyes, aims) vd:c_amera 0: Python keying the camera: at each 757⍝│ time (k seconds) it is at an eye (k by 3) looking at an aim (k by 3) 758ˡc̲amera ← { (ts, e, a) z → 759 "camera(" 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 ")\n" 760} 761 762⍝│ (name, what, rows) vd:s_teps 0: Python keying the group's objects in 763⍝│ steps -- each value holds until the next (keyed again the frame 764⍝│ before it), the change within one frame: a lamp on or off, 765⍝│ a marker jumping from place to place, a bar's new length. A row a 766⍝│ key: the object (from 1), the second, then its value -- what "glow" 767⍝│ (how strongly it glows), "location" (x y z) or "scale" (w d h). 768⍝│ Rows for one object in time order; data sampled once a frame keys 769⍝│ only where it changed 770⍝│ >> "vd:" u_se< "Video" 771⍝│ >> ("lamp", "glow", 2 3 r_eshape 1 0.0 0.0 1 2.5 1.0) vd:s_teps 0 772⍝│ steps('lamp', 'glow', nums('1.0 0.0 0.0 1.0 2.5 1.0', 3)) 773ˡs̲teps ← { (name, what, rows) z → 774 k ← 2 s̲elect s̲hape rows 775 "steps(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰq̲uote what) c̲at ", " c̲at ((f̲loat rows, k) ʰn̲ums 0) c̲at ")\n" 776} 777 778⍝│ (name, place, texts, times) vd:r_eadout 0: Python putting a readout 779⍝│ in front of the camera -- a counter, a register's name -- that shows 780⍝│ each text from its time (seconds, increasing) until the next, nothing 781⍝│ before the first: texts | between them, as vd:l_abels. place: x and y 782⍝│ as fractions of the picture's half width and half height from its 783⍝│ middle, the text's height as a fraction of its shorter half, r g b 784⍝│ (0 to 255). The text changes as the video plays (a frame handler), 785⍝│ so the numbers are the data's own, not keys 786ˡr̲eadout ← { (name, p, texts, ts) z → 787 q ← (3 t̲ake f̲loat p) c̲at ˡl̲inear 3 d̲rop p 788 "readout(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((q, t̲ally q) ʰn̲ums 0) c̲at "[0]" c̲at ", " c̲at (ʰq̲uote texts) c̲at ", " c̲at ((f̲loat ts, t̲ally ts) ʰn̲ums 0) c̲at "[0])\n" 789} 790 791⍝│ (name, path, place) vd:p_icture 0: Python putting a picture (a PNG, 792⍝│ path from the working directory) in the scene, upright and facing -y, 793⍝│ glowing as its own colors: place is x y z (its middle) and its width 794⍝│ (meters); its height keeps the picture's shape -- a screenshot beside 795⍝│ the model of what it shows 796ˡp̲icture ← { (name, path, p) z → 797 "picture(" c̲at (ʰq̲uote name) c̲at ", " c̲at (ʰq̲uote path) c̲at ", " c̲at ((f̲loat p, 4) ʰn̲ums 0) c̲at "[0]" c̲at ")\n" 798} 799 800⍝│ (name, origin, u, v, colors, order, gap) vd:g_rid 0: Python making a 801⍝│ grid of n by m flat cells as one mesh: cell (i, j) spans origin + 802⍝│ i u to origin + (i + 1) u along one side and j v along the other, 803⍝│ less gap (a fraction) at each edge; colors is n by m by 3 (0 to 255) 804⍝│ and order n by m, the second each cell appears (0: from the start) -- 805⍝│ a wall of a matrix, filled in as it is worked out. Written compactly 806⍝│ for big grids (a 512 by 512 wall is 262,144 cells): the colors as 807⍝│ whole numbers, made linear by the player, the seconds as whole 808⍝│ milliseconds. 809ˡg̲rid ← { (name, at, u, v, c, w, g) z → 810 s ← 2 t̲ake s̲hape c 811 cs ← f̲loor 0.5 + f̲loat c 812 ms ← f̲loor 0.5 + 1000.0 × f̲loat w 813 "grid(" c̲at (ʰq̲uote name) c̲at ", " c̲at ((f̲loat at, 3) ʰn̲ums 0) c̲at "[0], " c̲at ((f̲loat u, 3) ʰn̲ums 0) c̲at "[0], " c̲at ((f̲loat v, 3) ʰn̲ums 0) c̲at "[0], " c̲at ((f̲loat s, 2) ʰn̲ums 0) c̲at "[0], " c̲at ((cs, 3) ʰn̲ums 0) c̲at ", " c̲at ((ms, 1) ʰn̲ums 0) c̲at ", " c̲at (f̲ormat g) c̲at ")\n" 814} 815 816⍝│ (times, name) vd:s_tills 0: Python rendering the frames at the times 817⍝│ (seconds) as out/NAME-1.png, NAME-2.png, ... 818ˡs̲tills ← { (ts, name) z → "stills(" c̲at ((f̲loat ts, t̲ally ts) ʰn̲ums 0) c̲at "[0], " c̲at (ʰq̲uote name) c̲at ")\n" } 819 820⍝│ vd:r_ender file: Python rendering every frame to out/FILE, an MP4 821⍝│ (H.264) 822ˡr̲ender ← { file → "video(" c̲at (ʰq̲uote file) c̲at ")\n" } 823 824⍝│ vd:report: Python writing out/report.txt: the frames, and each group, 825⍝│ how many objects and how many of them keyed (the object or its 826⍝│ material: a tint or a glow) -- what a test checks 827ˡreport ← "report()\n"