@istmx/skills 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/README.md +38 -20
  2. package/bin/cli.js +50 -24
  3. package/istm-animate/SKILL.md +31 -26
  4. package/istm-animate/core/motion-principles/SKILL.md +284 -0
  5. package/istm-animate/core/motion-principles/references/designers.md +127 -0
  6. package/istm-animate/core/motion-principles/references/easing-guide.md +231 -0
  7. package/istm-animate/core/motion-principles/references/enter-exit-recipes.md +466 -0
  8. package/istm-animate/frameworks/canvas-generative/SKILL.md +325 -0
  9. package/istm-animate/frameworks/canvas-generative/references/algorithms.md +925 -0
  10. package/istm-animate/frameworks/css-native/SKILL.md +319 -0
  11. package/istm-animate/frameworks/css-native/references/modern-css.md +465 -0
  12. package/istm-animate/frameworks/framer-motion/SKILL.md +187 -0
  13. package/istm-animate/frameworks/framer-motion/references/api.md +312 -0
  14. package/istm-animate/frameworks/gsap/SKILL.md +188 -0
  15. package/istm-animate/frameworks/gsap/references/core.md +218 -0
  16. package/istm-animate/frameworks/gsap/references/plugins.md +371 -0
  17. package/istm-animate/frameworks/gsap/references/scrolltrigger.md +325 -0
  18. package/istm-animate/frameworks/gsap/references/timeline.md +218 -0
  19. package/istm-animate/frameworks/threejs-r3f/SKILL.md +243 -0
  20. package/istm-animate/frameworks/threejs-r3f/references/scene-setup.md +392 -0
  21. package/istm-animate/frameworks/threejs-r3f/references/shaders.md +446 -0
  22. package/istm-animate/mobile/android/compose-graphics/SKILL.md +503 -0
  23. package/istm-animate/mobile/android/compose-graphics/references/agsl-recipes.md +356 -0
  24. package/istm-animate/mobile/android/compose-graphics/references/canvas-generative.md +282 -0
  25. package/istm-animate/mobile/android/compose-graphics/references/m3-expressive-deep.md +303 -0
  26. package/istm-animate/mobile/android/compose-motion/SKILL.md +359 -0
  27. package/istm-animate/mobile/android/compose-motion/references/gestures-compose.md +273 -0
  28. package/istm-animate/mobile/android/compose-motion/references/recomposition-and-anim.md +196 -0
  29. package/istm-animate/mobile/android/compose-motion/references/shared-transitions.md +281 -0
  30. package/istm-animate/mobile/android/compose-multiplatform/SKILL.md +311 -0
  31. package/istm-animate/mobile/android/compose-multiplatform/references/cmp-interop.md +288 -0
  32. package/istm-animate/mobile/android/compose-multiplatform/references/cmp-platform-quirks.md +156 -0
  33. package/istm-animate/mobile/apple/swiftui-graphics/SKILL.md +408 -0
  34. package/istm-animate/mobile/apple/swiftui-graphics/references/canvas-swiftui.md +239 -0
  35. package/istm-animate/mobile/apple/swiftui-graphics/references/liquid-glass-deep.md +252 -0
  36. package/istm-animate/mobile/apple/swiftui-graphics/references/metal-recipes.md +382 -0
  37. package/istm-animate/mobile/apple/swiftui-motion/SKILL.md +379 -0
  38. package/istm-animate/mobile/apple/swiftui-motion/references/gestures-swiftui.md +336 -0
  39. package/istm-animate/mobile/apple/swiftui-motion/references/phase-keyframe-deep.md +231 -0
  40. package/istm-animate/mobile/apple/swiftui-motion/references/springs-cheatsheet.md +129 -0
  41. package/istm-animate/references/animate.md +199 -0
  42. package/istm-animate/references/audit.md +115 -0
  43. package/istm-animate/references/design-engineering.md +674 -0
  44. package/istm-animate/references/improve.md +101 -0
  45. package/istm-animate/references/opportunities.md +132 -0
  46. package/istm-animate/references/plan-template.md +73 -0
  47. package/istm-animate/references/recipes.md +324 -0
  48. package/istm-animate/references/review.md +112 -0
  49. package/istm-animate/references/standards.md +187 -0
  50. package/istm-animate/references/vocabulary.md +173 -0
  51. package/istm-awwward-designer/SKILL.md +29 -17
  52. package/istm-design/SKILL.md +31 -59
  53. package/istm-design/core/design-audit/SKILL.md +248 -0
  54. package/istm-design/core/desktop-principles/SKILL.md +363 -0
  55. package/istm-design/core/desktop-principles/references/keyboard-patterns.md +137 -0
  56. package/istm-design/core/desktop-principles/references/multi-window.md +105 -0
  57. package/istm-design/core/mobile-principles/SKILL.md +289 -0
  58. package/istm-design/core/mobile-principles/references/accessibility-mobile.md +175 -0
  59. package/istm-design/core/mobile-principles/references/gestures-deep.md +220 -0
  60. package/istm-design/core/ui-ux-pro-max/SKILL.md +392 -0
  61. package/istm-design/core/ui-ux-pro-max/UPSTREAM.md +23 -0
  62. package/istm-design/core/ui-ux-pro-max/data/app-interface.csv +31 -0
  63. package/istm-design/core/ui-ux-pro-max/data/charts.csv +26 -0
  64. package/istm-design/core/ui-ux-pro-max/data/colors.csv +193 -0
  65. package/istm-design/core/ui-ux-pro-max/data/google-fonts.csv +1924 -0
  66. package/istm-design/core/ui-ux-pro-max/data/icons.csv +106 -0
  67. package/istm-design/core/ui-ux-pro-max/data/landing.csv +35 -0
  68. package/istm-design/core/ui-ux-pro-max/data/motion.csv +17 -0
  69. package/istm-design/core/ui-ux-pro-max/data/products.csv +193 -0
  70. package/istm-design/core/ui-ux-pro-max/data/react-performance.csv +45 -0
  71. package/istm-design/core/ui-ux-pro-max/data/stacks/angular.csv +51 -0
  72. package/istm-design/core/ui-ux-pro-max/data/stacks/astro.csv +54 -0
  73. package/istm-design/core/ui-ux-pro-max/data/stacks/avalonia.csv +57 -0
  74. package/istm-design/core/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  75. package/istm-design/core/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  76. package/istm-design/core/ui-ux-pro-max/data/stacks/javafx.csv +76 -0
  77. package/istm-design/core/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
  78. package/istm-design/core/ui-ux-pro-max/data/stacks/laravel.csv +51 -0
  79. package/istm-design/core/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  80. package/istm-design/core/ui-ux-pro-max/data/stacks/nuxt-ui.csv +71 -0
  81. package/istm-design/core/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  82. package/istm-design/core/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  83. package/istm-design/core/ui-ux-pro-max/data/stacks/react.csv +54 -0
  84. package/istm-design/core/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  85. package/istm-design/core/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  86. package/istm-design/core/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  87. package/istm-design/core/ui-ux-pro-max/data/stacks/threejs.csv +54 -0
  88. package/istm-design/core/ui-ux-pro-max/data/stacks/uno.csv +60 -0
  89. package/istm-design/core/ui-ux-pro-max/data/stacks/uwp.csv +56 -0
  90. package/istm-design/core/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  91. package/istm-design/core/ui-ux-pro-max/data/stacks/winui.csv +60 -0
  92. package/istm-design/core/ui-ux-pro-max/data/stacks/wpf.csv +57 -0
  93. package/istm-design/core/ui-ux-pro-max/data/styles.csv +85 -0
  94. package/istm-design/core/ui-ux-pro-max/data/typography.csv +75 -0
  95. package/istm-design/core/ui-ux-pro-max/data/ui-reasoning.csv +162 -0
  96. package/istm-design/core/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  97. package/istm-design/core/ui-ux-pro-max/references/pro-rules.md +109 -0
  98. package/istm-design/core/ui-ux-pro-max/references/quick-reference.md +240 -0
  99. package/istm-design/core/ui-ux-pro-max/scripts/core.py +464 -0
  100. package/istm-design/core/ui-ux-pro-max/scripts/design_system.py +1371 -0
  101. package/istm-design/core/ui-ux-pro-max/scripts/search.py +162 -0
  102. package/istm-design/core/ui-ux-pro-max/scripts/tests/test_core.py +134 -0
  103. package/istm-design/core/ui-ux-pro-max/scripts/validate_data.py +114 -0
  104. package/istm-design/references/apple-design.md +282 -0
  105. package/istm-design/references/generation-guide.md +209 -0
  106. package/istm-design/references/pick-ui-library.md +77 -0
  107. package/istm-design/references/picker.md +197 -0
  108. package/istm-design/references/prototype.md +90 -0
  109. package/istm-design/references/schema.md +366 -0
  110. package/package.json +1 -1
  111. package/RELEASE_v1.2.0.md +0 -40
@@ -0,0 +1,503 @@
1
+ ---
2
+ name: compose-graphics
3
+ description: "Advanced Compose visuals - Material 3 Expressive motion physics, AGSL shaders (Android 13+), Canvas/DrawScope generative, graphicsLayer effects."
4
+ ---
5
+
6
+ # Compose Graphics
7
+
8
+ > Advanced Compose visuals: M3 Expressive motion physics, AGSL shaders (Android 13+), Canvas / DrawScope, graphicsLayer effects.
9
+ > Loaded for advanced thesis (shader, expressive, M3 Expressive, AGSL, Canvas, holographic).
10
+ > Foundation: `../compose-motion/SKILL.md` covers basics. Concise rules here. Deep-dive in `references/`.
11
+
12
+ ---
13
+
14
+ ## Decision Tree: Which API for Which Need
15
+
16
+ | Need | API |
17
+ |---|---|
18
+ | Spring physics with bounce / overshoot | `MotionScheme.expressive()` (M3 Expressive) |
19
+ | Pixel-level shader | `RuntimeShader` + `Modifier.graphicsLayer { renderEffect = ... }` (Android 13+) |
20
+ | Generative drawing (paths, particles, fractals) | `Canvas { drawScope -> ... }` |
21
+ | GPU effects (blur, shadows, color filters) | `Modifier.graphicsLayer { renderEffect = ... }` or `Modifier.blur(...)` |
22
+ | Adaptive system materials (Material You glassmorphism) | `Modifier.background(MaterialTheme.colorScheme.surfaceContainerHighest)` |
23
+ | Liquid glass on Android | AGSL shader recipe (no native API like iOS yet) |
24
+
25
+ ---
26
+
27
+ ## Domain 1: Material 3 Expressive
28
+
29
+ ### What It Is
30
+
31
+ The 2025 Material 3 evolution introduces spring-based motion physics replacing fixed-duration tweens. New shape morphing API via `androidx.graphics.shapes`. New `MotionScheme` selectable on the theme. Aimed at hero moments, key interactions, brand-defining UI.
32
+
33
+ ### MotionScheme
34
+
35
+ | Scheme | Personality | Use For |
36
+ |---|---|---|
37
+ | `MotionScheme.standard()` | Calmer, less overshoot | Default for chrome, lists, navigation |
38
+ | `MotionScheme.expressive()` | More overshoot, longer settle | Hero reveals, FABs, primary CTAs |
39
+
40
+ Apply on the theme:
41
+
42
+ ```kotlin
43
+ MaterialTheme(motionScheme = MotionScheme.expressive()) {
44
+ // children read tokens via MaterialTheme.motionScheme.*
45
+ }
46
+ ```
47
+
48
+ Tokens exposed:
49
+
50
+ | Token | Domain | Speed |
51
+ |---|---|---|
52
+ | `fastSpatialSpec()` | Position / size | < 200ms |
53
+ | `defaultSpatialSpec()` | Position / size | ~ 350ms |
54
+ | `slowSpatialSpec()` | Position / size | ~ 600ms |
55
+ | `fastEffectsSpec()` | Opacity / color | < 150ms |
56
+ | `defaultEffectsSpec()` | Opacity / color | ~ 250ms |
57
+ | `slowEffectsSpec()` | Opacity / color | ~ 400ms |
58
+
59
+ > **Spatial vs Effects:** spatial = anything physical (height, offset, scale). Effects = visual properties without inertia (alpha, color, elevation). Springs feel natural for spatial; tweens feel right for effects. The tokens encode this for you.
60
+
61
+ ### Hero Card Expand (Expressive Springs)
62
+
63
+ ```kotlin
64
+ @Composable
65
+ fun ExpressiveHero() {
66
+ var expanded by remember { mutableStateOf(false) }
67
+ MaterialTheme(motionScheme = MotionScheme.expressive()) {
68
+ val transition = updateTransition(targetState = expanded, label = "expand")
69
+ val height by transition.animateDp(
70
+ transitionSpec = { MaterialTheme.motionScheme.slowSpatialSpec() },
71
+ label = "height"
72
+ ) { if (it) 400.dp else 100.dp }
73
+ val alpha by transition.animateFloat(
74
+ transitionSpec = { MaterialTheme.motionScheme.defaultEffectsSpec() },
75
+ label = "alpha"
76
+ ) { if (it) 1f else 0f }
77
+
78
+ Card(
79
+ modifier = Modifier
80
+ .fillMaxWidth()
81
+ .height(height)
82
+ .clickable { expanded = !expanded }
83
+ ) {
84
+ Box(modifier = Modifier.alpha(alpha)) {
85
+ Text("Detail content", modifier = Modifier.padding(24.dp))
86
+ }
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ ### Spring Tuning Recipes
93
+
94
+ | Mood | Spec |
95
+ |---|---|
96
+ | Hero reveal | `spring(stiffness = Spring.StiffnessLow, dampingRatio = Spring.DampingRatioMediumBouncy)` |
97
+ | Snappy expressive | `spring(stiffness = Spring.StiffnessMediumLow, dampingRatio = 0.7f)` |
98
+ | Calm spatial | `MaterialTheme.motionScheme.defaultSpatialSpec()` (use the token) |
99
+ | Critical (no overshoot) | `spring(stiffness = Spring.StiffnessHigh, dampingRatio = 1f)` |
100
+
101
+ ### Shape Morphing (M3 Expressive 1.3+)
102
+
103
+ `androidx.graphics.shapes` ships predefined morphable shapes (`MaterialShapes.Circle`, `Pentagon`, `Cookie4Sided`, `Sunny`, `Heart`, etc.) and a `Morph(start, end)` interpolator.
104
+
105
+ ```kotlin
106
+ val morph = remember { Morph(MaterialShapes.Circle, MaterialShapes.Cookie4Sided) }
107
+ val progress by animateFloatAsState(
108
+ targetValue = if (active) 1f else 0f,
109
+ animationSpec = MaterialTheme.motionScheme.slowSpatialSpec(),
110
+ label = "morph"
111
+ )
112
+ Box(
113
+ modifier = Modifier
114
+ .size(96.dp)
115
+ .clip(GenericShape { size, _ ->
116
+ addPath(
117
+ morph.toPath(progress).asAndroidPath().asComposePath()
118
+ )
119
+ })
120
+ .background(MaterialTheme.colorScheme.primary)
121
+ )
122
+ ```
123
+
124
+ ### When to Use Expressive vs Standard
125
+
126
+ - **Expressive:** hero moments, key interactions, FABs, primary CTAs. 1-3% of UI.
127
+ - **Standard:** default for the rest of the app. Mixing too much Expressive feels chaotic - every element fighting for attention.
128
+
129
+ ---
130
+
131
+ ## Domain 2: AGSL Shaders (Android 13+)
132
+
133
+ ### What It Is
134
+
135
+ AGSL is Android's shader language. Similar to GLSL with simplifications (`half4` instead of `vec4`, restricted feature set, sandbox-safe). `RuntimeShader` compiles your AGSL source. Bind to a Compose modifier via `Modifier.graphicsLayer { renderEffect = ... }`.
136
+
137
+ ### Setup
138
+
139
+ ```kotlin
140
+ @Composable
141
+ fun ShaderEffect(content: @Composable () -> Unit) {
142
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
143
+ // Android 12 and below: skip the shader, render content as-is.
144
+ content()
145
+ return
146
+ }
147
+ val shader = remember { RuntimeShader(AGSL_SOURCE) }
148
+ val time by produceState(0f) {
149
+ while (true) {
150
+ withFrameMillis { ms ->
151
+ value = ms / 1000f
152
+ }
153
+ }
154
+ }
155
+ Box(
156
+ modifier = Modifier
157
+ .onSizeChanged {
158
+ shader.setFloatUniform("resolution", it.width.toFloat(), it.height.toFloat())
159
+ }
160
+ .graphicsLayer {
161
+ shader.setFloatUniform("time", time)
162
+ renderEffect = RenderEffect
163
+ .createRuntimeShaderEffect(shader, "image")
164
+ .asComposeRenderEffect()
165
+ }
166
+ ) { content() }
167
+ }
168
+ ```
169
+
170
+ > **Always gate on `Build.VERSION.SDK_INT >= 33`.** Pre-Android 13 fallback: render the content unmodified, or use `Modifier.blur()` / a static gradient overlay.
171
+
172
+ ### Recipe: Touch Ripple
173
+
174
+ AGSL source:
175
+
176
+ ```glsl
177
+ // ripple.agsl
178
+ uniform float2 resolution;
179
+ uniform float2 origin;
180
+ uniform float time;
181
+ uniform shader image;
182
+
183
+ half4 main(float2 fragCoord) {
184
+ float2 toOrigin = fragCoord - origin;
185
+ float dist = length(toOrigin);
186
+ float wave = sin(dist * 0.05 - time * 8.0) * 0.05;
187
+ float falloff = 1.0 / max(dist * 0.01, 1.0);
188
+ float2 dir = toOrigin / max(dist, 0.0001);
189
+ float2 displaced = fragCoord + dir * wave * falloff * 50.0;
190
+ return image.eval(displaced);
191
+ }
192
+ ```
193
+
194
+ Compose binding (state-driven `time`, animated via `LaunchedEffect`):
195
+
196
+ ```kotlin
197
+ @Composable
198
+ fun RippleSurface(content: @Composable BoxScope.() -> Unit) {
199
+ if (Build.VERSION.SDK_INT < 33) { Box { content() }; return }
200
+ val shader = remember { RuntimeShader(RIPPLE_AGSL) }
201
+ var origin by remember { mutableStateOf(Offset.Zero) }
202
+ var startMs by remember { mutableStateOf<Long?>(null) }
203
+ val time by produceState(0f, startMs) {
204
+ if (startMs == null) { value = 0f; return@produceState }
205
+ val begin = startMs!!
206
+ while (true) {
207
+ withFrameMillis { now ->
208
+ value = (now - begin) / 1000f
209
+ }
210
+ }
211
+ }
212
+ Box(
213
+ modifier = Modifier
214
+ .onSizeChanged {
215
+ shader.setFloatUniform("resolution", it.width.toFloat(), it.height.toFloat())
216
+ }
217
+ .pointerInput(Unit) {
218
+ detectTapGestures { tap ->
219
+ origin = tap
220
+ startMs = System.currentTimeMillis()
221
+ }
222
+ }
223
+ .graphicsLayer {
224
+ shader.setFloatUniform("origin", origin.x, origin.y)
225
+ shader.setFloatUniform("time", time)
226
+ renderEffect = RenderEffect
227
+ .createRuntimeShaderEffect(shader, "image")
228
+ .asComposeRenderEffect()
229
+ },
230
+ content = content
231
+ )
232
+ }
233
+ ```
234
+
235
+ ### Recipe: Holographic Gradient
236
+
237
+ ```glsl
238
+ uniform float time;
239
+ uniform shader image;
240
+
241
+ half4 main(float2 fragCoord) {
242
+ half4 color = image.eval(fragCoord);
243
+ float n = fragCoord.x * 0.01 + fragCoord.y * 0.005 + time * 0.3;
244
+ half3 rainbow = half3(
245
+ sin(n * 2.0) * 0.5 + 0.5,
246
+ sin(n * 2.0 + 2.094) * 0.5 + 0.5,
247
+ sin(n * 2.0 + 4.188) * 0.5 + 0.5
248
+ );
249
+ half luma = dot(color.rgb, half3(0.299, 0.587, 0.114));
250
+ return half4(mix(color.rgb, rainbow * luma * 2.0, 0.5), color.a);
251
+ }
252
+ ```
253
+
254
+ Multiplies the underlying view's luminance by a phase-shifted RGB sine wave - shimmer over text or icons. `time` animates the wave drift.
255
+
256
+ ### Recipe: Liquid Glass / Glassmorphism
257
+
258
+ Android lacks a native iOS-26-style `glassEffect`. Compose this with blur + chromatic aberration + soft edge tint:
259
+
260
+ ```glsl
261
+ uniform float2 resolution;
262
+ uniform shader image;
263
+
264
+ half4 main(float2 fragCoord) {
265
+ float2 uv = fragCoord / resolution;
266
+ // Chromatic aberration: sample R, G, B at slightly different offsets
267
+ float2 ca = (uv - 0.5) * 0.004;
268
+ half r = image.eval(fragCoord + ca * resolution).r;
269
+ half g = image.eval(fragCoord).g;
270
+ half b = image.eval(fragCoord - ca * resolution).b;
271
+ half4 base = half4(r, g, b, 1.0);
272
+ // Soft edge tint: brighten near borders for that frosted look
273
+ float edge = smoothstep(0.45, 0.5, max(abs(uv.x - 0.5), abs(uv.y - 0.5)));
274
+ half3 tinted = base.rgb + half3(edge * 0.08);
275
+ return half4(tinted, 0.85);
276
+ }
277
+ ```
278
+
279
+ Pair with `Modifier.blur(20.dp, BlurredEdgeTreatment.Unbounded)` upstream for the actual blur (cheaper than computing it in AGSL).
280
+
281
+ ### Performance Notes
282
+
283
+ - Each `RuntimeShader` is a render pass. Compounds at 60fps - benchmark via Macrobenchmark.
284
+ - `image.eval(coord)` samples the underlying view as a texture. Heavy if the view is complex (long lists, nested layouts). Cache static parts in a parent that doesn't recompose.
285
+ - On Android 12 and below: graceful fallback (static image, no shader). Never hard-crash.
286
+ - Prefer 1 well-crafted shader over chaining 4 shaders in series.
287
+
288
+ ---
289
+
290
+ ## Domain 3: Canvas / DrawScope
291
+
292
+ ### Canvas API
293
+
294
+ ```kotlin
295
+ Canvas(modifier = Modifier.size(200.dp)) {
296
+ // 'this' is DrawScope - size, drawCircle, drawPath, drawRect...
297
+ drawCircle(Color.Blue, radius = size.minDimension / 2)
298
+ drawPath(myPath, color = Color.White, style = Stroke(width = 4.dp.toPx()))
299
+ }
300
+ ```
301
+
302
+ | DrawScope method | Use |
303
+ |---|---|
304
+ | `drawCircle` | Filled or stroked circles |
305
+ | `drawRect` | Rectangles, optionally with gradient brush |
306
+ | `drawPath` | Arbitrary path with `Stroke` or `Fill` |
307
+ | `drawArc` | Slice of an oval - useful for progress arcs |
308
+ | `drawLine` | Straight segment between two `Offset` |
309
+ | `drawText` | Text via `TextMeasurer` (preferred) or `drawIntoCanvas { it.nativeCanvas.drawText(...) }` |
310
+ | `drawIntoCanvas { }` | Escape hatch - access raw `android.graphics.Canvas` |
311
+
312
+ ### Recipe: Animated Sine Wave
313
+
314
+ ```kotlin
315
+ @Composable
316
+ fun AnimatedWave() {
317
+ val infinite = rememberInfiniteTransition(label = "wave")
318
+ val phase by infinite.animateFloat(
319
+ initialValue = 0f,
320
+ targetValue = 2 * PI.toFloat(),
321
+ animationSpec = infiniteRepeatable(
322
+ animation = tween(3000, easing = LinearEasing)
323
+ ),
324
+ label = "phase"
325
+ )
326
+ Canvas(modifier = Modifier.fillMaxWidth().height(80.dp)) {
327
+ val path = Path()
328
+ var x = 0
329
+ while (x <= size.width.toInt()) {
330
+ val y = size.height / 2 + sin(x * 0.05f + phase) * 20f
331
+ if (x == 0) path.moveTo(x.toFloat(), y) else path.lineTo(x.toFloat(), y)
332
+ x += 2
333
+ }
334
+ drawPath(path, color = Color.Blue, style = Stroke(width = 2.dp.toPx()))
335
+ }
336
+ }
337
+ ```
338
+
339
+ ### Recipe: Particle System (50 Particles)
340
+
341
+ ```kotlin
342
+ data class Particle(var x: Float, var y: Float, var vx: Float, var vy: Float, var life: Float)
343
+
344
+ @Composable
345
+ fun ParticleField() {
346
+ val particles = remember {
347
+ mutableStateListOf<Particle>().apply {
348
+ repeat(50) {
349
+ add(Particle(
350
+ x = Random.nextFloat() * 1000f,
351
+ y = Random.nextFloat() * 1000f,
352
+ vx = (Random.nextFloat() - 0.5f) * 4f,
353
+ vy = (Random.nextFloat() - 0.5f) * 4f,
354
+ life = 1f
355
+ ))
356
+ }
357
+ }
358
+ }
359
+ LaunchedEffect(Unit) {
360
+ while (true) {
361
+ withFrameMillis { /* tick */ }
362
+ particles.forEachIndexed { i, p ->
363
+ p.x += p.vx
364
+ p.y += p.vy
365
+ p.life -= 0.01f
366
+ if (p.life <= 0f) {
367
+ p.x = Random.nextFloat() * 1000f
368
+ p.y = Random.nextFloat() * 1000f
369
+ p.life = 1f
370
+ }
371
+ }
372
+ }
373
+ }
374
+ Canvas(modifier = Modifier.fillMaxSize()) {
375
+ particles.forEach { p ->
376
+ drawCircle(
377
+ color = Color.White.copy(alpha = p.life),
378
+ radius = 2.dp.toPx(),
379
+ center = Offset(p.x, p.y)
380
+ )
381
+ }
382
+ }
383
+ }
384
+ ```
385
+
386
+ ### Recipe: Generative Pattern (Flow Field)
387
+
388
+ Quick mention: noise-driven particle motion. See `references/canvas-generative.md` for the full deep-dive (Perlin noise, particle pools, advection loop).
389
+
390
+ ### Performance Notes
391
+
392
+ - Canvas redraws on every state change of any state it reads. Wrap volatile state in `derivedStateOf` to gate redraws.
393
+ - `LaunchedEffect(Unit) { while(true) { withFrameMillis { ... } } }` is fine for 60fps. Avoid `delay(16)` - it drifts.
394
+ - Heavy generative work: precompute paths once in `remember`, only animate transforms via `translate { drawPath(...) }`.
395
+ - 200 simple draws per frame = OK on most devices. 2000+ starts to lag.
396
+
397
+ ---
398
+
399
+ ## Anti-Patterns
400
+
401
+ ### 1. Expressive Everywhere
402
+
403
+ ```kotlin
404
+ // BAD - every interaction overshoots, UI feels like a bouncy castle
405
+ MaterialTheme(motionScheme = MotionScheme.expressive()) {
406
+ AppRoot()
407
+ }
408
+
409
+ // GOOD - Standard for chrome, scope Expressive to hero moments
410
+ MaterialTheme(motionScheme = MotionScheme.standard()) {
411
+ NavigationScaffold {
412
+ // Hero detail screen overrides locally
413
+ MaterialTheme(motionScheme = MotionScheme.expressive()) {
414
+ HeroDetail()
415
+ }
416
+ }
417
+ }
418
+ ```
419
+
420
+ ### 2. RuntimeShader Without API Gate
421
+
422
+ ```kotlin
423
+ // BAD - crashes on Android 12 and below
424
+ val shader = remember { RuntimeShader(AGSL_SOURCE) }
425
+
426
+ // GOOD - gate on SDK level, provide fallback
427
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
428
+ ShaderEffect { content() }
429
+ } else {
430
+ Box(modifier = Modifier.background(fallbackGradient)) { content() }
431
+ }
432
+ ```
433
+
434
+ ### 3. Canvas Reading State Directly Each Frame
435
+
436
+ ```kotlin
437
+ // BAD - any state change in the parent triggers a recompose of the Canvas
438
+ Canvas(modifier = Modifier.fillMaxSize()) {
439
+ drawCircle(color = if (viewModel.isActive) Color.Red else Color.Blue, radius = 50f)
440
+ }
441
+
442
+ // GOOD - hoist the reads, derive a stable value
443
+ val color by remember { derivedStateOf { if (viewModel.isActive) Color.Red else Color.Blue } }
444
+ Canvas(modifier = Modifier.fillMaxSize()) {
445
+ drawCircle(color = color, radius = 50f)
446
+ }
447
+ ```
448
+
449
+ ### 4. Chaining 4 AGSL Shaders in Series
450
+
451
+ ```kotlin
452
+ // BAD - 4 render passes per frame, GPU melts on mid-range devices
453
+ .graphicsLayer { renderEffect = blurEffect }
454
+ .graphicsLayer { renderEffect = chromaticEffect }
455
+ .graphicsLayer { renderEffect = noiseEffect }
456
+ .graphicsLayer { renderEffect = vignetteEffect }
457
+
458
+ // GOOD - one shader doing all the math in a single pass
459
+ .graphicsLayer { renderEffect = combinedGlassEffect }
460
+ ```
461
+
462
+ ### 5. Allocating in DrawScope
463
+
464
+ ```kotlin
465
+ // BAD - new Path every frame, GC stutter
466
+ Canvas(modifier = Modifier.fillMaxSize()) {
467
+ val path = Path()
468
+ points.forEach { path.lineTo(it.x, it.y) }
469
+ drawPath(path, color = Color.Black)
470
+ }
471
+
472
+ // GOOD - reuse a remembered Path, rewind each frame
473
+ val path = remember { Path() }
474
+ Canvas(modifier = Modifier.fillMaxSize()) {
475
+ path.rewind()
476
+ points.forEach { path.lineTo(it.x, it.y) }
477
+ drawPath(path, color = Color.Black)
478
+ }
479
+ ```
480
+
481
+ ---
482
+
483
+ ## Quick Reference: Loading Sub-resources
484
+
485
+ | Need | Load |
486
+ |---|---|
487
+ | AGSL recipes (7 working shaders with binding code) | `references/agsl-recipes.md` |
488
+ | M3 Expressive choreography deep-dive | `references/m3-expressive-deep.md` |
489
+ | Generative drawing patterns (flow fields, L-systems, particles) | `references/canvas-generative.md` |
490
+ | Base animations (animateAsState, AnimatedVisibility, Transition) | `../compose-motion/SKILL.md` |
491
+ | CMP patterns (shared UI iOS / Android / Desktop) | `../compose-multiplatform/SKILL.md` |
492
+
493
+ ---
494
+
495
+ ## Sources
496
+
497
+ - [drinkthestars/shady](https://github.com/drinkthestars/shady) - AGSL shaders rendered in Compose
498
+ - [Mortd3kay/liquid-glass-android](https://github.com/Mortd3kay/liquid-glass-android)
499
+ - [JumpingKeyCaps/DynamicVisualEffectsAGSL](https://github.com/JumpingKeyCaps/DynamicVisualEffectsAGSL)
500
+ - [Material 3 Expressive blog](https://m3.material.io/blog/m3-expressive-motion-theming)
501
+ - [Material Design 3 Motion specs](https://m3.material.io/styles/motion/overview/specs)
502
+ - [Android AGSL docs](https://developer.android.com/develop/ui/views/graphics/agsl/using-agsl)
503
+ - [androidx.graphics.shapes](https://developer.android.com/jetpack/androidx/releases/graphics-shapes) - shape morphing