flutter 画转盘
import 'package:flutter/material.dart';
import 'dart:math';const double spacingAngle = 45.0; // 每两个文字之间的角度
// 自定义绘制器,ArcTextPainter 用于在圆弧上绘制文字
class ArcTextPainter extends CustomPainter {final double rotationAngle; // 动画旋转角度final double strokeWidth; // 圆环的宽度final List<String> text; // 文字列表final double curIndex; // 当前旋转进度ArcTextPainter({required this.rotationAngle,required this.strokeWidth,required this.text,required this.curIndex,});@overridevoid paint(Canvas canvas, Size size) {final radius = size.width / 2; // 圆的半径final center = Offset(size.width / 2, size.height / 2); // 圆心的坐标// 创建用于绘制圆弧的画笔final paint = Paint()..color = Colors.grey.shade300 // 圆弧的颜色..strokeWidth = strokeWidth // 圆弧的宽度..style = PaintingStyle.stroke; // 画笔样式为描边// 计算圆弧的矩形区域final arcRect = Rect.fromCircle(center: center, radius: radius - strokeWidth / 2);canvas.drawArc(arcRect, pi, pi, false, paint); // 绘制圆弧// 创建用于绘制箭头的画笔final arrowPaint = Paint()..color = Colors.purple // 箭头的颜色..style = PaintingStyle.fill; // 画笔样式为填充// 定义箭头的路径final arrowPath = Path();arrowPath.moveTo(center.dx, center.dy - radius + strokeWidth / 2); // 箭头起点arrowPath.lineTo(center.dx - 10, center.dy - radius + strokeWidth / 2 + 20); // 箭头的左边arrowPath.lineTo(center.dx + 10, center.dy - radius + strokeWidth / 2 + 20); // 箭头的右边arrowPath.close(); // 结束路径canvas.drawPath(arrowPath, arrowPaint); // 绘制箭头// 绘制圆弧上的文字_drawTextAlongArc(canvas, center, radius - strokeWidth / 2);}// 在圆弧上绘制文字void _drawTextAlongArc(Canvas canvas, Offset center, double radius) {final textPainter = TextPainter(textAlign: TextAlign.center, // 文字对齐方式为居中textDirection: TextDirection.ltr, // 文字方向为从左到右);// 遍历所有文字并绘制for (int i = 0; i < text.length; i++) {// 计算当前文字的角度double angle = (i - curIndex) * spacingAngle * (pi / 180) - pi/2;// print("angle:${i} ${angle*180/pi}");// 检查文字是否在可视范围内if (angle >= -pi && angle <= 0) {// 计算文字的位置final x = center.dx + radius * cos(angle); // x 坐标final y = center.dy + radius * sin(angle); // y 坐标canvas.save(); // 保存当前画布状态canvas.translate(x, y); // 移动画布到文字的位置// 设置文字的样式和内容textPainter.text = TextSpan(text: text[i],style: TextStyle(fontSize: 14, color: Colors.black), // 文字的样式);textPainter.layout(); // 计算文字的大小// 计算文字的实际可见区域double visibleFraction = _calculateVisibleFraction(angle);if (visibleFraction < 1.0) {// 如果文字不完全可见,则应用裁剪遮罩canvas.clipRect(Rect.fromLTWH(-textPainter.width / 2, // 左上角 x 坐标-textPainter.height / 2, // 左上角 y 坐标textPainter.width, // 文字的宽度textPainter.height, // 文字的高度));}textPainter.paint(canvas, Offset(-textPainter.width / 2, -textPainter.height / 2)); // 绘制文字canvas.restore(); // 恢复画布状态}}}// 计算文字的可见比例double _calculateVisibleFraction(double angle) {// 文字显示的比例,确保在 [-pi, 0] 范围内显示完全if (angle < -pi / 2) {return max(0, (angle + pi) / (pi / 2)); // 文字被遮挡的部分} else if (angle > 0) {return max(0, (-angle) / (pi / 2)); // 文字被遮挡的部分}return 1.0; // 文字完全可见}@overridebool shouldRepaint(CustomPainter oldDelegate) => true; // 是否需要重新绘制
}// ArcTextExample 是一个示例 widget,用于展示自定义绘制的效果
class ArcTextExample extends StatefulWidget {final double strokeWidth; // 圆环的宽度final List<String> text; // 文字列表final int initialIndex; // 初始索引final double animationDuration; // 动画持续时间const ArcTextExample({Key? key,required this.strokeWidth,required this.text,required this.initialIndex,required this.animationDuration,}) : super(key: key);@override_ArcTextExampleState createState() => _ArcTextExampleState();
}class _ArcTextExampleState extends State<ArcTextExample>with SingleTickerProviderStateMixin {late AnimationController _controller; // 动画控制器late Animation<double> _animation; // 动画double curIndex = 0.0; // 保存当前旋转的进度bool isAnimating = false; // 标记动画是否正在进行final TextEditingController indexController = TextEditingController(); // 目标索引的文本控制器final TextEditingController durationController = TextEditingController(); // 动画持续时间的文本控制器@overridevoid initState() {super.initState();// 初始化文本控制器的值indexController.text = widget.initialIndex.toString();durationController.text = widget.animationDuration.toString();// 计算初始旋转角度double initialAngle = ( - widget.initialIndex ) * spacingAngle * (pi / 180) - pi / 2;curIndex = widget.initialIndex.toDouble(); // 初始化时 curIndex 是初始索引// 创建动画控制器_controller = AnimationController(duration: Duration(seconds: widget.animationDuration.toInt()), // 设置动画的持续时间vsync: this, // 与当前的 TickerProvider 绑定);// print("initialAngle: ${initialAngle*180/pi}");// 创建动画_animation = Tween<double>(begin: initialAngle, // 动画开始的角度end: initialAngle + 2 * pi, // 动画结束的角度).animate(_controller)..addListener(() {setState(() {print("_animation.value: ${_animation.value * 180 / pi}");// 更新当前角度对应的索引范curIndex = (-(_animation.value + pi / 2) * (180 / pi)) / spacingAngle;print("Current Index: ${curIndex.toStringAsFixed(2)}"); // 打印当前索引});});}@overridevoid dispose() {_controller.dispose(); // 释放动画控制器资源indexController.dispose(); // 释放目标索引的文本控制器资源durationController.dispose(); // 释放动画持续时间的文本控制器资源super.dispose();}// 旋转到目标索引void rotateToIndex(int targetIndex, double duration) {if(targetIndex != curIndex){setState(() {if (isAnimating) {// 如果正在进行动画,则停止并重置_controller.stop();isAnimating = false;}_controller.duration = Duration(seconds: duration.toInt()); // 设置动画的持续时间double startAngle = (-curIndex) * spacingAngle * (pi / 180) - pi / 2; // 使用当前索引角度作为起始角度double targetAngle = (-targetIndex) * spacingAngle * (pi / 180) - pi / 2; // 计算目标角度print("开始度数: ${startAngle * 180/pi} 结束度数:${targetAngle * 180/pi}");double endAngle;// 确定旋转方1if (targetAngle < 0) {// 顺时针旋转endAngle = startAngle + targetAngle;} else {// 逆时针旋转endAngle = startAngle - targetAngle;}_animation = Tween<double>(begin: startAngle, // 动画开始的角度end: targetAngle, // 动画结束的角度).animate(_controller);isAnimating = true; // 标记动画为进行中_controller.reset(); // 重置动画控制_controller.forward(); // 开始动画});}}@overrideWidget build(BuildContext context) {return Scaffold(body: Column(children: [SizedBox(height: 140), // 上部间距Center(child: CustomPaint(size: Size(300, 200), // 设置圆弧的大小painter: ArcTextPainter(rotationAngle: _animation.value, // 当前旋转角度strokeWidth: widget.strokeWidth, // 圆环的宽度text: widget.text, // 文字列表curIndex: curIndex, // 当前旋转进度),),),SizedBox(height: 20), // 下部间距Padding(padding: const EdgeInsets.symmetric(horizontal: 20.0), // 水平内边距child: Column(children: [// 目标索引的输入框TextField(controller: indexController,decoration: InputDecoration(labelText: 'Target Index', // 输入框标签),keyboardType: TextInputType.number, // 键盘类型为数字),// 动画持续时间的输入框TextField(controller: durationController,decoration: InputDecoration(labelText: 'Animation Duration (seconds)', // 输入框标签),keyboardType: TextInputType.number, // 键盘类型为数字),SizedBox(height: 20), // 输入框和按钮之间的间距// 旋转按钮ElevatedButton(onPressed: () {// 获取目标索引和动画持续时间int targetIndex = int.tryParse(indexController.text) ?? 0;double duration = double.tryParse(durationController.text) ?? 10.0;// if (isAnimating) {// // 如果动画正在进行,停止并保存当前进度// _controller.stop();// curIndex = (-(_animation.value + pi / 2) * (180 / pi)) / spacingAngle; // 保存当前进度为 curIndex// _controller.reset(); // 重置动画控制器// }// 旋转到目标索引rotateToIndex(targetIndex, duration);},child: Text('Rotate to Index'), // 按钮文本),],),),],),);}
}void main() {runApp(MaterialApp(home: ArcTextExample(strokeWidth: 100.0, // 圆环的宽度text: List.generate(11, (i) => '第$i层'), // 文字列表initialIndex: 3, // 初animationDuration: 10.0, // 默认动画时间为10秒),));
}
相关文章:

flutter 画转盘
import package:flutter/material.dart; import dart:math;const double spacingAngle 45.0; // 每两个文字之间的角度 // 自定义绘制器,ArcTextPainter 用于在圆弧上绘制文字 class ArcTextPainter extends CustomPainter {final double rotationAngle; // 动画旋…...

图像识别,图片线条检测
import cv2 import numpy as np # 读取图片 img cv2.imread(1.png)# 灰度化 gray cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)# 边缘检测 edges cv2.Canny(gray, 100, 200) 当某个像素点的梯度强度低于 threshold1 时,该像素点被认为是非边缘;当梯度强度…...
python crawler web page
npm install or pip install 插件 import json import time from openpyxl import load_workbook from pip._vendor import requests from bs4 import BeautifulSoup import pandas as pd import re import xlsxwriter 設置request header header {user-agent: Mozilla/5.0…...

基于QT实现的TCP连接的网络通信(客户端)
上篇介绍了QT实现网络通信的服务器端,还没看服务器的朋友们先去上篇了解,这篇我来实现一下客户端的实现。 首先还是新建一个项目 选择mainwindow类 在通信前将.pro文件的第一行代码中追加network 窗口搭建 在mainwindow.ui中完成一下窗口的搭建 首先在…...

Vue2中watch与Vue3中watch对比
上一节说到了 computed计算属性对比 ,虽然计算属性在大多数情况下更合适,但有时也需要一个自定义的侦听器。这就是为什么 Vue 通过 watch 选项提供了一个更通用的方法,来响应数据的变化。当需要在数据变化时执行异步或开销较大的操作时&#…...
Web 3 一些常见术语
目录 Provider 提供者Signer 签名者Transaction 交易Contract 合约Receipt 收据 首先,从高层次上对可用对象的类型及其负责的内容有一个基本的了解是很有用的。 Provider 提供者 一个 Provider 是与区块链的只读连接,允许查询区块链状态,例…...
揭开数据分析中的规范性分析:从入门到精通
目录 引言1. 规范性分析的基本概念2. 规范性分析的方法论2.1 线性规划:资源利用最大化2.2 决策树分析:直观的选择路径2.3 贝叶斯网络:应对不确定性的利器2.4 多目标优化:平衡多重目标的艺术 3. 规范性分析的实际应用3.1 商业决策中…...

Linux文件IO
目录 前言 一.文件操作 系统调用接口 1.打开文件 2.关闭文件 3.读取文件 4.写入文件 二.文件描述符 重定向 三.动静态库 前言 在Linux操作系统中,文件I/O是一个核心概念,涉及如何读写文件、与设备通信以及如何管理数据流。Linux下一切皆文件, …...
ccfcsp-202309(1、2、3)
202309-1 坐标变换(其一) #include <bits/stdc.h> using namespace std; int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n, m;cin >> n >> m;int x, y;int opx 0, opy 0;for(int i 0; i < n; i){cin &g…...

数据结构--数据结构概述
一、数据结构三要素 1. 数据的逻辑结构 数据的逻辑结构是指数据元素之间的关系和组织方式,通常分为线性结构和非线性结构。 线性结构:例如线性表,其中数据元素按照顺序排列,彼此之间存在一对一的关系。 非线性结构:…...
Spring中的BeanFactoryAware
BeanFactoryAware 是 Spring 框架中的一个接口,用于在 Spring 容器中获取 BeanFactory 实例。实现这个接口的类可以在其属性被设置后获取到 BeanFactory,从而可以访问 Spring 容器中的其他 bean。 BeanFactoryAware 接口概述 BeanFactoryAware 接口位于…...
Neo4j service is not installed
问题: Starting Neo4j. Neo4j service is not installed Unable to start. See user log for details. Run with --verbose for a more detailed error message.解决: neo4j windows-service install neo4j start ok了...
LeetCode 3132.找出与数组相加的整数 II:排序+3次尝试(nlog n)
【LetMeFly】3132.找出与数组相加的整数 II:排序3次尝试(nlog n) 力扣题目链接:https://leetcode.cn/problems/find-the-integer-added-to-array-ii/ 给你两个整数数组 nums1 和 nums2。 从 nums1 中移除两个元素,并且所有其他元素都与变量…...

微信小程序--26(全局配置-1)
一、全局配置文件 1.标志 app.json 2.配置项 pages 记录当前小程序所有页面的存放路径 window 全局配置小程序窗口配置 tabBar 设置小程序底部的tabBar效果 style 是否启用新版本的组将样式 3.window 导航栏区域 navigationBar …...

汽车4S店管理系统-计算机毕设Java|springboot实战项目
🍊作者:计算机毕设残哥 🍊简介:毕业后就一直专业从事计算机软件程序开发,至今也有8年工作经验。擅长Java、Python、微信小程序、安卓、大数据、PHP、.NET|C#、Golang等。 擅长:按照需求定制化开发项目、 源…...

bug的常见排查和分析思路以及相关的原因分类
作为开发人员,经常会收到来自用户和QA,领导反馈的各种问题。 为了快速问题,我们有时需要站在更高的角度,更全面的看待问题。才能更快锁定问题。 具体的bug还需要结合企业实际业务情况,相关的框架,依赖库&…...

Nature:7个提升科研产出的实用建议
我是娜姐 迪娜学姐 ,一个SCI医学期刊编辑,探索用AI工具提效论文写作和发表。 一个值得思考的问题是:层出不穷的效率工具到底是提升还是降低了科研产出? 大学教授萨拉 (Sara) 描述了她典型的工作日场景:"…...

react-native从入门到实战系列教程-页面之间的跳转
路由的跳转,是app开发中需要处理的问题,一个页面不可能装下那么多的内容。在react-native中,我们使用的路由组件跟reactjs中还是有区别的,这里贴出官网的文档:https://reactnavigation.org/docs/navigating 实现效果 安装 按照官网的指导安装即可。代码实现 app.jsx中改造…...

HarmonyOS应用开发者高级认证(一)
1、依次点击A、B、C、D四个按钮,其中不会触发UI刷新的是: 答案: Button("C").onClick(() > {this.nameList[0].name "Jim"})分析:直接更新非一级数据不会触发UI刷新 2、如果要实现Row组件内的子元素均匀…...

【网络】套接字(socket)编程——UDP版
1.socket 1.1.什么是socket Socket 的中文翻译过来就是“套接字”。 套接字是什么,我们先来看看它的英文含义:插座。 Socket 就像一个电话插座,负责连通两端的电话,进行点对点通信,让电话可以进行通信,端…...

Cilium动手实验室: 精通之旅---20.Isovalent Enterprise for Cilium: Zero Trust Visibility
Cilium动手实验室: 精通之旅---20.Isovalent Enterprise for Cilium: Zero Trust Visibility 1. 实验室环境1.1 实验室环境1.2 小测试 2. The Endor System2.1 部署应用2.2 检查现有策略 3. Cilium 策略实体3.1 创建 allow-all 网络策略3.2 在 Hubble CLI 中验证网络策略源3.3 …...

k8s业务程序联调工具-KtConnect
概述 原理 工具作用是建立了一个从本地到集群的单向VPN,根据VPN原理,打通两个内网必然需要借助一个公共中继节点,ktconnect工具巧妙的利用k8s原生的portforward能力,简化了建立连接的过程,apiserver间接起到了中继节…...
【学习笔记】深入理解Java虚拟机学习笔记——第4章 虚拟机性能监控,故障处理工具
第2章 虚拟机性能监控,故障处理工具 4.1 概述 略 4.2 基础故障处理工具 4.2.1 jps:虚拟机进程状况工具 命令:jps [options] [hostid] 功能:本地虚拟机进程显示进程ID(与ps相同),可同时显示主类&#x…...

Linux 内存管理实战精讲:核心原理与面试常考点全解析
Linux 内存管理实战精讲:核心原理与面试常考点全解析 Linux 内核内存管理是系统设计中最复杂但也最核心的模块之一。它不仅支撑着虚拟内存机制、物理内存分配、进程隔离与资源复用,还直接决定系统运行的性能与稳定性。无论你是嵌入式开发者、内核调试工…...

20个超级好用的 CSS 动画库
分享 20 个最佳 CSS 动画库。 它们中的大多数将生成纯 CSS 代码,而不需要任何外部库。 1.Animate.css 一个开箱即用型的跨浏览器动画库,可供你在项目中使用。 2.Magic Animations CSS3 一组简单的动画,可以包含在你的网页或应用项目中。 3.An…...
JavaScript 数据类型详解
JavaScript 数据类型详解 JavaScript 数据类型分为 原始类型(Primitive) 和 对象类型(Object) 两大类,共 8 种(ES11): 一、原始类型(7种) 1. undefined 定…...

AI语音助手的Python实现
引言 语音助手(如小爱同学、Siri)通过语音识别、自然语言处理(NLP)和语音合成技术,为用户提供直观、高效的交互体验。随着人工智能的普及,Python开发者可以利用开源库和AI模型,快速构建自定义语音助手。本文由浅入深,详细介绍如何使用Python开发AI语音助手,涵盖基础功…...

MySQL的pymysql操作
本章是MySQL的最后一章,MySQL到此完结,下一站Hadoop!!! 这章很简单,完整代码在最后,详细讲解之前python课程里面也有,感兴趣的可以往前找一下 一、查询操作 我们需要打开pycharm …...
DAY 26 函数专题1
函数定义与参数知识点回顾:1. 函数的定义2. 变量作用域:局部变量和全局变量3. 函数的参数类型:位置参数、默认参数、不定参数4. 传递参数的手段:关键词参数5 题目1:计算圆的面积 任务: 编写一…...
土建施工员考试:建筑施工技术重点知识有哪些?
《管理实务》是土建施工员考试中侧重实操应用与管理能力的科目,核心考查施工组织、质量安全、进度成本等现场管理要点。以下是结合考试大纲与高频考点整理的重点内容,附学习方向和应试技巧: 一、施工组织与进度管理 核心目标: 规…...