Skip to content

Instantly share code, notes, and snippets.

@yashlamba
Created March 4, 2020 08:52
Show Gist options
  • Save yashlamba/3ac53691929287c5c9768dc179ab3ee6 to your computer and use it in GitHub Desktop.
Save yashlamba/3ac53691929287c5c9768dc179ab3ee6 to your computer and use it in GitHub Desktop.
testdartpad
import 'package:flutter/material.dart';
import 'dart:math';
import 'dart:ui';
final 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:CustomPaint(
painter: RosePainter(2, 4, 300, 300, 200, 0.1),
child: Container(),
),
),
),
);
}
}
class RosePainter extends CustomPainter {
double d, r, n, c;
double k, transformx, transformy;
List<Offset> points = [];
RosePainter(
this.d, this.n, this.transformx, this.transformy, this.r, this.c) {
k = n / d;
}
@override
void paint(Canvas canvas, Size size) {
var paint = Paint();
paint.color = Colors.red;
paint.strokeWidth = 2;
for (double i = 0; i < 2 * d * pi; i += 0.01) {
points.add(
Offset(r * (cos(k * i) + c) * cos(i), r * (cos(k * i) + c) * sin(i))
.translate(transformx, transformy));
}
canvas.drawPoints(PointMode.polygon, points, paint);
}
@override
bool shouldRepaint(RosePainter oldDelegate) => true;
@override
bool shouldRebuildSemantics(RosePainter oldDelegate) => false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment