pixelsrc 0.2.0

Pixelsrc - GenAI-native pixel art format and compiler
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
---
phase: 19
title: Advanced Transforms & Animation Features
---

# Phase 19: Advanced Transforms & Animation Features

**Status:** In Progress

**Depends on:** Phase 18 (Sprite Transforms - core transform system required)

---

Advanced features for power users. See [personas](../personas.md) for user context.

**Detailed Specification:** [Format Spec - ATF sections](../spec/format.md#transform-operations)

**Related:**
- [Transforms]./transforms.md - Core transform system (implement first)
- [Colored Grid Display]./colored-grid-display.md - Terminal preview tools

---

## Feature Overview

| Feature | Persona | Implementation | Priority |
|---------|---------|----------------|----------|
| **Palette cycling** | Animator+ | Animation attribute | ★★★ High |
| **Color ramps** | Pixel Artist+ | Palette attribute | ★★★ High |
| **Frame tags** | Game Dev | Animation attribute | ★★★ High |
| **Atlas export** | Game Dev | CLI export format | ★★★ High |
| **Nine-slice** | Game Dev | Sprite attribute | ★★☆ Medium |
| **Dithering patterns** | Pixel Artist | Transform operation | ★★☆ Medium |
| **Hue-shifted shadows** | Pixel Artist | Palette attribute | ★★☆ Medium |
| **Sel-out (selective outline)** | Pixel Artist | Transform operation | ★★☆ Medium |
| **Blend modes** | Pixel Artist+ | Composition layer attr | ★★☆ Medium |
| **Onion skinning** | Animator | CLI preview feature | ★★☆ Medium |
| **Sub-pixel animation** | Motion Designer | Transform operation | ★☆☆ Lower |
| **Squash & stretch** | Motion Designer | Transform operation | ★☆☆ Lower |
| **Secondary motion** | Motion Designer | Animation attribute | ★☆☆ Lower |
| **Particle systems** | Motion Designer | New type | ★☆☆ Lower |
| **Parallax hints** | Game Dev | Composition layer attr | ★☆☆ Lower |
| **Hit/hurt boxes** | Game Dev | Metadata | ★☆☆ Lower |
| **Arc motion paths** | Motion Designer | Keyframe feature | ★☆☆ Lower |

---

## High Priority Features

### Palette Cycling

**Persona:** Animator, Motion Designer, Game Dev

Animate by rotating palette colors instead of changing pixels. Classic technique for water, fire, energy effects.

**Implementation:** Animation attribute (not a transform)

```json
{
  "type": "animation",
  "name": "waterfall",
  "sprite": "water_static",
  "palette_cycle": {
    "tokens": ["{water1}", "{water2}", "{water3}", "{water4}"],
    "fps": 8,
    "direction": "forward"
  }
}
```

**How it works:**
- Single sprite, no frame changes
- Colors rotate through the token list
- Frame 0: water1→#1, water2→#2, water3→#3, water4→#4
- Frame 1: water1→#2, water2→#3, water3→#4, water4→#1
- etc.

**Multiple cycles:**
```json
{
  "palette_cycle": [
    {"tokens": ["{water1}", "{water2}", "{water3}"], "fps": 8},
    {"tokens": ["{glow1}", "{glow2}"], "fps": 4}
  ]
}
```

**Why not a transform?** Palette cycling doesn't modify the grid or generate frames in the traditional sense - it modifies color mapping over time. It's fundamentally different from spatial transforms.

---

### Color Ramps

**Persona:** Pixel Artist, Motion Designer

Auto-generate palette colors along a ramp with hue shifting (shadows aren't just darker - they shift toward cool/warm).

**Implementation:** Palette attribute

```json
{
  "type": "palette",
  "name": "skin",
  "ramps": {
    "skin": {
      "base": "#E8B89D",
      "steps": 5,
      "shadow_shift": {"lightness": -15, "hue": 10, "saturation": 5},
      "highlight_shift": {"lightness": 12, "hue": -5, "saturation": -10}
    }
  }
}
```

**Generates tokens:**
- `{skin_2}` (darkest shadow)
- `{skin_1}` (shadow)
- `{skin}` (base)
- `{skin+1}` (highlight)
- `{skin+2}` (brightest highlight)

**Simpler syntax:**
```json
{
  "ramps": {
    "skin": {"base": "#E8B89D", "steps": 3}
  }
}
```
Uses sensible defaults for shift values.

**Multiple ramps:**
```json
{
  "ramps": {
    "skin": {"base": "#E8B89D", "steps": 3},
    "hair": {"base": "#4A3728", "steps": 4},
    "metal": {"base": "#8899AA", "steps": 5, "shadow_shift": {"hue": 20}}
  }
}
```

---

### Frame Tags

**Persona:** Game Developer

Mark frame ranges with semantic names for game engine integration.

**Implementation:** Animation attribute

```json
{
  "type": "animation",
  "name": "player",
  "frames": ["idle1", "idle2", "run1", "run2", "run3", "run4", "jump", "fall"],
  "fps": 10,
  "tags": {
    "idle": {"start": 0, "end": 1, "loop": true},
    "run": {"start": 2, "end": 5, "loop": true},
    "jump": {"start": 6, "end": 6, "loop": false},
    "fall": {"start": 7, "end": 7, "loop": false}
  }
}
```

**Export includes tags:**
```bash
pxl render player.pxl --format atlas --output player.json
```

```json
{
  "frames": [...],
  "tags": {
    "idle": {"from": 0, "to": 1, "loop": true},
    "run": {"from": 2, "to": 5, "loop": true}
  }
}
```

**Tag-specific FPS:**
```json
{
  "tags": {
    "idle": {"start": 0, "end": 1, "fps": 4},
    "run": {"start": 2, "end": 5, "fps": 12}
  }
}
```

---

### Atlas Export

**Persona:** Game Developer

Pack multiple sprites into a single texture with coordinate metadata. Game engines load one image instead of hundreds = faster loading.

**Implementation:** CLI export format

**Basic usage:**
```bash
pxl render game.pxl --format atlas -o game_atlas
# Outputs: game_atlas.png + game_atlas.json
```

**Output structure:**

`game_atlas.png` - Single image with all sprites packed:
```
┌────────────────────────┐
│ coin │ player │ enemy  │
├──────┴────────┼────────┤
│    tree       │ chest  │
└───────────────┴────────┘
```

`game_atlas.json` - Coordinate data:
```json
{
  "image": "game_atlas.png",
  "size": [128, 64],
  "frames": {
    "coin": {"x": 0, "y": 0, "w": 16, "h": 16},
    "player": {"x": 16, "y": 0, "w": 32, "h": 32},
    "enemy": {"x": 48, "y": 0, "w": 24, "h": 24},
    "tree": {"x": 0, "y": 32, "w": 48, "h": 32},
    "chest": {"x": 48, "y": 32, "w": 24, "h": 24}
  },
  "animations": {
    "player_walk": {
      "frames": ["player_walk_1", "player_walk_2", "player_walk_3"],
      "fps": 8,
      "tags": {
        "idle": {"from": 0, "to": 1},
        "run": {"from": 2, "to": 5}
      }
    }
  }
}
```

**Packing options:**
```bash
# Max atlas size
pxl render game.pxl --format atlas --max-size 512x512 -o atlas

# Padding between sprites (prevents bleed)
pxl render game.pxl --format atlas --padding 1 -o atlas

# Power-of-two dimensions (required by some engines)
pxl render game.pxl --format atlas --power-of-two -o atlas

# Multiple atlases if needed
pxl render game.pxl --format atlas --max-size 256x256 -o atlas
# Outputs: atlas_0.png, atlas_0.json, atlas_1.png, atlas_1.json, ...
```

**Format variants:**
```bash
# Generic JSON (default)
pxl render game.pxl --format atlas -o out

# Aseprite-compatible
pxl render game.pxl --format atlas-aseprite -o out

# Godot-compatible
pxl render game.pxl --format atlas-godot -o out

# Unity-compatible
pxl render game.pxl --format atlas-unity -o out

# libGDX-compatible
pxl render game.pxl --format atlas-libgdx -o out
```

**Selective export:**
```bash
# Only specific sprites
pxl render game.pxl --format atlas --sprites "player_*,enemy_*" -o characters

# Only animations
pxl render game.pxl --format atlas --animations-only -o anims
```

---

## Medium Priority Features

### Nine-Slice

**Persona:** Game Developer

Scalable sprites where corners stay fixed and edges/center stretch.

**Implementation:** Sprite attribute

```json
{
  "type": "sprite",
  "name": "button",
  "palette": "ui",
  "nine_slice": {
    "left": 4,
    "right": 4,
    "top": 4,
    "bottom": 4
  },
  "grid": [
    "{c}{t}{t}{t}{t}{t}{t}{c}",
    "{l}{m}{m}{m}{m}{m}{m}{r}",
    "{l}{m}{m}{m}{m}{m}{m}{r}",
    "{c}{b}{b}{b}{b}{b}{b}{c}"
  ]
}
```

**Render at size:**
```bash
pxl render button.pxl --nine-slice 64x32 -o button_wide.png
```

**In compositions:**
```json
{
  "layers": [
    {"sprite": "button", "position": [0, 0], "nine_slice_size": [100, 40]}
  ]
}
```

---

### Dithering Patterns

**Persona:** Pixel Artist

Apply dithering patterns for gradients, transparency effects, texture.

**Implementation:** Transform operation

```json
{"type": "sprite", "name": "gradient", "source": "solid", "transform": [
  {"op": "dither", "pattern": "checker", "tokens": ["{dark}", "{light}"], "threshold": 0.5}
]}
```

**Built-in patterns:**
- `checker` - Checkerboard
- `ordered-2x2` - 2x2 Bayer matrix
- `ordered-4x4` - 4x4 Bayer matrix
- `diagonal` - Diagonal lines
- `horizontal` - Horizontal lines
- `noise` - Random (seeded)

**Gradient dither:**
```json
{
  "op": "dither-gradient",
  "direction": "vertical",
  "from": "{sky_light}",
  "to": "{sky_dark}",
  "pattern": "ordered-4x4"
}
```

---

### Hue-Shifted Shadows

**Persona:** Pixel Artist

Auto-generate shadow/highlight colors with hue shifting built into palette.

**Implementation:** Palette attribute (see Color Ramps above - this is the same feature)

**Quick syntax for individual colors:**
```json
{
  "type": "palette",
  "colors": {
    "{skin}": "#E8B89D",
    "{skin_shadow}": {"from": "{skin}", "shift": {"lightness": -20, "hue": 15}},
    "{skin_highlight}": {"from": "{skin}", "shift": {"lightness": 15, "hue": -10}}
  }
}
```

---

### Selective Outline (Sel-out)

**Persona:** Pixel Artist

Outline color varies based on the adjacent fill color, creating softer edges.

**Implementation:** Transform operation

```json
{"transform": [
  {"op": "sel-out", "fallback": "{outline}"}
]}
```

**How it works:**
- Examines each outline pixel's neighboring fill pixels
- Picks a darker/shifted version of the most common neighbor
- Falls back to specified color if can't determine

**With explicit mapping:**
```json
{
  "op": "sel-out",
  "mapping": {
    "{skin}": "{skin_dark}",
    "{hair}": "{hair_dark}",
    "*": "{outline}"
  }
}
```

---

### Blend Modes

**Persona:** Pixel Artist, Motion Designer

Layer blending for compositions.

**Implementation:** Composition layer attribute

```json
{
  "type": "composition",
  "layers": [
    {"sprite": "background", "position": [0, 0]},
    {"sprite": "shadow", "position": [10, 20], "blend": "multiply", "opacity": 0.5},
    {"sprite": "glow", "position": [5, 5], "blend": "screen"},
    {"sprite": "player", "position": [16, 16]}
  ]
}
```

**Blend modes:**
- `normal` (default)
- `multiply` - Darken
- `screen` - Lighten
- `overlay` - Contrast
- `add` - Additive (glow)
- `subtract` - Subtractive

---

### Onion Skinning

**Persona:** Animator

Preview previous/next frames as transparent overlays.

**Implementation:** CLI preview feature

```bash
pxl show walk_cycle.pxl --onion 2
```

Shows current frame with 2 previous and 2 next frames as ghosts.

**Options:**
- `--onion <count>` - Number of frames before/after
- `--onion-opacity <0-1>` - Ghost opacity (default 0.3)
- `--onion-prev-color <hex>` - Tint for previous frames
- `--onion-next-color <hex>` - Tint for next frames

---

## Lower Priority Features

### Sub-pixel Animation

**Persona:** Motion Designer

Create apparent motion smaller than 1 pixel by shifting colors.

**Implementation:** Transform operation with keyframes

```json
{
  "type": "transform",
  "name": "subpixel-shift",
  "params": ["amount"],
  "keyframes": {
    "subpixel-x": {"expr": "${amount} * sin(t * 3.14159)"}
  }
}
```

**How it works:**
- `subpixel-x: 0.5` means "50% blend toward the right pixel"
- Renderer interpolates colors at boundaries
- Creates smooth apparent motion < 1px

---

### Squash & Stretch

**Persona:** Motion Designer

Deform sprites for impact and bounce.

**Implementation:** Transform operation

```json
{
  "type": "transform",
  "name": "squash",
  "params": ["amount"],
  "ops": [
    {"op": "scale", "x": "${1 + amount}", "y": "${1 - amount}"}
  ]
}
```

**With keyframes:**
```json
{
  "type": "transform",
  "name": "bounce-squash",
  "frames": 8,
  "keyframes": [
    {"frame": 0, "scale-x": 1.0, "scale-y": 1.0},
    {"frame": 3, "scale-x": 0.8, "scale-y": 1.3},
    {"frame": 5, "scale-x": 1.2, "scale-y": 0.8},
    {"frame": 8, "scale-x": 1.0, "scale-y": 1.0}
  ],
  "easing": "ease-out"
}
```

**Note:** Scaling pixel art non-uniformly requires interpolation decisions. Options:
- Nearest neighbor (blocky but crisp)
- Smooth (blurry but fluid)
- Row/column duplication (pixel-art friendly)

---

### Secondary Motion

**Persona:** Motion Designer

Child elements that follow parent with delay/dampening (hair, capes, tails).

**Implementation:** Animation attribute

```json
{
  "type": "animation",
  "name": "run_with_cape",
  "source": "run",
  "attachments": [
    {
      "sprite": "cape",
      "anchor": [8, 4],
      "follow": "parent",
      "delay": 2,
      "damping": 0.7
    }
  ]
}
```

**Parameters:**
- `anchor` - Attachment point on parent
- `delay` - Frames behind parent motion
- `damping` - How much motion is reduced (0-1)
- `spring` - Springy overshoot factor

---

### Particle Systems

**Persona:** Motion Designer

Define particle emitters for effects (sparks, dust, rain).

**Implementation:** New type

```json
{
  "type": "particle",
  "name": "sparkle",
  "sprite": "spark",
  "emitter": {
    "rate": 5,
    "lifetime": [10, 20],
    "velocity": {"x": [-2, 2], "y": [-4, -1]},
    "gravity": 0.2,
    "fade": true,
    "rotation": [0, 360]
  }
}
```

**Use in composition:**
```json
{
  "type": "composition",
  "layers": [
    {"sprite": "gem"},
    {"particle": "sparkle", "position": [8, 8]}
  ]
}
```

---

### Parallax Hints

**Persona:** Game Developer

Depth values for scroll-speed calculation in game engines.

**Implementation:** Composition layer attribute

```json
{
  "type": "composition",
  "name": "scene",
  "layers": [
    {"sprite": "sky", "position": [0, 0], "parallax": 0.1},
    {"sprite": "mountains", "position": [0, 20], "parallax": 0.3},
    {"sprite": "trees", "position": [0, 40], "parallax": 0.7},
    {"sprite": "ground", "position": [0, 56], "parallax": 1.0}
  ]
}
```

**Exported as metadata** for game engine to interpret.

---

### Hit/Hurt Boxes

**Persona:** Game Developer

Collision regions per sprite or per frame.

**Implementation:** Metadata

```json
{
  "type": "sprite",
  "name": "player_attack",
  "grid": [...],
  "metadata": {
    "origin": [16, 32],
    "boxes": {
      "hurt": {"x": 4, "y": 0, "w": 24, "h": 32},
      "hit": {"x": 20, "y": 8, "w": 20, "h": 16}
    }
  }
}
```

**Per-frame boxes in animations:**
```json
{
  "type": "animation",
  "name": "attack",
  "frames": ["f1", "f2", "f3"],
  "frame_metadata": [
    {"boxes": {"hit": null}},
    {"boxes": {"hit": {"x": 20, "y": 8, "w": 20, "h": 16}}},
    {"boxes": {"hit": {"x": 24, "y": 4, "w": 24, "h": 20}}}
  ]
}
```

---

### Arc Motion Paths

**Persona:** Motion Designer

Motion follows curved paths instead of linear interpolation.

**Implementation:** Keyframe enhancement

```json
{
  "type": "transform",
  "name": "throw-arc",
  "frames": 12,
  "keyframes": [
    {"frame": 0, "shift-x": 0, "shift-y": 0},
    {"frame": 6, "shift-x": 24, "shift-y": -16},
    {"frame": 12, "shift-x": 48, "shift-y": 0}
  ],
  "interpolation": "bezier",
  "path": "arc"
}
```

**Or explicit control points:**
```json
{
  "keyframes": [
    {"frame": 0, "position": [0, 0], "control": [8, -20]},
    {"frame": 12, "position": [48, 0], "control": [40, -20]}
  ]
}
```

---

## Implementation Notes

### What Needs New Attributes

| Feature | Where | Attribute |
|---------|-------|-----------|
| Palette cycling | Animation | `palette_cycle` |
| Color ramps | Palette | `ramps` |
| Frame tags | Animation | `tags` |
| Nine-slice | Sprite | `nine_slice` |
| Blend modes | Composition layer | `blend`, `opacity` |
| Parallax | Composition layer | `parallax` |
| Secondary motion | Animation | `attachments` |
| Hit boxes | Sprite/Animation | `metadata.boxes` |

### What Can Be Transform Operations

- Dithering patterns
- Selective outline
- Sub-pixel animation
- Squash & stretch
- All geometric transforms

### What Needs New Types

- Particle systems (`type: particle`)

### What's CLI Only

- Onion skinning (`pxl show --onion`)

---

## Progressive Implementation

**Phase A:** High-priority features for Pixel Artist & Animator
- Color ramps
- Palette cycling
- Frame tags

**Phase B:** Game developer features
- Nine-slice
- Metadata / hitboxes
- Export format options

**Phase C:** Pixel art polish
- Dithering patterns
- Selective outline
- Blend modes

**Phase D:** Motion designer power features
- Squash & stretch
- Sub-pixel animation
- Secondary motion
- Arc paths

**Phase E:** Advanced systems
- Particle systems

---

## Open Questions

1. **Palette cycling + transforms:** If an animation has both palette cycling and sprite transforms, what's the interaction?

2. **Nine-slice + transforms:** Can you transform a nine-sliced sprite? (Probably: transform first, then nine-slice)

3. **Frame metadata format:** Should per-frame metadata be inline or in a separate structure?

4. **Particle randomness:** How to handle seeded randomness for reproducible particle effects?

5. **Blend mode support in CLI:** Should `pxl render` support blend modes, or compositions-only?

---

## Task Dependency Diagram

```
                      ADVANCED TRANSFORMS TASK FLOW
═══════════════════════════════════════════════════════════════════════════════

PREREQUISITE
┌─────────────────────────────────────────────────────────────────────────────┐
│                     Phase 18 Complete (TRF-12)                              │
└─────────────────────────────────────────────────────────────────────────────┘
WAVE 1 (Documentation First)
┌─────────────────────────────────────────────────────────────────────────────┐
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │                            ATF-1                                    │    │
│  │               Documentation & Format Spec                           │    │
│  │               - Spec all new attributes                             │    │
│  │               - Update format.md                                    │    │
│  │               - Create examples                                     │    │
│  └─────────────────────────────────────────────────────────────────────┘    │
└─────────────────────────────────────────────────────────────────────────────┘
WAVE 2 (High Priority - Parallel)
┌─────────────────────────────────────────────────────────────────────────────┐
│  ┌───────────────┐  ┌───────────────┐  ┌───────────────┐  ┌───────────────┐ │
│  │    ATF-2      │  │    ATF-3      │  │    ATF-4      │  │    ATF-5      │ │
│  │  Color Ramps  │  │   Palette     │  │  Frame Tags   │  │    Atlas      │ │
│  │  (Palette)    │  │   Cycling     │  │  (Animation)  │  │   Export      │ │
│  └───────────────┘  └───────────────┘  └───────────────┘  └───────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
WAVE 3 (Game Dev Features - Parallel)
┌─────────────────────────────────────────────────────────────────────────────┐
│  ┌─────────────────────────────────┐  ┌─────────────────────────────────┐   │
│  │            ATF-6                │  │            ATF-7                │   │
│  │         Nine-Slice              │  │       Hit/Hurt Boxes            │   │
│  │         (Sprite)                │  │        (Metadata)               │   │
│  └─────────────────────────────────┘  └─────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────────────┘
WAVE 4 (Pixel Art Polish - Parallel)
┌─────────────────────────────────────────────────────────────────────────────┐
│  ┌───────────────┐  ┌───────────────┐  ┌───────────────┐  ┌───────────────┐ │
│  │    ATF-8      │  │    ATF-9      │  │   ATF-10      │  │   ATF-11      │ │
│  │  Dithering    │  │  Selective    │  │    Blend      │  │    Onion      │ │
│  │  Patterns     │  │   Outline     │  │    Modes      │  │   Skinning    │ │
│  └───────────────┘  └───────────────┘  └───────────────┘  └───────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
WAVE 5 (Motion Designer - Parallel)
┌─────────────────────────────────────────────────────────────────────────────┐
│  ┌───────────────┐  ┌───────────────┐  ┌───────────────┐  ┌───────────────┐ │
│  │   ATF-12      │  │   ATF-13      │  │   ATF-14      │  │   ATF-15      │ │
│  │   Squash &    │  │  Sub-pixel    │  │  Secondary    │  │  Arc Motion   │ │
│  │   Stretch     │  │  Animation    │  │   Motion      │  │    Paths      │ │
│  └───────────────┘  └───────────────┘  └───────────────┘  └───────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
WAVE 6 (Advanced Systems)
┌─────────────────────────────────────────────────────────────────────────────┐
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │                           ATF-16                                    │    │
│  │                      Particle Systems                               │    │
│  │                      (New type: particle)                           │    │
│  └─────────────────────────────────────────────────────────────────────┘    │
└─────────────────────────────────────────────────────────────────────────────┘
WAVE 7 (Testing)
┌─────────────────────────────────────────────────────────────────────────────┐
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │                           ATF-17                                    │    │
│  │                    Comprehensive Test Suite                         │    │
│  │                    (all features)                                   │    │
│  └─────────────────────────────────────────────────────────────────────┘    │
└─────────────────────────────────────────────────────────────────────────────┘

═══════════════════════════════════════════════════════════════════════════════

PARALLELIZATION SUMMARY:
┌─────────────────────────────────────────────────────────────────────────────┐
│  Wave 1: ATF-1 (docs first)                    (1 task)                     │
│  Wave 2: ATF-2 + ATF-3 + ATF-4 + ATF-5         (4 tasks in parallel)        │
│  Wave 3: ATF-6 + ATF-7                         (2 tasks in parallel)        │
│  Wave 4: ATF-8 + ATF-9 + ATF-10 + ATF-11       (4 tasks in parallel)        │
│  Wave 5: ATF-12 + ATF-13 + ATF-14 + ATF-15     (4 tasks in parallel)        │
│  Wave 6: ATF-16                                (1 task)                     │
│  Wave 7: ATF-17                                (1 task)                     │
└─────────────────────────────────────────────────────────────────────────────┘

CRITICAL PATH: ATF-1 → ATF-2 → ... → ATF-16 → ATF-17

BEADS CREATION ORDER:
  1. ATF-1 (dep: TRF-12 - Phase 18 complete)
  2. ATF-2 through ATF-16 (dep: ATF-1)
  3. ATF-17 (dep: ATF-2 through ATF-16)
```

---

## Tasks

### Task ATF-1: Documentation & Format Spec

**Wave:** 1 (FIRST - docs before implementation)

Write comprehensive format specification for all Phase 19 features before implementation begins.

**Deliverables:**
- Update `docs/spec/format.md` with:
  - `palette.ramps` attribute syntax
  - `animation.palette_cycle` attribute syntax
  - `animation.tags` attribute syntax
  - `sprite.nine_slice` attribute syntax
  - `composition.layer.blend` and `opacity` attributes
  - `metadata.boxes` for hit/hurt regions
  - `animation.attachments` for secondary motion
  - `particle` type specification
- Create example files demonstrating each feature
- Update `src/prime.rs` with new feature documentation

**Verification:**
```bash
grep "palette_cycle" docs/spec/format.md
grep "nine_slice" docs/spec/format.md
./target/release/pxl prime | grep -i "advanced"
```

**Dependencies:** Task TRF-12 (Phase 18 complete)

---

### Task ATF-2: Color Ramps

**Wave:** 2 (parallel with ATF-3, ATF-4, ATF-5)

Implement automatic color ramp generation with hue-shifted shadows/highlights.

**Deliverables:**
- Add `ramps` attribute to Palette in `src/models.rs`
- Implement ramp generation with configurable shifts
- Generate tokens: `{name_2}`, `{name_1}`, `{name}`, `{name+1}`, `{name+2}`

**Verification:**
```bash
./target/release/pxl render examples/color_ramps.pxl -o output.png
```

**Dependencies:** Task ATF-1

---

### Task ATF-3: Palette Cycling

**Wave:** 2 (parallel with ATF-2, ATF-4, ATF-5)

Implement palette color rotation for water/fire/energy effects.

**Deliverables:**
- Add `palette_cycle` attribute to Animation in `src/models.rs`
- Support single and multiple cycles
- Implement color rotation during render

**Verification:**
```bash
./target/release/pxl render examples/waterfall.pxl -o waterfall.gif
```

**Dependencies:** Task ATF-1

---

### Task ATF-4: Frame Tags

**Wave:** 2 (parallel with ATF-2, ATF-3, ATF-5)

Implement semantic frame range markers for game engine integration.

**Deliverables:**
- Add `tags` attribute to Animation in `src/models.rs`
- Support per-tag FPS and loop settings
- Include tags in atlas export metadata

**Verification:**
```bash
./target/release/pxl render examples/player.pxl --format atlas -o player
cat player.json | jq '.tags'
```

**Dependencies:** Task ATF-1

---

### Task ATF-5: Atlas Export

**Wave:** 2 (parallel with ATF-2, ATF-3, ATF-4)

Implement sprite atlas packing with coordinate metadata.

**Deliverables:**
- Add `--format atlas` to CLI render command
- Implement rectangle packing algorithm
- Support options: `--max-size`, `--padding`, `--power-of-two`
- Support format variants: `atlas-aseprite`, `atlas-godot`, `atlas-unity`

**Verification:**
```bash
./target/release/pxl render game.pxl --format atlas -o game_atlas
ls game_atlas.png game_atlas.json
```

**Dependencies:** Task ATF-1

---

### Task ATF-6: Nine-Slice

**Wave:** 3 (parallel with ATF-7)

Implement scalable sprite slicing for UI elements.

**Deliverables:**
- Add `nine_slice` attribute to Sprite in `src/models.rs`
- Implement nine-slice rendering at arbitrary sizes
- Support `--nine-slice WxH` CLI option

**Verification:**
```bash
./target/release/pxl render button.pxl --nine-slice 64x32 -o button_wide.png
```

**Dependencies:** Task ATF-1

---

### Task ATF-7: Hit/Hurt Boxes

**Wave:** 3 (parallel with ATF-6)

Implement collision region metadata for sprites and animations.

**Deliverables:**
- Add `metadata.boxes` to Sprite in `src/models.rs`
- Add `frame_metadata` to Animation for per-frame boxes
- Include box data in atlas export

**Verification:**
```bash
./target/release/pxl render attack.pxl --format atlas -o attack
cat attack.json | jq '.frames[0].boxes'
```

**Dependencies:** Task ATF-1

---

### Task ATF-8: Dithering Patterns

**Wave:** 4 (parallel with ATF-9, ATF-10, ATF-11)

Implement dither transform operations with various patterns.

**Deliverables:**
- Add `dither` transform operation
- Implement patterns: checker, ordered-2x2, ordered-4x4, diagonal, noise
- Add `dither-gradient` for directional gradients

**Verification:**
```bash
./target/release/pxl transform sprite.pxl --dither checker -o dithered.pxl
```

**Dependencies:** Task ATF-1

---

### Task ATF-9: Selective Outline

**Wave:** 4 (parallel with ATF-8, ATF-10, ATF-11)

Implement color-aware outline generation (sel-out).

**Deliverables:**
- Add `sel-out` transform operation
- Implement neighbor color detection
- Support explicit color mapping

**Verification:**
```bash
./target/release/pxl transform sprite.pxl --sel-out -o outlined.pxl
```

**Dependencies:** Task ATF-1

---

### Task ATF-10: Blend Modes

**Wave:** 4 (parallel with ATF-8, ATF-9, ATF-11)

Implement layer blending for compositions.

**Deliverables:**
- Add `blend` and `opacity` attributes to CompositionLayer
- Implement modes: normal, multiply, screen, overlay, add, subtract

**Verification:**
```bash
./target/release/pxl render composition.pxl -o output.png
```

**Dependencies:** Task ATF-1

---

### Task ATF-11: Onion Skinning

**Wave:** 4 (parallel with ATF-8, ATF-9, ATF-10)

Implement animation preview with frame ghosts.

**Deliverables:**
- Add `--onion N` flag to `pxl show` command
- Render previous/next frames as transparent overlays
- Support `--onion-opacity` and `--onion-prev-color`/`--onion-next-color`

**Verification:**
```bash
./target/release/pxl show walk_cycle.pxl --onion 2
```

**Dependencies:** Task ATF-1

---

### Task ATF-12: Squash & Stretch

**Wave:** 5 (parallel with ATF-13, ATF-14, ATF-15)

Implement scale-based deformation for impact effects.

**Deliverables:**
- Add `scale` transform operation with x/y parameters
- Support keyframe-based squash/stretch animations
- Handle pixel interpolation options

**Verification:**
```bash
./target/release/pxl render bounce.pxl -o bounce.gif
```

**Dependencies:** Task ATF-1

---

### Task ATF-13: Sub-pixel Animation

**Wave:** 5 (parallel with ATF-12, ATF-14, ATF-15)

Implement apparent motion smaller than 1 pixel via color blending.

**Deliverables:**
- Add `subpixel-x` and `subpixel-y` transform properties
- Implement color interpolation at sub-pixel boundaries

**Verification:**
```bash
./target/release/pxl render smooth_motion.pxl -o smooth.gif
```

**Dependencies:** Task ATF-1

---

### Task ATF-14: Secondary Motion

**Wave:** 5 (parallel with ATF-12, ATF-13, ATF-15)

Implement attached elements with delayed/dampened motion.

**Deliverables:**
- Add `attachments` attribute to Animation
- Implement delay and damping physics
- Support spring-based overshoot

**Verification:**
```bash
./target/release/pxl render run_with_cape.pxl -o cape.gif
```

**Dependencies:** Task ATF-1

---

### Task ATF-15: Arc Motion Paths

**Wave:** 5 (parallel with ATF-12, ATF-13, ATF-14)

Implement curved motion interpolation using bezier paths.

**Deliverables:**
- Add `interpolation: bezier` keyframe option
- Add `path: arc` for automatic curve fitting
- Support explicit control points

**Verification:**
```bash
./target/release/pxl render throw_arc.pxl -o throw.gif
```

**Dependencies:** Task ATF-1

---

### Task ATF-16: Particle Systems

**Wave:** 6

Implement particle emitters for effects like sparks, dust, rain.

**Deliverables:**
- Add new `particle` type to format
- Implement emitter with rate, lifetime, velocity, gravity
- Support fade, rotation, and random seed

**Verification:**
```bash
./target/release/pxl render sparkle.pxl -o sparkle.gif
```

**Dependencies:** Task ATF-1

---

### Task ATF-17: Test Suite

**Wave:** 7

Comprehensive tests for all Phase 19 features.

**Deliverables:**
- Unit tests for each new feature
- Integration tests for CLI commands
- Test fixtures for all new format attributes
- Round-trip tests

**Verification:**
```bash
cargo test advanced
cargo test --test cli_integration atlas
cargo test --test cli_integration particle
```

**Dependencies:** Tasks ATF-2 through ATF-16

---

## Verification Summary

```bash
# 1. All existing tests pass
cargo test

# 2. New feature tests pass
cargo test advanced
cargo test palette_cycle
cargo test nine_slice
cargo test particle

# 3. CLI commands work
./target/release/pxl render examples/waterfall.pxl -o waterfall.gif
./target/release/pxl render game.pxl --format atlas -o atlas
./target/release/pxl show walk.pxl --onion 2

# 4. Documentation updated
./target/release/pxl prime | grep -i palette_cycle
grep "particle" docs/spec/format.md
```

---

## Success Criteria

1. All high-priority features work (color ramps, palette cycling, frame tags, atlas export)
2. Game dev features work (nine-slice, hit boxes)
3. Pixel art polish features work (dithering, sel-out, blend modes, onion skinning)
4. Motion designer features work (squash/stretch, sub-pixel, secondary motion, arc paths)
5. Particle systems work
6. All tests pass
7. Documentation complete and accurate