Metaballs 是一個 Flutter 套件,可在 Web 上使用 WebGL,在原生平台使用 shader 套件創造流體、動態的 metaball 效果。它能實現平滑、互動式的視覺化效果,呈現出有機融合的形狀,並對使用者輸入或動畫做出反應。適用於背景動畫、抽象介面與沉浸式 UI,利用 GPU 加速在 Android、iOS、Web、macOS、Windows 與 Linux 上達到高效率。此套件將複雜的著色器邏輯簡化為易用的 API,讓沒有深入圖形知識的開發者也能輕鬆實現進階視覺效果。
適用情境
互動式應用背景
動畫啟動畫面
抽象 UI 元素
資料或音樂的視覺化工具
動態漸層疊加
主要特色
基於 WebGL 的網頁渲染
基於着色器的原生實作
流暢、反應迅速的蝌蚪狀球體物理效果
跨平台相容性
用於複雜視覺效果的簡單 API
GPU 加速效能
適合對象
尋求流暢動畫的UI設計師
開發沉浸式體驗的開發者
具有藝術或抽象主題的應用程式
需要即時視覺反饋的專案
原型設計互動背景
使用建議
移動設備上的更高GPU使用率
對單個球體屬性的自訂有限
需要了解基本的著色器概念
不適合用於靜態或簡單的UI
效能可能在舊裝置上有所差異
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
Animated Metaballs for Flutter
About
This library makes it easy to add well performing, highly configurable metaballs to your flutter project. The metaballs automatically scale to any screen size so you don't have to manually adjust the parameters for different devices. The metaballs have been implemented in shaders for the best performance across all devices. All available effects have been optimized for both mouse and touch input and should not interfere with any gesture detectors
A gradient for coloring the metaballs, overwrites color
int? metaballs
40
1 to 128
The amount of metaballs
Duration? animationDuration
Duration(milliseconds: 200)
The duration of the color changing animation
double? speedMultiplier
1
Above 0
A multiplier of the ball movement speed
double? bounceStiffness
3
Above 0
A multiplier to change the speed at which balls change direction
double? minBallRadius
15
0 or more
The minimum size of a ball
double? maxBallRadius
40
Above min
The maximum size of a ball
double? glowRadius
0.7
0 to 1
A multiplier to indicate the radius of the glow
double? glowIntensity
0.6
0 to 1
The brightness of the glow around the ball
Widget? child
A widget to be placed on top of the Metaballs widget
Effects
MetaballsEffect.follow()
This effect adds a metaball for every cursor / touch and then follows that cursor / touch around
Property
Default value
Accepted values
Description
double? smoothing
1
0 or more
The amount the metaballs movement gets smoothed
double? growthFactor
1
0 or more
The amount the metaballs grow relative to their movement speed
double? radius
0 or more
The size of the following metaball where 0 is the minBallRadius and 1 is the maxBallRadius
MetaballsEffect.speedup()
This effect makes all metaballs speedup relative to how fast you move your mouse or swipe on your touchscreen
Property
Default value
Accepted values
Description
double? speedup
1
Above 0
The amount the metaballs speed up relative to the mouse / swipe speed
MetaballsEffect.grow()
This effect increases the radius of all metaballs based on how close they are to the mouse cursor or a touch
Property
Default value
Accepted values
Description
double? radius
0.5
Above 0
The radius around the mouse / touch in which the metaballs get scaled up
double? growthFactor
0.5
Above 0
The amount by which the metaballs increase in size
double? smoothing
1
0 or more
The amount the movement gets smoothed
MetaballsEffect.ripple()
This effect makes all metaballs increase and then decrease their radius in an outgoing ripple from a tab / mouse click
Property
Default value
Accepted values
Description
double? speed
1
Above 0
The speed of the ripple effect
double? width
1
Above 0
The the ripple width
double? growthFactor
1
Above 0
The amount by which the metaballs grow
Duration? fade
Duration(milliseconds: 1200)
The time before the ripple is completely faded away
Web support
On web the gradients are currently manually implemented in webgl because ShaderMask is currently not supported on web. Because of that certain gradient features are currently not implemented like the focal and focalRadius options on the RadialGradient and the transform matrix on all gradients. Support for these options will probably be added in a later release but currently don't have high priority. If you depend on these features feel free to open a feature request or pull request on github.