This commit is contained in:
toly
2023-12-16 12:40:32 +08:00
parent ab2778a22b
commit 01fdf966c5
593 changed files with 8995 additions and 27753 deletions

1
assets/draw/p10/p10.dart Normal file
View File

@@ -0,0 +1 @@
export 'p10_page.dart';

View File

@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:idraw/components/demo_shower.dart';
import 's01.dart' as s1;
import 's02.dart' as s2;
import 's03.dart' as s3;
import 's04.dart' as s4;
import 's05.dart' as s5;
class P10Page extends StatelessWidget {
const P10Page({super.key});
@override
Widget build(BuildContext context) {
return const DemoShower(
srcCodeDir: 'draw/p10',
demos: [
s1.Paper(),
s2.Paper(),
s3.Paper(),
s4.Paper(),
s5.Paper(),
],
);
}
}

71
assets/draw/p10/s01.dart Normal file
View File

@@ -0,0 +1,71 @@
import 'dart:math';
import 'package:flutter/material.dart';
import '../components/coordinate_pro.dart';
/// create by 张风捷特烈 on 2020-03-19
/// contact me by email 1981462002@qq.com
/// 说明: 纸
class Paper extends StatefulWidget {
final Color color;
final double angle;
const Paper({Key? key, this.color = Colors.lightBlue, this.angle = 30 }) : super(key: key);
@override
_PaperState createState() => _PaperState();
}
class _PaperState extends State<Paper>{
@override
Widget build(BuildContext context) {
return Center(
child: CustomPaint(
size: Size(100, 100),
painter: PicManPainter(color: widget.color, angle : widget.angle), // 背景
),
);
}
}
class PicManPainter extends CustomPainter {
final Color color; // 颜色
final double angle; // 角度(与x轴交角 角度制)
Paint _paint = Paint();
PicManPainter({this.color = Colors.yellowAccent, this.angle = 30});
@override
void paint(Canvas canvas, Size size) {
canvas.clipRect(Offset.zero & size); //剪切画布
final double radius = size.width / 2;
canvas.translate(radius, size.height / 2);
_drawHead(canvas, size);
_drawEye(canvas, radius);
}
//绘制头
void _drawHead(Canvas canvas, Size size) {
var rect = Rect.fromCenter(
center: Offset(0, 0), height: size.width, width: size.height);
var a = angle / 180 * pi;
canvas.drawArc(rect, a, 2 * pi - a.abs() * 2, true, _paint..color = color);
}
//绘制眼睛
void _drawEye(Canvas canvas, double radius) {
canvas.drawCircle(Offset(radius * 0.15, -radius * 0.6), radius * 0.12,
_paint..color = Colors.white);
}
@override
bool shouldRepaint(covariant PicManPainter oldDelegate) =>
oldDelegate.color != color || oldDelegate.angle != angle;
}

87
assets/draw/p10/s02.dart Normal file
View File

@@ -0,0 +1,87 @@
import 'dart:math';
import 'package:flutter/material.dart';
/// create by 张风捷特烈 on 2020/11/2
/// contact me by email 1981462002@qq.com
/// 说明:
///
class Paper extends StatefulWidget {
final Color color;
const Paper({Key? key, this.color = Colors.lightBlue}) : super(key: key);
@override
_PaperState createState() => _PaperState();
}
class _PaperState extends State<Paper> with SingleTickerProviderStateMixin {
late AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
lowerBound: 10,
upperBound: 40,
duration: const Duration(seconds: 1),
vsync: this,
)..repeat(reverse: true);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Center(
child: CustomPaint(
size: Size(100, 100),
painter: PicManPainter(color: widget.color, angle: _controller), // 背景
),
);
}
}
class PicManPainter extends CustomPainter {
final Animation<double> angle; // 角度(与x轴交角 角度制)
final Color color; // 颜色
Paint _paint = Paint();
PicManPainter({this.color = Colors.yellowAccent, required this.angle})
: super(repaint: angle);
@override
void paint(Canvas canvas, Size size) {
canvas.clipRect(Offset.zero & size); //剪切画布
final double radius = size.width / 2;
canvas.translate(radius, size.height / 2);
_drawHead(canvas, size);
_drawEye(canvas, radius);
}
//绘制头
void _drawHead(Canvas canvas, Size size) {
var rect = Rect.fromCenter(
center: Offset(0, 0), height: size.width, width: size.height);
var a = angle.value / 180 * pi;
canvas.drawArc(rect, a, 2 * pi - a.abs() * 2, true, _paint..color = color);
}
//绘制眼睛
void _drawEye(Canvas canvas, double radius) {
canvas.drawCircle(Offset(radius * 0.15, -radius * 0.6), radius * 0.12,
_paint..color = Colors.white);
}
@override
bool shouldRepaint(covariant PicManPainter oldDelegate) {
print('-----shouldRepaint---------');
return true;
}
}

