Skip to content

Instantly share code, notes, and snippets.

@jonasjuni
Created February 2, 2022 22:54
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 jonasjuni/b853faf425fe13b445f772a065bd846b to your computer and use it in GitHub Desktop.
Save jonasjuni/b853faf425fe13b445f772a065bd846b to your computer and use it in GitHub Desktop.
Jonas Junior's Draw a Vikings Dash Contest - Feb 2022
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
restorationScopeId: 'app',
home: ParallaxPage(),
);
}
}
class ParallaxPage extends StatelessWidget {
const ParallaxPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 1300,
),
child: const AspectRatio(
aspectRatio: 1,
child: Padding(
padding: EdgeInsets.all(8.0),
child: ParallaxMouse(),
),
),
),
),
);
}
}
class ParallaxMouse extends StatefulWidget {
const ParallaxMouse({Key? key}) : super(key: key);
@override
_ParallaxMouseState createState() => _ParallaxMouseState();
}
class _ParallaxMouseState extends State<ParallaxMouse> {
var _offset = Offset.zero;
var _scale = 0.7;
@override
Widget build(BuildContext context) {
return MouseRegion(
onExit: (event) {
_offset = Offset.zero;
_scale = 0.8;
},
onHover: (event) {
setState(() {
_offset = event.localPosition -
Offset(
(context.size?.width ?? 0) / 2,
(context.size?.height ?? 0) / 2,
);
_scale = 1.1;
});
},
child: Stack(
alignment: Alignment.center,
children: [
//background
Transform(
alignment: FractionalOffset.center,
transform: Matrix4.identity()
..setEntry(3, 2, 0.001)
..rotateX(0.001 * _offset.dy)
..rotateY(-0.001 * _offset.dx),
child: SizedBox.expand(
child: CustomPaint(
painter: HexPainter(),
),
),
),
//Dash
Transform(
alignment: FractionalOffset.center,
transform: Matrix4.identity()
..setEntry(3, 2, 0.001)
..scale(_scale, _scale, _scale)
..rotateX(0.0012 * _offset.dy)
..rotateY(-0.0012 * _offset.dx),
//TODO add custom drawing
child: Image.network('https://i.imgur.com/ykOQV7A.png'),
),
//Eyes
Transform(
alignment: FractionalOffset.center,
transform: Matrix4.identity()
..setEntry(3, 2, 0.001)
..scale(_scale, _scale, _scale)
..rotateX(0.0011 * _offset.dy)
..rotateY(-0.0011 * _offset.dx),
//TODO add custom drawing
child: Image.network('https://i.imgur.com/rRJw8C7.png'),
),
//Helmets
Transform(
alignment: FractionalOffset.center,
transform: Matrix4.identity()
..setEntry(3, 2, 0.001)
..scale(_scale, _scale, _scale)
..rotateX(0.0013 * _offset.dy)
..rotateY(-0.0013 * _offset.dx),
//TODO add custom drawing
child: Image.network('https://i.imgur.com/HmjDVDg.png'),
),
// Wings/ Feathers
Transform(
alignment: FractionalOffset.center,
transform: Matrix4.identity()
..setEntry(3, 2, 0.001)
..scale(_scale, _scale, _scale)
..rotateX(0.0014 * _offset.dy)
..rotateY(-0.0014 * _offset.dx),
//TODO add custom drawing
child: Image.network('https://i.imgur.com/jgvTF8n.png'),
)
],
),
);
}
}
//Twitter nft hex path
class HexPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()..color = Colors.amber;
final path = Path()
..moveTo(size.width * 0.9662593, size.height * 0.3738303)
..cubicTo(
size.width * 0.9297686,
size.height * 0.2912950,
size.width * 0.8872177,
size.height * 0.2120222,
size.width * 0.8390068,
size.height * 0.1367645)
..lineTo(size.width * 0.8234565, size.height * 0.1127245)
..cubicTo(
size.width * 0.8043111,
size.height * 0.08284877,
size.width * 0.7792206,
size.height * 0.05793482,
size.width * 0.7500050,
size.height * 0.03979456)
..cubicTo(
size.width * 0.7207894,
size.height * 0.02165408,
size.width * 0.6881788,
size.height * 0.01074234,
size.width * 0.6545531,
size.height * 0.007852210)
..lineTo(size.width * 0.6272525, size.height * 0.005485856)
..cubicTo(
size.width * 0.5425509,
size.height * -0.001828611,
size.width * 0.4574456,
size.height * -0.001828611,
size.width * 0.3727470,
size.height * 0.005485856)
..lineTo(size.width * 0.3454464, size.height * 0.007852210)
..cubicTo(
size.width * 0.3118187,
size.height * 0.01074234,
size.width * 0.2792121,
size.height * 0.02165408,
size.width * 0.2499955,
size.height * 0.03979456)
..cubicTo(
size.width * 0.2207794,
size.height * 0.05793482,
size.width * 0.1956874,
size.height * 0.08284877,
size.width * 0.1765430,
size.height * 0.1127245)
..lineTo(size.width * 0.1609927, size.height * 0.1369797)
..cubicTo(
size.width * 0.1127828,
size.height * 0.2122373,
size.width * 0.07023040,
size.height * 0.2915102,
size.width * 0.03374012,
size.height * 0.3740454)
..lineTo(size.width * 0.02198989, size.height * 0.4006131)
..cubicTo(size.width * 0.007511800, size.height * 0.4333812, 0,
size.height * 0.4692057, 0, size.height * 0.5054856)
..cubicTo(
0,
size.height * 0.5417662,
size.width * 0.007511800,
size.height * 0.5775895,
size.width * 0.02198989,
size.height * 0.6103582)
..lineTo(size.width * 0.03374012, size.height * 0.6369259)
..cubicTo(
size.width * 0.07023040,
size.height * 0.7194633,
size.width * 0.1127828,
size.height * 0.7987362,
size.width * 0.1609927,
size.height * 0.8739916)
..lineTo(size.width * 0.1765430, size.height * 0.8982467)
..cubicTo(
size.width * 0.1956874,
size.height * 0.9281220,
size.width * 0.2207794,
size.height * 0.9530386,
size.width * 0.2499955,
size.height * 0.9711789)
..cubicTo(
size.width * 0.2792121,
size.height * 0.9893191,
size.width * 0.3118187,
size.height * 1.000231,
size.width * 0.3454464,
size.height * 1.003119)
..lineTo(size.width * 0.3727470, size.height * 1.005486)
..cubicTo(
size.width * 0.4574456,
size.height * 1.012800,
size.width * 0.5425509,
size.height * 1.012800,
size.width * 0.6272525,
size.height * 1.005486)
..lineTo(size.width * 0.6545531, size.height * 1.003119)
..cubicTo(
size.width * 0.6882038,
size.height * 1.000194,
size.width * 0.7208294,
size.height * 0.9892331,
size.width * 0.7500450,
size.height * 0.9710337)
..cubicTo(
size.width * 0.7792656,
size.height * 0.9528342,
size.width * 0.8043411,
size.height * 0.9278584,
size.width * 0.8234565,
size.height * 0.8979241)
..lineTo(size.width * 0.8390068, size.height * 0.8736689)
..cubicTo(
size.width * 0.8872177,
size.height * 0.7984135,
size.width * 0.9297686,
size.height * 0.7191406,
size.width * 0.9662593,
size.height * 0.6366032)
..lineTo(size.width * 0.9780096, size.height * 0.6100355)
..cubicTo(size.width * 0.9924848, size.height * 0.5772669, size.width,
size.height * 0.5414435, size.width, size.height * 0.5051630)
..cubicTo(
size.width,
size.height * 0.4688830,
size.width * 0.9924848,
size.height * 0.4330585,
size.width * 0.9780096,
size.height * 0.4002904)
..lineTo(size.width * 0.9662593, size.height * 0.3738303)
..close();
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment