std.svg.anim
SMIL-Animationen: Attributanimation (<animate>), Transformationen (<animateTransform>), Farbübergänge, Bewegung entlang eines Pfads und Keyframes.
Zwei Wege, eine Animation an ein Element zu hängen:
elem = 0— die Animation wird vorgemerkt und beim nächstenSvgApplyals Kind des dort geschlossenen Elements geschrieben. Das Element bekommt dafür automatisch einid(_a0,_a1, …).elem > 0— die Animation wird sofort geschrieben und verweist überhref=„#_a{elem}“auf ein bereits vorhandenes Element.
Die Dauer ist eine Zahl in Sekunden (f64), kein String. Die Wiederholung setzt SvgAnimRepeat vorab: 0 bedeutet indefinite.
→ std.svg · std.svg.elements · std.svg.path
Verwendung
import std.io;
import std.svg.builder;
import std.svg.elements;
import std.svg.style;
import std.svg.anim;
fn main(): int64 {
var doc: int64 := SvgNew(400.0, 300.0);
SvgSetPrettyPrint(doc, 1);
// Vorgemerkt: haengt sich an das naechste abgeschlossene Element
SvgSetFillHex(doc, "red");
SvgAnimate(doc, 0, "r", "50", "80", 1.0);
SvgCircle(doc, 200.0, 150.0, 50.0);
SvgApply(doc);
// Dreimal statt endlos, Drehung ueber die Konstante
SvgAnimRepeat(doc, 3);
SvgAnimateTransform(doc, 0, SVG_AT_ROTATE, "0 200 200", "360 200 200", 2.0);
SvgSetFillHex(doc, "blue");
SvgRect(doc, 150.0, 150.0, 100.0, 100.0);
SvgApply(doc);
// Keyframes: Zeiten als Anteil 0.0–1.0
var kf: int64 := SvgKeyframesBegin(doc, 0, "opacity");
SvgKeyframe(doc, kf, 0.0, "0");
SvgKeyframe(doc, kf, 0.5, "1");
SvgKeyframe(doc, kf, 1.0, "0");
SvgKeyframesEnd(doc, kf, 2.0, 0);
SvgSetFillHex(doc, "green");
SvgCircle(doc, 350.0, 250.0, 30.0);
SvgApply(doc);
Print(SvgToString(doc)); Print("\n");
SvgFree(doc);
return 0;
}
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="300">
<circle cx="200" cy="150" r="50" fill="red" id="_a0">
<animate attributeName="r" from="50" to="80" dur="1s" repeatCount="indefinite"/>
</circle>
<rect x="150" y="150" width="100" height="100" fill="blue" id="_a1">
<animateTransform attributeName="transform" type="rotate" from="0 200 200" to="360 200 200" additive="sum" dur="2s" repeatCount="3"/>
</rect>
<circle cx="350" cy="250" r="30" fill="green" id="_a2">
<animate attributeName="opacity" values="0;1;0" keyTimes="0;0.5;1" dur="2s" repeatCount="indefinite"/>
</circle>
</svg>
SvgAnimRepeat wirkt fort, bis es neu gesetzt wird — im Beispiel erbt die Keyframe-Animation deshalb nicht die 3 aus dem zweiten Block, weil SvgKeyframesEnd die Wiederholung als eigenes Argument nimmt.
Konstanten
| Name | Wert | Bedeutung |
|---|---|---|
SVG_AT_TRANSLATE | 0 | type=„translate“ |
SVG_AT_SCALE | 1 | type=„scale“ |
SVG_AT_ROTATE | 2 | type=„rotate“ |
SVG_AT_SKEWX | 3 | type=„skewX“ |
SVG_AT_SKEWY | 4 | type=„skewY“ |
Funktionen
| Signatur | Sichtbarkeit | Beschreibung |
|---|---|---|
SvgAnimRepeat(doc: int64, repeatCount: int64): void | pub | Wiederholung für die folgenden Animationen; 0 = indefinite |
SvgAnimate(doc: int64, elem: int64, attrName: pchar, fromV: pchar, toV: pchar, dur: f64): void | pub | <animate> für ein Attribut |
SvgAnimateTransform(doc: int64, elem: int64, atType: int64, fromV: pchar, toV: pchar, dur: f64): void | pub | <animateTransform>, Typ über SVG_AT_* |
SvgAnimateMotion(doc: int64, elem: int64, motionPath: pchar, dur: f64, repeatCount: int64): void | pub | Bewegung entlang eines Pfads |
SvgAnimateMotionRotate(doc: int64, elem: int64, motionPath: pchar, dur: f64, repeatCount: int64): void | pub | Bewegung mit Ausrichtung entlang des Pfads |
SvgAnimateColor(doc: int64, elem: int64, attrName: pchar, fromHex: pchar, toHex: pchar, dur: f64): void | pub | Farbübergang, Farben als Hex |
SvgKeyframesBegin(doc: int64, elem: int64, attrName: pchar): int64 | pub | Keyframe-Folge beginnen |
SvgKeyframe(doc: int64, kf: int64, time: f64, value: pchar): void | pub | Einzelner Keyframe, Zeit als Anteil 0.0–1.0 |
SvgKeyframesEnd(doc: int64, kf: int64, dur: f64, repeatCount: int64): void | pub | Keyframe-Folge abschließen |
SvgAnimateBeginOn(doc: int64, anim: int64, otherId: int64, eventName: pchar): void | pub | Start an ein Ereignis eines anderen Elements binden |
Letzte Aktualisierung: 2026-08-19 — Seite gegen die echten Signaturen neu geschrieben: jede Funktion nimmt doc und elem, die Dauer ist ein f64 in Sekunden, der Transformtyp eine SVG_AT_*-Konstante, und SvgAnimateBegin/SvgAnimateEnd/SvgAnimateKeyframes/SvgAnimateSet gibt es nicht. Beispiel mit lyxc 1.1.3I übersetzt und ausgeführt, Ausgabe übernommen.
