A bowl full of momentum
Install
npm install -g @lmctl-ai/lmctl
lmvideo 0.1.38 is released. Source examples are pinned to public commit aab2677.
Follow the rebounds as a crowd of colored balls finds the floor. 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/ballpit-impact.lms
Source
# Physics motion: pastel balls arriving in a shallow pit, with depth-tested afterimages at impact.
mkdir("build/physics");
program=_lmcode_ cli="lmvideo" install="github:lmctl-ai/lmvideo@v0.1.38";
let world=physics_world(0.008333333,1337).gravity(0.0,-9.81,0.0).planar(true);
world.box(10.0,0.4,5.0,0.0,-0.2,0.0,0.0,physics_material(0.8,0.12));
for(i in range(0,24)){world.sphere(0.22,-2.5+float(i%8)*0.7,2.0+float(i/8)*0.65,0.0,0.35,physics_material(0.42,0.58));}
let take=world.bake(180,1);
fn palette(i: int) -> string { let c="#f2c86d"; if(i%4==0){c="#ef8f8f";} if(i%4==1){c="#79c7c0";} if(i%4==2){c="#9fa5dc";} return c; }
video.size(512,384);video.fps(24);video.frames(96);video.output("build/physics/ballpit-impact.mp4");video.begin();
let scene=scene3d().background("#10192b").ambient(0.28);let camera=camera3d().look_at(7.0,4.0,10.0,0.0,1.0,0.0).perspective(43.0,0.1,40.0);
for(frame in range(0,video.count())){
video.frame();let phase=sin(3.1415926535*float(frame)/96.0);let t=phase*phase;scene.clear();scene.camera(camera).shadows(256,0.0004,0.001,1);scene.directional_light(-3.0,6.0,5.0,"#fff0d6",1.3);scene.add(mesh_box(10.0,0.4,5.0),"#bd9b7a").position(0.0,-0.2,0.0);
for(i in range(0,24)){for(g in range(1,2)){let pf=(frame-6*g+96)%96;let gq=sin(3.1415926535*float(pf)/96.0);let gt=gq*gq;let ghost=scene.add(mesh_sphere(0.22,16,24),material(palette(i),0.0,0.8).opacity(0.14).alpha("blend",0.5)).unlit(true).cast_shadow(false).receive_shadow(false);take.pose(gt,i+1).sync(ghost);}let node=scene.add(mesh_sphere(0.22,16,24),palette(i));take.pose(t,i+1).sync(node);}
let rendered=scene.render_image(512,384,2);canvas.clear("#101827");canvas.image(rendered,0.0,0.0);canvas.text("time-replayed physics",16.0,28.0,font(15.0),paint().color("#fff1d6"));if(frame==24){rendered.save("build/physics/ballpit-impact.png");}
}
video.end();
end _lmcode_
r=run_lmcode(program);assert(r.ok,(r.ok ? "" : r.message));