94
assets/draw/p10/s03.dart Normal file
View File

@@ -0,0 +1,94 @@
import 'dart:math';
import 'package:flutter/material.dart';
/// create by 张风捷特烈 on 2020/11/2
/// contact me by email 1981462002@qq.com
/// 说明:
///
class Paper extends StatefulWidget {
final Color color;
const Paper({Key? key, this.color = Colors.lightBlue}) : super(key: key);
@override
_PaperState createState() => _PaperState();
}
class _PaperState extends State<Paper> with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<Color?> _colorCtrl;
late Animation<double> _angleCtrl;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 1),
vsync: this,
);
_angleCtrl = _controller.drive(Tween(begin: 10, end: 40));
_colorCtrl =
ColorTween(begin: Colors.blue, end: Colors.red).animate(_controller);
_controller.repeat(reverse: true);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Center(
child: CustomPaint(
size: Size(100, 100),
painter: PicManPainter(
color: _colorCtrl, angle: _angleCtrl, repaint: _controller),
),
);
}
}
class PicManPainter extends CustomPainter {
final Animation<double> repaint;
final Animation<double> angle;
final Animation<Color?> color;
Paint _paint = Paint();
PicManPainter({ required this.repaint,required this.color,required this.angle})
: super(repaint: repaint);
@override
void paint(Canvas canvas, Size size) {
canvas.clipRect(Offset.zero & size); //剪切画布
final double radius = size.width / 2;
canvas.translate(radius, size.height / 2);
_drawHead(canvas, size);
_drawEye(canvas, radius);
}
//绘制头
void _drawHead(Canvas canvas, Size size) {
var rect = Rect.fromCenter(
center: Offset(0, 0), height: size.width, width: size.height);
var a = angle.value / 180 * pi;
canvas.drawArc(
rect, a, 2 * pi - a.abs() * 2, true, _paint..color = color.value??Colors.black);
}
//绘制眼睛
void _drawEye(Canvas canvas, double radius) {
canvas.drawCircle(Offset(radius * 0.15, -radius * 0.6), radius * 0.12,
_paint..color = Colors.white);
}
@override
bool shouldRepaint(covariant PicManPainter oldDelegate)=> oldDelegate.repaint != repaint;
}

82
assets/draw/p10/s04.dart Normal file
View File

