Skip to content

Instantly share code, notes, and snippets.

@iBelow
Last active May 1, 2026 22:10
Show Gist options
  • Select an option

  • Save iBelow/04d78185c4d03ff9fdee1686ff65a13f to your computer and use it in GitHub Desktop.

Select an option

Save iBelow/04d78185c4d03ff9fdee1686ff65a13f to your computer and use it in GitHub Desktop.
fl
import 'package:flutter/material.dart';
import 'dart:math' as math;
void main() =>
runApp(const MaterialApp(home: Scaffold(body: SoundWaveOptimizer())));
class SoundWaveOptimizer extends StatefulWidget {
const SoundWaveOptimizer({super.key});
@override
State<SoundWaveOptimizer> createState() => _SoundWaveOptimizerState();
}
class _SoundWaveOptimizerState extends State<SoundWaveOptimizer>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 5),
)..repeat();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
color: const Color(0xFF050505),
alignment: Alignment.center,
child: RepaintBoundary(
child: CustomPaint(
size: const Size(400, 400),
painter: OptimizedWavePainter(animation: _controller),
),
),
);
}
}
class OptimizedWavePainter extends CustomPainter {
final Animation<double> animation;
OptimizedWavePainter({required this.animation}) : super(repaint: animation);
@override
void paint(Canvas canvas, Size size) {
final center = Offset(size.width / 2, size.height / 2);
final double t = animation.value;
_drawOrganicShape(
canvas,
center,
size.width * 0.35,
t,
6,
0.6,
const Color(0xFF00D2FF),
);
_drawOrganicShape(
canvas,
center,
size.width * 0.30,
t,
4,
-0.4,
const Color(0xFF9D50BB),
);
canvas.drawCircle(center, size.width * 0.2, Paint()..color = Colors.white);
}
void _drawOrganicShape(
Canvas canvas,
Offset center,
double radius,
double t,
int frequency,
double speed,
Color color,
) {
final path = Path();
final paint = Paint()
..color = color.withValues(alpha: 0.6)
..style = PaintingStyle.stroke
..strokeWidth = 3;
for (double i = 0; i <= math.pi * 2 + 0.1; i += 0.05) {
double wobble = math.sin(i * frequency + (t * speed * math.pi * 2)) * 12;
double pulse = math.cos(t * math.pi * 2) * 8;
double currentRadius = radius + wobble + pulse;
double x = center.dx + math.cos(i) * currentRadius;
double y = center.dy + math.sin(i) * currentRadius;
if (i == 0) {
path.moveTo(x, y);
} else {
path.lineTo(x, y);
}
}
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(OptimizedWavePainter oldDelegate) {
return oldDelegate.animation.value != animation.value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment