🎉 Initial commit

This commit is contained in:
2025-03-19 21:10:19 +08:00
commit 86c8755f79
70 changed files with 6915 additions and 0 deletions

52
animation/transform.go Normal file
View File

@@ -0,0 +1,52 @@
package animation
import (
"fmt"
)
// TransformAnimation 变换动画
type TransformAnimation struct {
BaseAnimation
TransformType string // 变换类型scale, translate等
From string // 起始变换值
To string // 结束变换值
}
// NewTransformAnimation 创建一个变换动画
func NewTransformAnimation(targetID string, transformType string, from, to string, duration float64, repeatCount int) *TransformAnimation {
return &TransformAnimation{
BaseAnimation: BaseAnimation{
Type: Transform,
Duration: duration,
RepeatCount: repeatCount,
Delay: 0,
TargetID: targetID,
Attributes: make(map[string]string),
},
TransformType: transformType,
From: from,
To: to,
}
}
// GenerateSVG 生成变换动画的SVG代码
func (a *TransformAnimation) GenerateSVG() string {
// 创建一个animateTransform元素并将其添加到目标元素中
svg := fmt.Sprintf("<animateTransform href=\"#%s\" attributeName=\"transform\" attributeType=\"XML\" type=\"%s\" ", a.TargetID, a.TransformType)
svg += fmt.Sprintf("from=\"%s\" to=\"%s\" ", a.From, a.To)
svg += fmt.Sprintf("dur=\"%gs\" ", a.Duration)
if a.RepeatCount < 0 {
svg += "repeatCount=\"indefinite\" "
} else if a.RepeatCount > 0 {
svg += fmt.Sprintf("repeatCount=\"%d\" ", a.RepeatCount)
}
if a.Delay > 0 {
svg += fmt.Sprintf("begin=\"%gs\" ", a.Delay)
}
svg += "additive=\"sum\" />\n"
return svg
}