-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathmain.dart
72 lines (62 loc) · 2.37 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import 'dart:math';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:vector_math/vector_math.dart' as v;
// Look Ma NO WIDGET in Flutter !!!
class Colored extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final random = v.SimplexNoise();
final frames = 200;
canvas.drawPaint(Paint()..color = Colors.black87);
for (double i = 10; i < frames; i += .1) {
canvas.translate(i % .3, i % .6);
canvas.save();
canvas.rotate(pi / i * 25);
final area = Offset(i, i) & Size(i * 10, i * 10);
// Blue trail is made of rectangle
canvas.drawRect(
area,
Paint()
..filterQuality =
FilterQuality.high // Change this to lower render time
..blendMode =
BlendMode.screen // Remove this to see the natural drawing shape
..color =
// Addition of Opacity gives you the fading effect from dark to light
Colors.blue.withRed(i.toInt() * 20 % 11).withOpacity(i / 850));
// Tail particles effect
// Change this to add more fibers
final int tailFibers = (i * 1.5).toInt();
for (double d = 0; d < area.width; d += tailFibers) {
for (double e = 0; e < area.height; e += tailFibers) {
final n = random.noise2D(d, e);
final tail = exp(i / 50) - 5;
final tailWidth = .2 + (i * .11 * n);
canvas.drawCircle(
Offset(d, e),
tailWidth,
Paint()
..color = Colors.red.withOpacity(.4)
..isAntiAlias = true // Change this to lower render time
// Particles accelerate as they fall so we change the blur size for movement effect
..imageFilter = ImageFilter.blur(sigmaX: tail, sigmaY: 0)
..filterQuality =
FilterQuality.high // Change this to lower render time
..blendMode = BlendMode
.screen); // Remove this to see the natural drawing shape
}
}
canvas.restore();
}
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
void main() => RenderingFlutterBinding(
root: RenderPositionedBox(
alignment: Alignment(.1, -.2),
child: RenderCustomPaint(painter: Colored()),
),
);