Download flutter/dev/benchmarks/macrobenchmarks/lib/src/animated_advanced_blend.dart from luom2645/agent-workspace: direct link, hf CLI and curl.
- Browser
- Download file 2.42 kB
-
https://huggingface.co/luom2645/agent-workspace/resolve/main/flutter/dev/benchmarks/macrobenchmarks/lib/src/animated_advanced_blend.dart
- Command line
-
hf download hf://luom2645/agent-workspace/flutter/dev/benchmarks/macrobenchmarks/lib/src/animated_advanced_blend.dart
-
curl -L -o animated_advanced_blend.dart https://huggingface.co/luom2645/agent-workspace/resolve/main/flutter/dev/benchmarks/macrobenchmarks/lib/src/animated_advanced_blend.dart
2.42 kB
| // Copyright 2014 The Flutter Authors. 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'; | |
| class _MultiplyPainter extends CustomPainter { | |
| _MultiplyPainter(this._color); | |
| final Color _color; | |
| void paint(Canvas canvas, Size size) { | |
| const int xDenominator = 2; | |
| const int yDenominator = 10; | |
| final double width = size.width / xDenominator; | |
| final double height = size.height / yDenominator; | |
| for (int y = 0; y < yDenominator; y++) { | |
| for (int x = 0; x < xDenominator; x++) { | |
| final Rect rect = Offset(x * width, y * height) & Size(width, height); | |
| final Paint basePaint = | |
| Paint() | |
| ..color = Color.fromARGB( | |
| (((x + 1) * width) / size.width * 255.0).floor(), | |
| (((y + 1) * height) / size.height * 255.0).floor(), | |
| 255, | |
| 127, | |
| ); | |
| canvas.drawRect(rect, basePaint); | |
| final Paint multiplyPaint = | |
| Paint() | |
| ..color = _color | |
| ..blendMode = BlendMode.multiply; | |
| canvas.drawRect(rect, multiplyPaint); | |
| } | |
| } | |
| } | |
| bool shouldRepaint(CustomPainter oldDelegate) { | |
| return true; | |
| } | |
| } | |
| class AnimatedAdvancedBlend extends StatefulWidget { | |
| const AnimatedAdvancedBlend({super.key}); | |
| State<AnimatedAdvancedBlend> createState() => _AnimatedAdvancedBlendState(); | |
| } | |
| class _AnimatedAdvancedBlendState extends State<AnimatedAdvancedBlend> | |
| with SingleTickerProviderStateMixin { | |
| late final AnimationController controller = AnimationController( | |
| vsync: this, | |
| duration: const Duration(milliseconds: 5000), | |
| ); | |
| late final Animation<double> animation = controller.drive(Tween<double>(begin: 0.0, end: 1.0)); | |
| Color _color = const Color.fromARGB(255, 255, 0, 255); | |
| void initState() { | |
| super.initState(); | |
| controller.repeat(); | |
| animation.addListener(() { | |
| setState(() { | |
| _color = Color.fromARGB((animation.value * 255).floor(), 255, 0, 255); | |
| }); | |
| }); | |
| } | |
| void dispose() { | |
| controller.dispose(); | |
| super.dispose(); | |
| } | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| home: Scaffold(body: CustomPaint(painter: _MultiplyPainter(_color), child: Container())), | |
| ); | |
| } | |
| } | |