A different route

Contents Previous Next

Install

npm install -g @lmctl-ai/lmctl

lmvideo 0.1.38 is released. Source examples are pinned to public commit aab2677.

Download lmvideo 0.1.38

Twelve colored balls find their way through fifteen pegs. Motion is replayed through a smooth periodic phase to form the loop.

Run this example

lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmvideo/aab2677a4b6264ae6afae8ad64a1d7c1dcd3a052/examples/physics/plinko.lms

Source

# Plinko: seeded spheres, a mid-flight witness, and a time-replayed loop.
mkdir("build/physics");
program=_lmcode_ cli="lmvideo" install="github:lmctl-ai/lmvideo@v0.1.38";
let w=physics_world(0.008333333,77).gravity(0.0,-9.81,0.0).planar(true);
let ball=physics_material(0.35,0.7);let peg=physics_material(0.6,0.2);
w.box(9.0,0.4,5.0,0.0,-0.2,0.0,0.0,physics_material(0.8,0.1));
for(i in range(0,15)){w.sphere(0.14,-2.6+float(i%5)*1.3,0.7+float(i/5)*0.75,0.0,0.0,peg);}
for(i in range(0,12)){w.sphere(0.23,-2.0+float(i%4)*1.3,3.2+float(i/4)*0.65,0.0,0.35,ball);}
let take=w.bake(180,1);video.size(512,384);video.fps(24);video.frames(96);video.output("build/physics/plinko.mp4");video.begin();
let s=scene3d().background("#101827").ambient(0.26);let c=camera3d().look_at(7.0,5.0,10.0,0.0,1.3,0.0).perspective(43.0,0.1,40.0);
for(f in range(0,video.count())){video.frame();let q=sin(3.1415926535*float(f)/96.0);let t=q*q;s.clear().camera(c).shadows(256,0.0004,0.001,1).directional_light(-2.0,5.0,4.0,"#fff0d4",1.3);s.add(mesh_box(9.0,0.4,5.0),"#c89d72").position(0.0,-0.2,0.0);for(i in range(0,15)){let peg=s.add(mesh_sphere(0.14,14,20),"#d6c28c");take.pose(t,i+1).sync(peg);}for(i in range(0,12)){for(g in range(1,4)){let pf=(f-6*g+96)%96;let gq=sin(3.1415926535*float(pf)/96.0);let gt=gq*gq;let ghost=s.add(mesh_sphere(0.23,16,24),material("#e9a65b",0.0,0.8).opacity(0.11/float(g)).alpha("blend",0.5)).unlit(true).cast_shadow(false).receive_shadow(false);take.pose(gt,i+16).sync(ghost);}let n=s.add(mesh_sphere(0.23,16,24),"#e9a65b");take.pose(t,i+16).sync(n);}let im=s.render_image(512,384,2);canvas.clear("#101827");canvas.image(im,0.0,0.0);canvas.text("time-replayed physics",16.0,28.0,font(15.0),paint().color("#fff1d6"));if(f==40){im.save("build/physics/plinko.png");}}
video.end();
end _lmcode_
r=run_lmcode(program);assert(r.ok,(r.ok ? "" : r.message));

Raw LMScript source

Twelve colored balls find their way through fifteen pegs. (4.0 seconds)
A different route
Twelve colored balls find their way through fifteen pegs.