Created
September 14, 2019 09:35
-
-
Save tarek360/ca65a2aeb328e946c491da08dcc4f106 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HeartsPainter extends CustomPainter { | |
final Paint hearPaint = Paint() | |
..style = PaintingStyle.stroke; | |
@override | |
void paint(Canvas canvas, Size size) { | |
print('Hearts Painting..'); | |
const int count = 700; | |
for (int i = 0; i < count; i++) { | |
_drawHeart( | |
canvas, | |
Size((i + 1) / count * size.width, (i + 1) / count * size.height), | |
Colors.blue.withRed((i / count * 255).toInt()).withOpacity(0.4)); | |
} | |
} | |
void _drawHeart(Canvas canvas, Size size, Color color) { | |
final Path path = Path(); | |
final double width = size.width; | |
final double height = size.height; | |
// Starting point | |
path.moveTo(width / 2, height / 5); | |
// Upper left path | |
path.cubicTo( | |
5 * width / 14, 0, | |
0, height / 15, | |
width / 28, 2 * height / 5); | |
// Lower left path | |
path.cubicTo( | |
width / 14, 2 * height / 3, | |
3 * width / 7, 5 * height / 6, | |
width / 2, height); | |
// Lower right path | |
path.cubicTo( | |
4 * width / 7, 5 * height / 6, | |
13 * width / 14, 2 * height / 3, | |
27 * width / 28, 2 * height / 5); | |
// Upper right path | |
path.cubicTo( | |
width, height / 15, | |
9 * width / 14, 0, | |
width / 2, height / 5); | |
canvas.drawPath( | |
path, | |
hearPaint..color = color); | |
} | |
@override | |
bool shouldRepaint(HeartsPainter oldDelegate) => false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment