metaballs 1.5.0

SDKflutter
Platformandroidioswindowslinuxmacosweb

A metaballs implementation for flutter using webgl on the web and the shader package on other devices

Animated Metaballs for Flutter

Pub Version Live Example

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


Installing:

dependencies:
  metaballs: ^1.4.2
import 'package:metaballs/metaballs.dart';

Usage:

Metaballs(
  color: const Color.fromARGB(255, 66, 133, 244),
  effect: MetaballsEffect.follow(
    growthFactor: 1,
    smoothing: 1,
    radius: 0.5,
  ),
  gradient: LinearGradient(
    colors: [
      const Color.fromARGB(255, 90, 60, 255),
      const Color.fromARGB(255, 120, 255, 255),
    ],
    begin: Alignment.bottomRight,
    end: Alignment.topLeft
  ),
  metaballs: 40,
  animationDuration: const Duration(milliseconds: 200),
  speedMultiplier: 1,
  bounceStiffness: 3,
  minBallRadius: 15,
  maxBallRadius: 40,
  glowRadius: 0.7,
  glowIntensity: 0.6,
  child: Text('METABALLS')
)

PropertyDefault valueAccepted valuesDescription
Color? colorColor(0xff4285F4)The color of the metaballs
MetaballsEffect? effectThe animated effect applied to the metaballs
Gradient? gradientA gradient for coloring the metaballs, overwrites color
int? metaballs401 to 128The amount of metaballs
Duration? animationDurationDuration(milliseconds: 200)The duration of the color changing animation
double? speedMultiplier1Above 0A multiplier of the ball movement speed
double? bounceStiffness3Above 0A multiplier to change the speed at which balls change direction
double? minBallRadius150 or moreThe minimum size of a ball
double? maxBallRadius40Above minThe maximum size of a ball
double? glowRadius0.70 to 1A multiplier to indicate the radius of the glow
double? glowIntensity0.60 to 1The brightness of the glow around the ball
Widget? childA 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

PropertyDefault valueAccepted valuesDescription
double? smoothing10 or moreThe amount the metaballs movement gets smoothed
double? growthFactor10 or moreThe amount the metaballs grow relative to their movement speed
double? radius0 or moreThe 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

PropertyDefault valueAccepted valuesDescription
double? speedup1Above 0The 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

PropertyDefault valueAccepted valuesDescription
double? radius0.5Above 0The radius around the mouse / touch in which the metaballs get scaled up
double? growthFactor0.5Above 0The amount by which the metaballs increase in size
double? smoothing10 or moreThe 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

PropertyDefault valueAccepted valuesDescription
double? speed1Above 0The speed of the ripple effect
double? width1Above 0The the ripple width
double? growthFactor1Above 0The amount by which the metaballs grow
Duration? fadeDuration(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.