@@ -0,0 +1,82 @@
import 'dart:math';
import 'package:flutter/material.dart';
/// create by 张风捷特烈 on 2020/11/2
/// contact me by email 1981462002@qq.com
/// 说明:
///
class Paper extends StatefulWidget {
final Color color;
const Paper({Key? key, this.color = Colors.lightBlue}) : super(key: key);
@override
_PaperState createState() => _PaperState();
}
class _PaperState extends State<Paper> with SingleTickerProviderStateMixin {
late AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 1),
vsync: this,
);
_controller.repeat(reverse: true);
}
@override
Widget build(BuildContext context) {
return Center(
child: CustomPaint(
size: Size(100, 100),
painter: PicManPainter(_controller), // 背景
),
);
}
}
class PicManPainter extends CustomPainter {
final Animation<double> repaint; // 角度(与x轴交角 角度制)
final ColorTween colorTween = ColorTween(begin: Colors.blue, end: Colors.red);
final Tween<double> angleTween = Tween(begin: 10.0, end: 40.0);
Paint _paint = Paint();
PicManPainter(this.repaint)
: super(repaint: repaint);
@override
void paint(Canvas canvas, Size size) {
canvas.clipRect(Offset.zero & size); //剪切画布
final double radius = size.width / 2;
canvas.translate(radius, size.height / 2);
_drawHead(canvas, size);
_drawEye(canvas, radius);
}
//绘制头
void _drawHead(Canvas canvas, Size size) {
var rect = Rect.fromCenter(
center: Offset(0, 0), height: size.width, width: size.height);
double a = angleTween.evaluate(repaint) / 180 * pi;
canvas.drawArc(rect, a, 2 * pi - a.abs() * 2, true,
_paint..color = colorTween.evaluate(repaint)??Colors.black);
}
//绘制眼睛
void _drawEye(Canvas canvas, double radius) {
canvas.drawCircle(Offset(radius * 0.15, -radius * 0.6), radius * 0.12,
_paint..color = Colors.white);
}
@override
bool shouldRepaint(covariant PicManPainter oldDelegate) =>
oldDelegate.repaint != repaint;
}

100
assets/draw/p10/s05.dart Normal file
View File

@@ -0,0 +1,100 @@
import 'dart:math';
import 'package:flutter/material.dart';
/// create by 张风捷特烈 on 2020/11/2
/// contact me by email 1981462002@qq.com
/// 说明:
///
class Paper extends StatefulWidget {
final Color color;
const Paper({Key? key, this.color = Colors.lightBlue}) : super(key: key);
@override
_PaperState createState() => _PaperState();
}
class _PaperState extends State<Paper> with SingleTickerProviderStateMixin {
late AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 1),
vsync: this,
);
_controller.repeat(reverse: true);
}
@override
Widget build(BuildContext context) {
return Center(
child: CustomPaint(
size: Size(100, 100), painter: PicManPainter(_controller), // 背景
),
);
}
}
class PicManPainter extends CustomPainter {
final Animation<double> repaint;
// 创建 Tween
final ColorDoubleTween tween = ColorDoubleTween(
begin: ColorDouble(color: Colors.blue, value: 10),
end: ColorDouble(color: Colors.red, value: 10));
Paint _paint = Paint();
PicManPainter(this.repaint) : super(repaint: repaint);
@override
void paint(Canvas canvas, Size size) {
canvas.clipRect(Offset.zero & size); //剪切画布
final double radius = size.width / 2;
canvas.translate(radius, size.height / 2);
_drawHead(canvas, size);
_drawEye(canvas, radius);
}
//绘制头
void _drawHead(Canvas canvas, Size size) {
var rect = Rect.fromCenter(
center: Offset(0, 0), height: size.width, width: size.height);
var a = tween.evaluate(repaint).value / 180 * pi;
canvas.drawArc(rect, a, 2 * pi - a.abs() * 2, true,
_paint..color = tween.evaluate(repaint).color ?? Colors.black);
}
//绘制眼睛
void _drawEye(Canvas canvas, double radius) {
canvas.drawCircle(Offset(radius * 0.15, -radius * 0.6), radius * 0.12,
_paint..color = Colors.white);
}
@override
bool shouldRepaint(covariant PicManPainter oldDelegate) =>
oldDelegate.repaint != repaint;
}
class ColorDouble {
final Color? color;
final double value;
ColorDouble({this.color = Colors.blue, this.value = 0});
}
class ColorDoubleTween extends Tween<ColorDouble> {
ColorDoubleTween({required ColorDouble begin, required ColorDouble end})
: super(begin: begin, end: end);
@override
ColorDouble lerp(double t) => ColorDouble(
color: Color.lerp(begin?.color, end?.color, t),
value: (begin!.value + (end!.value - begin!.value) * t),
);
}