Skip to content

Commit

Permalink
绘制集录添加新案例
Browse files Browse the repository at this point in the history
  • Loading branch information
toly1994328 committed Mar 27, 2022
1 parent 59f8125 commit 5fb9805
Show file tree
Hide file tree
Showing 23 changed files with 741 additions and 144 deletions.
18 changes: 18 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.toly1994.flutter_unit">
<uses-permission android:name="android.permission.INTERNET"/>
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="smsto" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
<application
android:label="flutter_unit"
android:icon="@mipmap/logo">
Expand Down
27 changes: 27 additions & 0 deletions assets/data/gallery_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"image": "assets/images/anim_draw.webp",
"name": "基础绘制",
"info": "收录一些基础图形绘制案例,这些案例对初涉绘制的编程者会非常友好。通过这些案例,可以学会点、线、矩形、圆、圆弧、文字、图片等基本图形的绘制方法,了解 Canvas、Paint、Path 等绘制中核心对象的使用。"
},
{
"image": "assets/images/draw_bg3.webp",
"name": "动画手势",
"info": "收录一些动画和手势的绘制案例,这些案例会让绘制更具有操作性。通过这些案例,可以学会动画和手势的使用,如滑动、旋转、缩放、移动等效果,让绘制不再只是静态展现。"
},
{
"image": "assets/images/base_draw.webp",
"name": "粒子绘制",
"info": "收录一些粒子相关的绘制案例,这些案例将是绘制的顶级操作。通过这些案例,可以学会如何使用粒子来绘制惊艳的视觉效果,如粒子时钟、粒子爆炸、粒子背景等效果,让绘制拥有无限可能。"
},
{
"image": "assets/images/draw_bg4.webp",
"name": "趣味绘制",
"info": "收录一些比较有趣的绘制案例,让我们一起在这里一起体验绘制的乐趣、编程的乐趣和智慧的乐趣吧。"
},
{
"image": "assets/images/caver.webp",
"name": "艺术画廊",
"info": "收录一些殿堂级的绘制案例,这些案例将是绘制的巅峰作品,它们的没有任何的实用性,也不为任何需求而生,它们仅是因为存在而存在,是人类智慧和表达的媒介,称谓艺术。"
}
]
2 changes: 0 additions & 2 deletions lib/app/blocs/color_change_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ class ColorChangeCubit extends Cubit<SelectTab> {
color: color,
family: family ?? state.family,
));


}
35 changes: 0 additions & 35 deletions lib/app/res/str_unit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,4 @@ class StrUnit {
static const String version = 'V1.5.1';
static const String appName = 'Flutter Unit';

static const String galleryInfo = """
[
{
"image":"assets/images/anim_draw.webp",
"name":"基础绘制",
"info":"收录一些基础图形绘制案例,这些案例对初涉绘制的编程者会非常友好。通过这些案例,可以学会点、线、矩形、圆、圆弧、文字、图片等基本图形的绘制方法,了解 Canvas、Paint、Path 等绘制中核心对象的使用。"
},
{
"image":"assets/images/draw_bg3.webp",
"name":"动画手势",
"info":"收录一些动画和手势的绘制案例,这些案例会让绘制更具有操作性。通过这些案例,可以学会动画和手势的使用,如滑动、旋转、缩放、移动等效果,让绘制不再只是静态展现。"
},
{
"image":"assets/images/base_draw.webp",
"name":"粒子绘制",
"info":"收录一些粒子相关的绘制案例,这些案例将是绘制的顶级操作。通过这些案例,可以学会如何使用粒子来绘制惊艳的视觉效果,如粒子时钟、粒子爆炸、粒子背景等效果,让绘制拥有无限可能。"
},
{
"image":"assets/images/draw_bg4.webp",
"name":"趣味绘制",
"info":"收录一些比较有趣的绘制案例,让我们一起在这里一起体验绘制的乐趣、编程的乐趣和智慧的乐趣吧。"
},
{
"image":"assets/images/caver.webp",
"name":"艺术画廊",
"info":"收录一些殿堂级的绘制案例,这些案例将是绘制的巅峰作品,它们的没有任何的实用性,也不为任何需求而生,它们仅是因为存在而存在,是人类智慧和表达的媒介,称谓艺术。"
}
]
""";


}
2 changes: 1 addition & 1 deletion lib/app/views/about/version_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class VersionInfo extends StatelessWidget {
);
}

_launchURL(String url) async {
void _launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
Expand Down
14 changes: 2 additions & 12 deletions lib/app/views/navigation/bloc_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_unit/app/blocs/global/global_bloc.dart';
import 'package:flutter_unit/app/blocs/global/global_event.dart';
import 'package:flutter_unit/bloc_exp.dart';
import 'package:flutter_unit/painter_system/bloc/gallery_unit/bloc.dart';
import 'package:flutter_unit/point_system/blocs/point_system_bloc.dart';
import 'package:flutter_unit/widget_system/repositories/repositories.dart';
import 'package:flutter_unit/user_system/bloc/authentic/bloc.dart';
Expand Down Expand Up @@ -38,36 +39,25 @@ class _BlocWrapperState extends State<BlocWrapper> {
@override
Widget build(BuildContext context) {
return MultiBlocProvider(
//使用MultiBlocProvider包裹
providers: [
//Bloc提供器
BlocProvider<GlobalBloc>(create: (_) => GlobalBloc(storage)..add(const EventInitApp())),

BlocProvider<WidgetsBloc>(create: (_) => WidgetsBloc(repository: repository)),

BlocProvider<WidgetDetailBloc>(
create: (_) => WidgetDetailBloc(repository: repository)),

BlocProvider<CategoryBloc>(
create: (_) => categoryBloc),

BlocProvider<LikeWidgetBloc>(
create: (_) => LikeWidgetBloc(repository: repository)),

BlocProvider<RegisterBloc>(create: (_) => RegisterBloc()),

BlocProvider<LoginBloc>(create: (_) => LoginBloc(authenticBloc: authBloc)),
BlocProvider<AuthenticBloc>(create: (_) => authBloc),

BlocProvider<CategoryWidgetBloc>(
create: (_) => CategoryWidgetBloc(categoryBloc: categoryBloc)),

BlocProvider<SearchBloc>(
create: (_) => SearchBloc(repository: repository)),

BlocProvider<PointBloc>(create: (_) => PointBloc()),
BlocProvider<UpdateBloc>(create: (_) => UpdateBloc()),

BlocProvider<GalleryUnitBloc>(create: (_) => GalleryUnitBloc()..loadGalleryInfo()),
BlocProvider<PointCommentBloc>(create: (_) => PointCommentBloc()),
], child: widget.child);
}
Expand Down
16 changes: 8 additions & 8 deletions lib/painter_system/anim/circle_halo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ class CircleHaloPainter extends CustomPainter {
Path result =
Path.combine(PathOperation.difference, circlePath, circlePath2);

List<Color> colors = const[
Color(0xFFF60C0C),
Color(0xFFF3B913),
Color(0xFFE7F716),
Color(0xFF3DF30B),
Color(0xFF0DF6EF),
Color(0xFF0829FB),
Color(0xFFB709F4),
List<Color> colors = [
const Color(0xFFF60C0C),
const Color(0xFFF3B913),
const Color(0xFFE7F716),
const Color(0xFF3DF30B),
const Color(0xFF0DF6EF),
const Color(0xFF0829FB),
const Color(0xFFB709F4),
];
colors.addAll(colors.reversed.toList());
final List<double> pos =
Expand Down
1 change: 1 addition & 0 deletions lib/painter_system/anim/curve_shower/anim_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AnimPainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {

canvas.translate(0, size.height);

_drawAxis(canvas,size);
Expand Down
5 changes: 1 addition & 4 deletions lib/painter_system/anim/curve_shower/curve_anim_shower.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ class _CurveAnimShowerState extends State<CurveAnimShower>
padding: const EdgeInsets.all(30.0),
child: CustomPaint(
painter: AnimPainter(points),
size: const Size(
200,
200,
),
size: const Size(200, 200),
)),
],
),
Expand Down
108 changes: 108 additions & 0 deletions lib/painter_system/anim/rotate_by_point/angle_panter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import 'dart:math';

import 'package:dash_painter/dash_painter.dart';
import 'package:flutter/material.dart';

import 'line.dart';

class AnglePainter extends CustomPainter {
final DashPainter dashPainter = const DashPainter(span: 4, step: 4);

AnglePainter({required this.line}) : super(repaint: line);

final Paint pointPaint = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1;

final Paint helpPaint = Paint()
..style = PaintingStyle.stroke
..color = Colors.lightBlue
..strokeWidth = 1;

final TextPainter textPainter = TextPainter(
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
);

final Line line;

@override
void paint(Canvas canvas, Size size) {
canvas.translate(size.width / 2, size.height / 2);
drawHelp(canvas, size);
line.paint(canvas);
}

void drawHelp(Canvas canvas, Size size) {
Path helpPath = Path()
..moveTo(-size.width / 2, 0)
..relativeLineTo(size.width, 0)
..moveTo(0, -size.height / 2)
..relativeLineTo(0, size.height);
dashPainter.paint(canvas, helpPath, helpPaint);

drawHelpText('0°', canvas, Offset(size.width / 2 - 20, 0));
drawHelpText('p0', canvas, line.start.translate(-20, 0));
drawHelpText('p1', canvas, line.end.translate(-20, 0));

// drawHelpText('p2', canvas, Offset(60, 40).translate(10, 0));
// drawAnchor(canvas, Offset(60, 40));
drawAnchor(canvas, line.percent(0.2));
// drawAnchor(canvas, line.percent(0.5));

// drawAnchor(canvas, line.percent(0.8));

drawHelpText(
'角度: ${(line.positiveRad * 180 / pi).toStringAsFixed(2)}°',
canvas,
Offset(
-size.width / 2 + 10,
-size.height / 2 + 10,
),
);



// canvas.drawArc(
// Rect.fromCenter(center: line.start, width: 20, height: 20),
// 0,
// line.positiveRad,
// false,
// helpPaint,
// );

// canvas.save();
// Offset center = const Offset(60, 60);
// canvas.translate(center.dx, center.dy);
// canvas.rotate(line.positiveRad);
// canvas.translate(-center.dx, -center.dy);
// canvas.drawCircle(center, 4, helpPaint);
// canvas.drawRect(
// Rect.fromCenter(center: center, width: 30, height: 60), helpPaint);
// canvas.restore();
}

void drawAnchor(Canvas canvas, Offset offset) {
canvas.drawCircle(offset, 4, pointPaint..style = PaintingStyle.stroke);
canvas.drawCircle(offset, 2, pointPaint..style = PaintingStyle.fill);
}

void drawHelpText(
String text,
Canvas canvas,
Offset offset, {
Color color = Colors.lightBlue,
}) {
textPainter.text = TextSpan(
text: text,
style: TextStyle(fontSize: 12, color: color),
);
textPainter.layout(maxWidth: 200);
textPainter.paint(canvas, offset);
}

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}
71 changes: 71 additions & 0 deletions lib/painter_system/anim/rotate_by_point/line.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Line with ChangeNotifier {
Line({
this.start = Offset.zero,
this.end = Offset.zero,
});

Offset start;
Offset end;

final Paint pointPaint = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1;

void paint(Canvas canvas) {
canvas.drawLine(start, end, pointPaint);
drawAnchor(canvas, start);
drawAnchor(canvas, end);
}

double get rad => (end - start).direction;

double get positiveRad => rad < 0 ? 2 * pi + rad : rad;

double get length => (end - start).distance;

void drawAnchor(Canvas canvas, Offset offset) {
canvas.drawCircle(offset, 4, pointPaint..style = PaintingStyle.stroke);
canvas.drawCircle(offset, 2, pointPaint..style = PaintingStyle.fill);
}

double detaRotate = 0;

void rotate(double rotate, {Offset? centre}) {
detaRotate = rotate - detaRotate;
centre = centre ?? start;
Line p2p0 = Line(start: centre, end: start);
Line p2p1 = Line(start: centre, end: end);
p2p0._rotateByStart(detaRotate);
p2p1._rotateByStart(detaRotate);
start = p2p0.end;
end = p2p1.end;
detaRotate = rotate;
notifyListeners();
}



Offset percent(double percent){
return Offset(
length*percent*cos(rad),
length*percent*sin(rad),
)+start;
}

void _rotateByStart(double rotate) {
end = Offset(
length * cos(rad + rotate),
length * sin(rad + rotate),
) +
start;
}

void tick() {
notifyListeners();
}
}
Loading

0 comments on commit 5fb9805

Please sign in to comment.