Skip to content

Instantly share code, notes, and snippets.

@sidroniolima
Created July 6, 2023 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidroniolima/1fea5ebf208ecdfe31d857e0e004119b to your computer and use it in GitHub Desktop.
Save sidroniolima/1fea5ebf208ecdfe31d857e0e004119b to your computer and use it in GitHub Desktop.
malevolent-performance-0406

malevolent-performance-0406

Created with <3 with dartpad.dev.

import 'package:flutter/material.dart';
import 'dart:math';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SizedBox(
height: 150.0,
child: ClipPath(
clipper: BackgroundClipPath(),
child: Container(
decoration: const BoxDecoration(
color: Color(0xFFF78770),
),
),
),
);
}
}
class BackgroundClipPath extends CustomClipper<Path> {
@override
Path getClip(Size size) {
var path = Path();
int height = size.height.toInt();
int beginCurve = height - 100;
int middleCurve = height;
int minBeginCurve = height~/2;
int waves = 5;
int paths = waves * 2;
List<Offset> offsets = [];
Random rdn = Random();
path.lineTo(0.0, size.height - 30);
for (int i = 0; i < paths; i++) {
double dx = size.width / paths * (i + 1);
int ratio = minBeginCurve - rdn.nextInt(minBeginCurve - beginCurve);
double dy = (i%2==0) ? middleCurve.toDouble() : (ratio).toDouble();
print('middle: $middleCurve, max: $beginCurve, ratio: $dy');
offsets.add(Offset(dx, dy));
}
for (int i = 0; i < paths; i+=2) {
path.quadraticBezierTo(offsets[i].dx, offsets[i].dy, offsets[i+1].dx, offsets[i+1].dy);
if (i == paths - 2) { break; }
}
path.lineTo(size.width, 0.0);
path.close();
return path;
}
@override
bool shouldReclip(covariant CustomClipper<Path> oldClipper) => false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment