books
This commit is contained in:
1
assets/draw/p06/p06.dart
Normal file
1
assets/draw/p06/p06.dart
Normal file
@@ -0,0 +1 @@
|
||||
export 'p06_page.dart';
|
||||
28
assets/draw/p06/p06_page.dart
Normal file
28
assets/draw/p06/p06_page.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
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;
|
||||
import 's06.dart' as s6;
|
||||
|
||||
class P06Page extends StatelessWidget {
|
||||
const P06Page({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const DemoShower(
|
||||
srcCodeDir: 'draw/p06',
|
||||
demos: [
|
||||
s1.Paper(),
|
||||
s2.Paper(),
|
||||
s3.Paper(),
|
||||
s4.Paper(),
|
||||
s5.Paper(),
|
||||
s6.Paper(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
56
assets/draw/p06/s01.dart
Normal file
56
assets/draw/p06/s01.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../components/coordinate.dart';
|
||||
|
||||
|
||||
/// create by 张风捷特烈 on 2020/5/1
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
|
||||
class Paper extends StatelessWidget {
|
||||
const Paper({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
child: CustomPaint(
|
||||
// 使用CustomPaint
|
||||
painter: PaperPainter(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PaperPainter extends CustomPainter {
|
||||
|
||||
|
||||
final Coordinate coordinate = Coordinate();
|
||||
PaperPainter();
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
coordinate.paint(canvas, size);
|
||||
canvas.translate(size.width / 2, size.height / 2);
|
||||
|
||||
Path path = Path();
|
||||
|
||||
Paint paint = Paint()
|
||||
..color = Colors.purpleAccent
|
||||
..strokeWidth = 2
|
||||
..style = PaintingStyle.stroke;
|
||||
|
||||
path
|
||||
..lineTo(100, 100)
|
||||
..relativeLineTo(0, -50)
|
||||
..close();
|
||||
|
||||
canvas.drawPath(path, paint);
|
||||
canvas.drawPath(path.shift(Offset(100, 0)), paint);
|
||||
canvas.drawPath(path.shift(Offset(200, 0)), paint);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(CustomPainter oldDelegate) => false;
|
||||
}
|
||||
61
assets/draw/p06/s02.dart
Normal file
61
assets/draw/p06/s02.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../components/coordinate.dart';
|
||||
|
||||
/// create by 张风捷特烈 on 2020/5/1
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
|
||||
class Paper extends StatelessWidget {
|
||||
const Paper({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
child: CustomPaint(
|
||||
// 使用CustomPaint
|
||||
painter: PaperPainter(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PaperPainter extends CustomPainter {
|
||||
final Coordinate coordinate = Coordinate();
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
coordinate.paint(canvas, size);
|
||||
canvas.translate(size.width / 2, size.height / 2);
|
||||
|
||||
Path path = Path();
|
||||
Paint paint = Paint()
|
||||
..color = Colors.purple
|
||||
..style = PaintingStyle.fill;
|
||||
|
||||
path
|
||||
..relativeMoveTo(0, 0)
|
||||
..relativeLineTo(-30, 120)
|
||||
..relativeLineTo(30, -30)
|
||||
..relativeLineTo(30, 30)
|
||||
..close();
|
||||
|
||||
canvas.drawPath(path, paint);
|
||||
|
||||
print(path.contains(Offset(20, 20)));
|
||||
print(path.contains(Offset(0, 20)));
|
||||
|
||||
Rect bounds = path.getBounds();
|
||||
canvas.drawRect(
|
||||
bounds,
|
||||
Paint()
|
||||
..color = Colors.orange
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(CustomPainter oldDelegate) => false;
|
||||
}
|
||||
56
assets/draw/p06/s03.dart
Normal file
56
assets/draw/p06/s03.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../components/coordinate.dart';
|
||||
|
||||
/// create by 张风捷特烈 on 2020/5/1
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
|
||||
|
||||
class Paper extends StatelessWidget {
|
||||
const Paper({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
child: CustomPaint(
|
||||
// 使用CustomPaint
|
||||
painter: PaperPainter(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PaperPainter extends CustomPainter {
|
||||
|
||||
|
||||
final Coordinate coordinate = Coordinate();
|
||||
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
coordinate.paint(canvas, size);
|
||||
canvas.translate(size.width / 2, size.height / 2);
|
||||
|
||||
Path path = Path();
|
||||
Paint paint = Paint()
|
||||
..color = Colors.purple
|
||||
..style = PaintingStyle.fill;
|
||||
path
|
||||
..relativeMoveTo(0, 0)
|
||||
..relativeLineTo(-30, 120)
|
||||
..relativeLineTo(30, -30)
|
||||
..relativeLineTo( 30,30)
|
||||
..close();
|
||||
|
||||
for(int i=0;i<8;i++){
|
||||
canvas.drawPath(path.transform(Matrix4.rotationZ(i*pi/4).storage), paint);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(CustomPainter oldDelegate) => false;
|
||||
}
|
||||
68
assets/draw/p06/s04.dart
Normal file
68
assets/draw/p06/s04.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../components/coordinate.dart';
|
||||
|
||||
|
||||
/// create by 张风捷特烈 on 2020/5/1
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
|
||||
class Paper extends StatelessWidget {
|
||||
const Paper({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
child: CustomPaint(
|
||||
// 使用CustomPaint
|
||||
painter: PaperPainter(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PaperPainter extends CustomPainter {
|
||||
|
||||
|
||||
final Coordinate coordinate= Coordinate();
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
coordinate.paint(canvas, size);
|
||||
canvas.translate(size.width / 2, size.height / 2);
|
||||
|
||||
Path path = Path();
|
||||
Paint paint = Paint();
|
||||
paint
|
||||
..color = Colors.purple
|
||||
..style = PaintingStyle.fill;
|
||||
path
|
||||
..relativeMoveTo(0, 0)
|
||||
..relativeLineTo(-30, 120)
|
||||
..relativeLineTo(30, -30)
|
||||
..relativeLineTo( 30,30)
|
||||
..close();
|
||||
|
||||
|
||||
var pathOval =Path()..addOval(Rect.fromCenter(center: Offset(0, 0),width: 60,height: 60));
|
||||
canvas.drawPath(Path.combine(PathOperation.difference, path, pathOval), paint);
|
||||
|
||||
canvas.translate(120, 0);
|
||||
canvas.drawPath(Path.combine(PathOperation.intersect, path, pathOval), paint);
|
||||
|
||||
canvas.translate(120, 0);
|
||||
canvas.drawPath(Path.combine(PathOperation.union, path, pathOval), paint);
|
||||
|
||||
canvas.translate(-120*3.0, 0);
|
||||
canvas.drawPath(Path.combine(PathOperation.reverseDifference, path, pathOval), paint);
|
||||
|
||||
canvas.translate(-120, 0);
|
||||
canvas.drawPath(Path.combine(PathOperation.xor, path, pathOval), paint);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(CustomPainter oldDelegate) => false;
|
||||
}
|
||||
74
assets/draw/p06/s05.dart
Normal file
74
assets/draw/p06/s05.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../components/coordinate.dart';
|
||||
|
||||
|
||||
|
||||
/// create by 张风捷特烈 on 2020/5/1
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
|
||||
class Paper extends StatelessWidget{
|
||||
const Paper({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
child: CustomPaint(
|
||||
// 使用CustomPaint
|
||||
painter: PaperPainter(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class PaperPainter extends CustomPainter {
|
||||
final Coordinate coordinate = Coordinate();
|
||||
|
||||
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
coordinate.paint(canvas, size);
|
||||
canvas.translate(size.width / 2, size.height / 2);
|
||||
|
||||
Paint paint = Paint()
|
||||
..color = Colors.purple
|
||||
..strokeWidth = 1
|
||||
..style = PaintingStyle.stroke;
|
||||
|
||||
Path path = Path();
|
||||
path
|
||||
..relativeMoveTo(0, 0)
|
||||
..relativeLineTo(-30, 120)
|
||||
..relativeLineTo(30, -30)
|
||||
..relativeLineTo(30, 30)
|
||||
..close();
|
||||
|
||||
path.addOval(Rect.fromCenter(center: Offset.zero, width: 50, height: 50));
|
||||
|
||||
PathMetrics pms = path.computeMetrics();
|
||||
pms.forEach((pm) {
|
||||
print(
|
||||
"---length:-${pm.length}----contourIndex:-${pm.contourIndex}----contourIndex:-${pm.isClosed}----");
|
||||
|
||||
Tangent? tangent = pm.getTangentForOffset(pm.length * 0.5);
|
||||
if(tangent==null) return;
|
||||
print(
|
||||
"---position:-${tangent.position}----angle:-${tangent.angle}----vector:-${tangent.vector}----");
|
||||
|
||||
canvas.drawCircle(
|
||||
tangent.position, 5, Paint()..color = Colors.deepOrange);
|
||||
});
|
||||
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(CustomPainter oldDelegate) => false;
|
||||
}
|
||||
83
assets/draw/p06/s06.dart
Normal file
83
assets/draw/p06/s06.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// create by 张风捷特烈 on 2020/5/1
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
|
||||
class Paper extends StatefulWidget {
|
||||
const Paper({super.key});
|
||||
|
||||
@override
|
||||
_PaperState createState() => _PaperState();
|
||||
}
|
||||
|
||||
class _PaperState extends State<Paper> with SingleTickerProviderStateMixin {
|
||||
late AnimationController _ctrl;
|
||||
double progress = 0.0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_ctrl = AnimationController(
|
||||
duration: Duration(seconds: 3), vsync: this)
|
||||
..forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ctrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
child: CustomPaint(
|
||||
// 使用CustomPaint
|
||||
painter: PaperPainter(progress: _ctrl),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PaperPainter extends CustomPainter {
|
||||
final Animation<double> progress;
|
||||
|
||||
PaperPainter({required this.progress}) : super(repaint: progress);
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
canvas.translate(size.width / 2, size.height / 2);
|
||||
|
||||
Paint paint = Paint()
|
||||
..color = Colors.purple
|
||||
..strokeWidth = 1
|
||||
..style = PaintingStyle.stroke;
|
||||
|
||||
Path path = Path();
|
||||
path
|
||||
..relativeMoveTo(0, 0)
|
||||
..relativeLineTo(-30, 120)
|
||||
..relativeLineTo(30, -30)
|
||||
..relativeLineTo(30, 30)
|
||||
..close();
|
||||
|
||||
path.addOval(Rect.fromCenter(center: Offset.zero, width: 50, height: 50));
|
||||
|
||||
PathMetrics pms = path.computeMetrics();
|
||||
for (PathMetric pm in pms) {
|
||||
Tangent? tangent = pm.getTangentForOffset(pm.length * progress.value);
|
||||
if(tangent ==null) continue;
|
||||
canvas.drawCircle(
|
||||
tangent.position, 5, Paint()..color = Colors.deepOrange);
|
||||
}
|
||||
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(PaperPainter oldDelegate) =>
|
||||
oldDelegate.progress != progress;
|
||||
}
|
||||
Reference in New Issue
Block a user