Created
November 18, 2020 14:05
-
-
Save talamaska/af90cf102e790a892635f9c7a1734187 to your computer and use it in GitHub Desktop.
Flutter Vikings Logo Contest
This file contains 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
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | |
// for details. All rights reserved. Use of this source code is governed by a | |
// BSD-style license that can be found in the LICENSE file. | |
import 'package:flutter/material.dart'; | |
import 'dart:ui' as ui; | |
void main() => runApp(FlutterVikingsLogoApp()); | |
class FlutterVikingsLogoApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Vikings Logo Contest', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: FlutterVikingsLogoPage(title: 'Flutter Vikings Logo Contest'), | |
); | |
} | |
} | |
class FlutterVikingsLogoPage extends StatefulWidget { | |
FlutterVikingsLogoPage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_FlutterVikingsLogoPageState createState() => _FlutterVikingsLogoPageState(); | |
} | |
class _FlutterVikingsLogoPageState extends State<FlutterVikingsLogoPage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: FlutterVikingsLogo( | |
width: 200.0, | |
height: 200.0, | |
), | |
), | |
); | |
} | |
} | |
class FlutterVikingsLogo extends StatelessWidget { | |
const FlutterVikingsLogo({ | |
@required this.width, | |
@required this.height, | |
}); | |
final double width; | |
final double height; | |
@override | |
Widget build(BuildContext context) { | |
return SizedBox( | |
width: width, | |
height: height, | |
child: CustomPaint( | |
painter: FlutterVikingsLogoPainter( | |
width: width, | |
height: height, | |
), | |
)); | |
} | |
} | |
class FlutterVikingsLogoPainter extends CustomPainter { | |
FlutterVikingsLogoPainter({ | |
@required this.width, | |
@required this.height, | |
}); | |
final double width; | |
final double height; | |
Path _leftWingPath(Size size) { | |
return Path() | |
..lineTo(size.width * 0.68, size.height * 0.23) | |
..cubicTo(size.width * 0.68, size.height * 0.23, size.width, | |
size.height * 0.48, size.width, size.height * 0.48) | |
..cubicTo(size.width, size.height * 0.48, size.width * 0.11, | |
size.height * 1.2, size.width * 0.11, size.height * 1.2) | |
..cubicTo(size.width * 0.07, size.height * 1.23, 0, size.height * 1.21, 0, | |
size.height * 1.16) | |
..cubicTo( | |
0, size.height * 1.16, 0, size.height * 0.72, 0, size.height * 0.72) | |
..cubicTo(0, size.height * 0.71, size.width * 0.01, size.height * 0.69, | |
size.width * 0.02, size.height * 0.68) | |
..cubicTo(size.width * 0.02, size.height * 0.68, size.width * 0.59, | |
size.height * 0.23, size.width * 0.59, size.height * 0.23) | |
..cubicTo(size.width * 0.62, size.height / 5, size.width * 0.65, | |
size.height / 5, size.width * 0.68, size.height * 0.23) | |
..cubicTo(size.width * 0.68, size.height * 0.23, size.width * 0.68, | |
size.height * 0.23, size.width * 0.68, size.height * 0.23); | |
} | |
Path _rightWingPath(Size size) { | |
return Path() | |
..lineTo(size.width * 0.59, size.height * 0.23) | |
..cubicTo(size.width * 0.59, size.height * 0.23, size.width * 0.27, | |
size.height * 0.48, size.width * 0.27, size.height * 0.48) | |
..cubicTo(size.width * 0.27, size.height * 0.48, size.width * 1.16, | |
size.height * 1.2, size.width * 1.16, size.height * 1.2) | |
..cubicTo(size.width * 1.2, size.height * 1.23, size.width * 1.27, | |
size.height * 1.21, size.width * 1.27, size.height * 1.16) | |
..cubicTo(size.width * 1.27, size.height * 1.16, size.width * 1.27, | |
size.height * 0.72, size.width * 1.27, size.height * 0.72) | |
..cubicTo(size.width * 1.27, size.height * 0.71, size.width * 1.26, | |
size.height * 0.69, size.width * 1.25, size.height * 0.68) | |
..cubicTo(size.width * 1.25, size.height * 0.68, size.width * 0.68, | |
size.height * 0.23, size.width * 0.68, size.height * 0.23) | |
..cubicTo(size.width * 0.65, size.height / 5, size.width * 0.61, | |
size.height / 5, size.width * 0.59, size.height * 0.23) | |
..cubicTo(size.width * 0.59, size.height * 0.23, size.width * 0.59, | |
size.height * 0.23, size.width * 0.59, size.height * 0.23); | |
} | |
Path _shadowPath(Size size) { | |
return Path() | |
..lineTo(size.width * 0.63, size.height * 0.78) | |
..lineTo(size.width * 0.27, size.height * 0.48) | |
..lineTo(size.width / 2, size.height * 0.88) | |
..lineTo(size.width * 0.63, size.height * 0.78); | |
} | |
Path _rightHorn(Size size) { | |
return Path() | |
..lineTo(size.width * 1.04, 0) | |
..cubicTo(size.width * 1.04, 0, size.width * 1.15, size.height / 4, | |
size.width * 1.02, size.height * 0.34) | |
..cubicTo(size.width * 1.02, size.height * 0.34, size.width * 1.17, | |
size.height * 0.4, size.width * 1.21, size.height * 0.49) | |
..cubicTo(size.width * 1.21, size.height * 0.49, size.width * 1.43, | |
size.height * 0.26, size.width * 1.04, 0) | |
..cubicTo( | |
size.width * 1.04, 0, size.width * 1.04, 0, size.width * 1.04, 0); | |
} | |
Path _rightHornRing(Size size) { | |
return Path() | |
..lineTo(size.width * 1.14, size.height * 0.58) | |
..cubicTo(size.width * 1.14, size.height * 0.58, size.width * 1.23, | |
size.height * 0.54, size.width * 1.19, size.height * 0.48) | |
..cubicTo(size.width * 1.15, size.height * 0.42, size.width, | |
size.height / 3, size.width, size.height * 0.34) | |
..cubicTo(size.width * 0.96, size.height * 0.35, size.width * 0.89, | |
size.height * 0.38, size.width * 0.89, size.height * 0.38) | |
..cubicTo(size.width * 0.89, size.height * 0.38, size.width * 1.09, | |
size.height * 0.48, size.width * 1.14, size.height * 0.58) | |
..cubicTo(size.width * 1.14, size.height * 0.58, size.width * 1.14, | |
size.height * 0.58, size.width * 1.14, size.height * 0.58); | |
} | |
Path _leftHorn(Size size) { | |
return Path() | |
..lineTo(size.width * 0.22, 0) | |
..cubicTo(size.width * 0.22, 0, size.width * 0.12, size.height / 4, | |
size.width / 4, size.height * 0.34) | |
..cubicTo(size.width / 4, size.height * 0.34, size.width * 0.1, | |
size.height * 0.4, size.width * 0.06, size.height * 0.49) | |
..cubicTo(size.width * 0.06, size.height * 0.49, -0.16, | |
size.height * 0.26, size.width * 0.22, 0) | |
..cubicTo( | |
size.width * 0.22, 0, size.width * 0.22, 0, size.width * 0.22, 0); | |
} | |
Path _leftHornRing(Size size) { | |
return Path() | |
..lineTo(size.width * 0.12, size.height * 0.58) | |
..cubicTo(size.width * 0.12, size.height * 0.58, size.width * 0.04, | |
size.height * 0.54, size.width * 0.08, size.height * 0.48) | |
..cubicTo(size.width * 0.12, size.height * 0.42, size.width * 0.26, | |
size.height / 3, size.width * 0.28, size.height * 0.34) | |
..cubicTo(size.width * 0.3, size.height * 0.35, size.width * 0.38, | |
size.height * 0.38, size.width * 0.38, size.height * 0.38) | |
..cubicTo(size.width * 0.38, size.height * 0.38, size.width * 0.18, | |
size.height * 0.48, size.width * 0.12, size.height * 0.58) | |
..cubicTo(size.width * 0.12, size.height * 0.58, size.width * 0.12, | |
size.height * 0.58, size.width * 0.12, size.height * 0.58); | |
} | |
@override | |
void paint(Canvas canvas, Size size) { | |
Paint paint = Paint(); | |
Path path = Path(); | |
// Left wing | |
paint.color = Color(0xff055799); | |
path = _leftWingPath(size); | |
canvas.drawPath(path, paint); | |
// Right wing | |
paint.color = Color(0xff07c6f9); | |
path = _rightWingPath(size); | |
canvas.drawPath(path, paint); | |
// Path Shadow | |
final gradient = ui.Gradient.linear( | |
Offset(size.width / 2, size.height * 0.88), | |
Offset(size.width * 0.27, size.height * 0.48), | |
[ | |
Color(0xFF000000).withOpacity(0), | |
Color(0xFF000000).withOpacity(0.4), | |
], | |
[0, 1], | |
); | |
final gradientPaint = Paint()..shader = gradient; | |
path = _shadowPath(size); | |
canvas.drawPath(path, gradientPaint); | |
// Right horn | |
paint.color = Color(0xff07c6f9); | |
path = _rightHorn(size); | |
canvas.drawPath(path, paint); | |
// Right horn ring | |
paint.color = Color(0xff055799); | |
path = _rightHornRing(size); | |
canvas.drawPath(path, paint); | |
// Left horn | |
paint.color = Color(0xff055799); | |
path = _leftHorn(size); | |
canvas.drawPath(path, paint); | |
// Left horn ring | |
paint.color = Color(0xff07c6f9); | |
path = _leftHornRing(size); | |
canvas.drawPath(path, paint); | |
} | |
@override | |
bool shouldRepaint(FlutterVikingsLogoPainter oldDelegate) { | |
return oldDelegate.width != width || oldDelegate.height != height; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment