LayMeshDocs
中文

Styles and animation: complete projects#

Start with style and animation libraries: learn bundled libraries, sources and imports, then explore entries, parameters and composition. One .lay file is enough to begin.

Style manual · Animation manual

Three complete projects progress from library composition to artistic text and a complex scene. Each includes editable .lay, themes, resources and a real WASM preview. Static images and animation use the same source. Inspect the complete layout, then choose Present: their first step uses after-previous and starts on entry.

Project Appearance Motion
Library cards Bootstrap colors, 2mm blur override, Open Props gradients/radii/shadows, inset shadow Title entrance, staggered cards, stroke drawing, custom perspective emphasis
Artistic poster Glyph gradients, outlines, vector extrusion, curved text, wave warp, shadows, glow, transparent image Independent children, repeated alternating motion, perspective on the whole group
Complex dashboard 256 vector motifs, 12 plots, 24 equations, translucent panels and effects Parallel loops, negative delays, perspective flips, 12 drawn strokes, finite window

styled-cards#

Three offline libraries and one project theme#

The layout stores dimensions, placement, component content and steps. styled-theme.lcss manages appearance and keyframes together, explicitly importing Bootstrap, Open Props and Animate.css. metric() reuses the card structure. A loop reads three content records and assigns their appearance classes. The first card follows the note; each subsequent card connects to its predecessor's top_right. Text inside each group also follows bottom_left anchors.

The first combines bg-primary rounded shadow custom and changes only Bootstrap shadow blur to 2mm. The second uses Open Props variables for gradient, radius and layered shadow; the third uses an inset shadow. Descendant selectors such as .metric .label unify child text. Explicit parameter priority still applies.

Full source
styled-cards.lay
# Reusable appearance and motion live in styled-theme.lcss; geometry stays here.page = canvas(size=(200mm,105mm), stylesheet="styled-theme.lcss", background="#f6f7fb")title = page.add(text("Style + motion",class="heading"),target=page.top_left,offset=(12mm,8mm))note = page.add(text("Three offline libraries / one project theme",class="caption"),target=title.bottom_left,offset=(0mm,5mm)) function metric(label,value,detail,appearance) {  card = group(class="metric")  plate = card.add(rect(size=(54mm,38mm),class=appearance))  label_text = card.add(text(label,class="label"),target=plate.top_left,offset=(5mm,5mm))  value_text = card.add(text(value,class="value"),target=label_text.bottom_left,offset=(0mm,6mm))  card.add(text(detail,class="footnote"),target=value_text.bottom_left,offset=(0mm,7mm))  return card}metrics = [  ("Bootstrap","2 mm","Blur override only","bg-primary rounded shadow custom"),  ("Open Props","Gradient","Radius + layered shadow","ocean"),  ("Inset shadow","Inside","Same animation pipeline","inset")]instances = []for label,value,detail,appearance in metrics {  target = note.bottom_left  gap = (0mm,10mm)  if len(instances) > 0 {    target = instances[len(instances)-1].top_right    gap = (7mm,0mm)  }  item = page.add(metric(label,value,detail,appearance),target=target,offset=gap)  instances = append(instances,item)}rule = page.add(line(length=page.width-24mm,class="rule"),target=instances[0].bottom_left,offset=(0mm,11mm))page.add(text("Theme + components + anchors",class="caption"),target=rule.start,offset=(0mm,9mm)) intro = page.step(name="Title",start="after-previous",hold=200ms)intro.animate(title,class="animate__animated animate__fadeInDown",duration=600ms)intro.animate(note,class="animate__animated animate__fadeIn",duration=400ms,delay=200ms)cards = page.step(name="Staggered cards",start="after-previous",hold=400ms)for i,item in enumerate(instances) {  cards.animate(item,class="animate__animated animate__fadeInUp",duration=700ms,delay=i*150ms)}cards.animate(rule,name="laymesh-draw",duration=1s,fill="both")focus = page.step(name="Inspect one card",start="after-previous",hold=400ms)focus.animate(instances[1],class="focus-motion")

Preview

Background
Preparing animation…
Styled Cards
Preparing preview…
Total —
Details

Not run yet

Measured in this browser; excludes debounce.

Edits stay on this page
Dependencies
  • examples/animation/styled-cards.lay
  • examples/animation/styled-theme.lcss

instances = append(instances,item) saves each placed instance. append() returns a new list, so assign its result. A second loop passes the instances to animate() with delay=i*150ms for staggered entrances. Changing card size or font size moves adjacent cards and subsequent text through their anchors, without editing individual page coordinates.

Global time Action
0–0.6s Title and note enter together; note has a 0.2s delay
0.6–0.8s Hold
0.8–1.8s Cards start 0.15s apart; the divider draws concurrently
1.8–2.2s Hold
2.2–3.1s The second card runs the theme's custom perspective motion
3.1–3.5s Hold, then retain the final state

Edit box-shadow-blur:2mm in the theme: both static and animated shadows change. box-shadow-spread:2mm changes expansion instead. Edit focus-card to change motion. Explicit duration in an action overrides CSS timing; see step parameters.

Layout source · Project theme

art-direction#

Animate the existing artistic text and effects examples#

This project adapts the existing artistic text example and transparent image/group effects, moving repeated appearance into art-direction.lcss. The repository's alpha-ring.png needs no download.

Full source
art-direction.lay
# Adapted from examples/effects/art-text.lay and images-groups.lay.page = canvas(size=(180mm,125mm),stylesheet="art-direction.lcss",background="#f6f7fb")heading = page.add(text("ART DIRECTION / styled and animated",class="heading"),target=page.top_left,offset=(12mm,8mm))art = group()plate = art.add(rect(size=(156mm,83mm),class="plate"))hero = art.add(text("Layers in motion",class="hero"),target=plate.top_left,offset=(8mm,8mm))route = path(commands=[move_to(0mm,10mm),cubic_to(35mm,0mm,95mm,0mm,128mm,10mm)],class="route")# Path and path text share their local origin; place their group as a unit.curve = group()trace = curve.add(route,target=curve.top_left)curved = curve.add(text("Text follows a curved path",class="curved",path=text_path(route,align="center")),target=curve.top_left)art.add(curve,anchor=top_center,target=plate.top_center,offset=(0mm,31mm))wave = art.add(text("Wave and glow",class="wave"),target=plate.bottom_left,anchor=bottom_left,offset=(12mm,-25mm))stamp = art.add(image(src="../effects/alpha-ring.png",class="stamp"),size=(20mm,20mm),                target=plate.bottom_right,anchor=bottom_right,offset=(-10mm,-15mm))art.add(text("Glyph paint / outline / extrusion / alpha shadows",class="poster-note"),         target=plate.bottom_left,anchor=bottom_left,offset=(8mm,-10mm))poster = page.add(art,target=heading.bottom_left,offset=(0mm,12mm))page.add(text("Child motion and parent perspective compose without changing layout.",class="caption"),          target=poster.bottom_left,offset=(0mm,7mm)) entrance = page.step(name="Glyphs and curved path",start="after-previous",hold=300ms)entrance.animate(hero,class="animate__animated animate__fadeInUp",duration=800ms)entrance.animate(trace,name="laymesh-draw",duration=1200ms,fill="both")entrance.animate(curved,class="animate__animated animate__fadeIn",duration=600ms,start="after-previous",delay=200ms)details = page.step(name="Independent child animations",start="after-previous",hold=300ms)details.animate(wave,class="wave-motion")details.animate(stamp,class="animate__animated animate__flipInY",duration=1200ms)inspect = page.step(name="Whole poster in perspective",start="after-previous",hold=600ms)inspect.animate(poster,class="poster-motion")

Preview

Background
Preparing animation…
Art Direction
Preparing preview…
Total —
Details

Not run yet

Measured in this browser; excludes debounce.

Edits stay on this page
Dependencies
  • examples/animation/art-direction.lay
  • examples/animation/art-direction.lcss
  • examples/effects/alpha-ring.png

.hero combines glyph gradient, white outline, two-dimensional vector extrusion and an existing effects shadow. .curved uses CSS text shadow, .wave uses wave warp and glow, and .stamp uses an alpha-based drop-shadow. The plate's box shadow follows a different outline. Each retains the blur semantics explained in Shadows and effects.

The poster follows the page heading; its caption follows bottom_left, and the stamp aligns inside the plate's bottom_right. The curve stays in .lay. Path and path text share a local origin, and their group aligns with the plate. Control points describe geometry rather than each object's page placement. A draw action progressively shows the stroke. The three steps are:

  1. Title entrance and stroke drawing run concurrently; curved text appears 0.2s after drawing ends.
  2. Wave text moves vertically for two alternating iterations; the transparent image performs flipInY concurrently.
  3. The placed poster group rotates in perspective, carrying every child and effect.

Total time is 7.6s, including holds. float-wave occupies 2.4s and inspect-poster occupies 2s. Glyph warp belongs to static appearance; playback transform moves the result without reshaping text. The last keyframe returns to zero rotation. Exit or Static restores the original design.

Layout source · Project theme · Transparent image

complex-dashboard#

Organize a complex animation with loops#

This project uses the content counts of 09-motion-3d from the existing stress-scene recipe, rewritten as a maintainable Lay program. Component functions define structure; loops create objects; lists retain instances; anchors connect neighbours. Samples live separately in dashboard-data.json. These deterministic synthetic signals are illustrative data, not experimental results.

Full source
complex-dashboard.lay
# Layout uses components, loops and anchors. Plot data lives in its own file.page = canvas(size=(320mm,180mm), stylesheet="dashboard-theme.lcss", background="#f4f6fa")data = dict(src="dashboard-data.json")colors = ["#2975b9","#d88735","#318b7d","#8867b1"]equations = [  r"\int_0^\infty e^{-x^2}\,dx=\frac{\sqrt{\pi}}{2}",  r"E=\sum_{i=1}^{N}\frac{1}{2}m_i v_i^2",  r"\frac{\partial u}{\partial t}=\alpha\nabla^2 u",  r"\mathbf{A}=\begin{pmatrix}a&b\\c&d\end{pmatrix}",  r"f(x)=\frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2\sigma^2}}",  r"\hat{f}(\omega)=\int_{-\infty}^{\infty}f(t)e^{-i\omega t}\,dt",  r"\Delta G=\Delta H-T\Delta S",  r"\lim_{n\to\infty}\left(1+\frac{1}{n}\right)^n=e"] # Lay supports arithmetic and loops; cycle a palette without unrolling items.function cycle_index(index,count) {  while index >= count { index = index - count }  return index} # Seed the first item; anchor others to a neighbour or the previous row.function in_grid(material,items,columns,origin,inset,gap,opacity=1) {  count = len(items)  if count == 0 {    return page.add(material,target=origin,offset=inset,opacity=opacity)  }  if cycle_index(count,columns) == 0 {    return page.add(material,target=items[count-columns].bottom_left,offset=(0mm,gap[1]),opacity=opacity)  }  return page.add(material,target=items[count-1].top_right,offset=(gap[0],0mm),opacity=opacity)} function motif(index,size) {  tile = group()  plate = tile.add(rect(size=size,class="motif-plate"))  tile.add(ellipse(size=(size[0]/2,size[1]/2),class="motif-ring",border_color=colors[cycle_index(index,4)]),           anchor=center,target=plate.center)  tile.add(line(length=size[0]*0.8,class="motif-stroke"),anchor=center,target=plate.center,rotation=18deg)  return tile}motifs = []motif_size = (310mm/32-1mm,145mm/8-1mm)for i in range(256) {  item = in_grid(motif(i,motif_size),motifs,32,page.top_left,(5mm,25mm),(1mm,1mm),opacity=0.6)  motifs = append(motifs,item)} title = page.add(text("Complex dashboard / 12 charts + 24 equations",class="heading"),                 target=page.top_left,offset=(7mm,5mm))note = page.add(text("256 patterns | 12 charts | 24 equations | 3d",class="caption"),                target=title.bottom_left,offset=(0mm,4mm)) chart_size = (304mm/4-3mm,90mm/3-3mm)function chart(index) {  card = group(class="chart-card")  plate = card.add(rect(size=chart_size,class="chart-plate"))  kind = "Signal"  if cycle_index(index,3) == 2 { kind = "Heat map" }  card.add(text("Panel "+str(index+1)+" / "+kind,class="panel-label"),           target=plate.top_left,offset=(2mm,1mm))  q = plot(size=(chart_size[0]-3mm,chart_size[1]-5mm),           plot_area=box(offset=(7mm,1mm),size=(chart_size[0]-12mm,chart_size[1]-12mm)),           frame=box,style=plot_style(font_family="DejaVu Sans",font_size=4pt,line_width=0.18mm),           x=axis(range=(0,10),ticks=[0,5,10]),y=axis(range=(-1.5,1.5),ticks=[-1,0,1]))  values = data["panels"][index]  if cycle_index(index,3) == 2 {    q.heatmap(z=values["z"],extent=(0,10,-1.5,1.5),origin=lower,cmap="viridis")  } else {    for k,ys in enumerate(values["series"]) {      q.line(x=data["x"],y=ys,color=colors[k])    }    q.scatter(x=data["scatter_x"],y=values["scatter_y"],color="#20354b",marker_size=0.45mm)  }  card.add(q,target=plate.top_left,offset=(0mm,4mm))  return card}charts = []for i in range(len(data["panels"])) {  item = in_grid(chart(i),charts,4,page.top_left,(8mm,27mm),(3mm,3mm))  charts = append(charts,item)} formula_size = (304mm/6-2mm,52mm/4-2mm)function equation_card(source) {  card = group(class="formula-card")  plate = card.add(rect(size=formula_size,class="formula-plate"))  card.add(formula(source=source,class="equation"),anchor=center,target=plate.center)  return card}formulas = []for i in range(24) {  item = in_grid(equation_card(equations[cycle_index(i,len(equations))]),formulas,6,                 charts[len(charts)-4].bottom_left,(0mm,8mm),(2mm,2mm))  formulas = append(formulas,item)}strokes = []for i in range(12) {  item = in_grid(line(length=20mm,line_color=colors[cycle_index(i,4)],line_width=0.22mm),                 strokes,12,formulas[len(formulas)-6].bottom_left,(0mm,4mm),(5mm,0mm))  strokes = append(strokes,item)} # Lists keep the placed instances available for a second pass of animation.scene = page.step(name="Complex scene",start="after-previous",duration=12s,hold=0s)scene.animate(title,name="title-motion",duration=3s,iterations="infinite",easing="linear",fill="both")for i,item in enumerate(charts) {  scene.animate(item,name="panel-flip",duration=3s,delay=-i*71ms,                iterations="infinite",easing="ease-in-out",fill="both")}for i,item in enumerate(formulas) {  scene.animate(item,name="panel-flip",duration=3s,delay=-(i+len(charts))*71ms,                iterations="infinite",easing="ease-in-out",fill="both")}for i in range(0,len(motifs),4) {  scene.animate(motifs[i],name="motif-motion",duration=4s,delay=-i*13ms,                iterations="infinite",easing="linear",fill="both")}for i,item in enumerate(strokes) {  scene.animate(item,name="laymesh-draw",duration=2s,delay=-i*90ms,                iterations="infinite",direction="alternate",easing="linear",fill="both")}

Preview

Background
Preparing animation…
Complex Dashboard
Preparing preview…
Total —
Details

Not run yet

Measured in this browser; excludes debounce.

Edits stay on this page
Dependencies
  • examples/animation/complex-dashboard.lay
  • examples/animation/dashboard-data.json
  • examples/animation/dashboard-theme.lcss
Content Composition
256 vector motifs Gradient plate, ellipse and crossed stroke; every fourth motif rotates
12 plots Eight three-curve/scatter plots and four heatmaps; translucent card groups with shadows/glow
24 equations Nested formula cards with shadows, projected together with each card
12 open strokes Alternating draw loops
Title, plots and equations Concurrent actions with negative delays to vary loop phases

These counts describe input content, not lowered paths or measured frame rates. An explicit duration=12s bounds the step, allowing infinite loops to play, seek and export without changing their CSS iteration counts. This page has one step; Previous returns to its start. Use the first two projects to practise multiple steps.

Read the source in three layers:

  1. motif(), chart() and equation_card() define reusable structures. The theme stores repeated appearance and keyframes.
  2. in_grid() seeds only the first item. Each neighbour connects to the preceding item's top_right; a new row connects to the previous row's bottom_left. Equations follow the final chart row, and strokes follow the final equation row. gap controls spacing.
  3. Creation loops collect placed instances. Animation loops traverse those lists, calculating negative delays from indices. range(0,len(motifs),4) selects every fourth motif for rotation.

cycle_index() uses a loop to cycle palettes and equations; current Lay has no % operator. Curves and heatmap matrices load from JSON, whose editor tab is directly editable. The Node maintenance script recomputes synthetic samples only; it does not generate or overwrite .lay or .lcss. Existing data ships with the project, so compilation and playback need no Node step.

sh
laymesh validate examples/animation/complex-dashboard.lay# Only needed when updating the synthetic data recipe:node scripts/build-dashboard-data.mjs

This advanced stress scene puts more load on a device than the first two projects. Fit shows the whole layout; expand the workspace for plot/equation detail. Measure performance on the actual device; see playback implementation and verification.

Complete layout · Project theme · Sample data · Data maintenance

Save, export and practise#

Keep the theme and relative resources with the layout. The engine provides the three offline libraries, so projects need no copied upstream CSS. Static export shows the complete design; MP4/GIF uses the same source's continuous timeline.

sh
laymesh validate examples/animation/styled-cards.laylaymesh render examples/animation/styled-cards.lay -o cards.pdf --dpi 150laymesh animate examples/animation/styled-cards.lay -o cards.mp4 --width 960 --fps 20laymesh render examples/animation/art-direction.lay -o poster.png --time 4 --width 960laymesh animate examples/animation/complex-dashboard.lay -o dashboard.mp4 --width 960 --fps 10

Change one factor at a time: blur from 2mm to 1mm, then card delay, then keyframe angles. Compare static layout, time snapshots and actual playback. Address import warnings, missing animation and effect overflow with style troubleshooting and animation troubleshooting.