LeaferJS 是一款好用的 Canvas 引擎,通过LeaferJS绘制罗盘案例.
https://www.leaferjs.com/ui/guide/

示例

太极八卦罗盘

直接上代码


<template><div id="LuoPan"></div><div id="info"><p>屏幕宽度: {{ screenWidth }}px</p><p>屏幕高度: {{ screenHeight }}px</p><p>圆心x: {{ centerX }}px</p><p>圆心Y: {{ centerY }}px</p><p>太极半径: {{ tjRadius }}px</p><p>罗盘环宽度: {{ loopWidth }}px</p><p>太极旋转速度: {{ tj_v }}</p><p>先天八卦旋转速度: {{ xtbg_v }}</p></div>
</template>
<script>
import {Leafer, Rect, Ellipse, Group,Text} from 'leafer-ui'
import '@leafer-in/state'import { Animate } from '@leafer-in/animate'export default {name: 'LuoPan',data(){return {screenWidth: 0,// 屏幕宽度screenHeight: 0, //屏幕高度centerX: 0, //圆心xcenterY: 0, //圆心YtjRadius: 100, //太极半径loopWidth: 50, // 罗盘环宽度tj_v: 5, // 太极旋转速度xtbg_v: 10, // 先天八卦旋转速度htbg_v: 20, // 后天八卦旋转速度loopData:{xtbg:[{code: "011",txt: "巽"},{code: "010",txt: "坎"},{code: "001",txt: "艮"}, {code: "000",txt: "坤"},{code: "100",txt: "震"},{code: "101",txt: "离"},{code: "110",txt: "兑"},{code: "111",txt: "乾"},],htbg:[{code: "000",txt: "坤"},{code: "110",txt: "兑"},{code: "111",txt: "乾"},{code: "010",txt: "坎"},{code: "001",txt: "艮"},{code: "100",txt: "震"},{code: "011",txt: "巽"},{code: "101",txt: "离"},],}};},mounted() {this.updateScreenSize();const leafer = new Leafer({view: 'LuoPan', // view 参数支持设置 canvas 标签对象width: 0, // 不能设置为 0, 否则会变成自动布局height: 800,fill: 'rgba(255,223,0,1)'})// 绘制太极const groudTaiji  = this.drewTaiji(leafer);// 绘制先天八卦const groudXtbagua = this.drewLoopXtbg(leafer,8, this.loopData.xtbg,1);// 绘制先天八卦const groudHtbagua = this.drewLoopHtbg(leafer,8, this.loopData.htbg,2);},methods: {// 获取屏幕长宽updateScreenSize() {this.screenWidth = window.innerWidth;this.screenHeight = window.innerHeight;this.centerX = this.screenWidth / 2 - this.tjRadius-200;this.centerY = this.screenHeight / 2 - this.tjRadius;},drewLoopHtbg(leafer,num, htbg,level) {const groundHtbg = new Group({x: this.centerX+this.tjRadius,y: this.centerY+this.tjRadius,around: 'center',animation:{keyframes: [{x: this.centerX+this.tjRadius,y: this.centerY+this.tjRadius,rotation: 360,cornerRadius: 0}],easing: 'linear',duration: this.htbg_v, // 自动分配剩余的时长给未设置 duration 的关键帧: (3 - 0.5 - 0.2 - 0.1) / 2loop: true},});// 画框for (let i = 0; i < num; i++) {const itemAngle = 360/num;const item = Ellipse.one({fill: 'rgb(255,146,0,0.2)',draggable: false,x: this.centerX + this.tjRadius,y: this.centerY + this.tjRadius,width: this.tjRadius * 2 + this.loopWidth*2*2,height: this.tjRadius * 2 + this.loopWidth*2*2,startAngle: i*itemAngle,endAngle: (i+1)*itemAngle,innerRadius: (this.tjRadius+this.loopWidth)/(this.loopWidth*2+this.tjRadius),hoverStyle: { // // 鼠标悬停 样式fill: 'rgba(255,255,255, 0.8)',shadow: {x: 0,y: 0,blur: 30,color: 'rgba(255,255,255,0.97)',box: true // box-shadow}}});// 画爻var htbgItem = htbg[i];var htbgItemCode = htbgItem['code'];var htbgItemTxt = htbgItem['txt'];for (let j = 0; j < 3; j++) {var arry = htbgItemCode.split("");var arryElement = arry[j];const tempRadius = this.tjRadius - j*this.loopWidth/5 - this.loopWidth/3 + this.loopWidth*(level-1);if(arryElement == '1'){const yaoYang = Rect.one({zIndex: 10,fill: '#fff',draggable: false,y: this.loopWidth*(level-1) + this.centerY + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.sin(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),x: this.loopWidth*(level-1) + this.centerX + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.cos(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),width: this.loopWidth/3*2,height: this.loopWidth / 9,rotation: i * itemAngle + 118,around: 'center',});groundHtbg.add(yaoYang);}else{const yaoYangOne = Rect.one({zIndex: 10,fill: '#fff',draggable: false,x: this.loopWidth*(level-1) + this.centerX + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.cos(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),y: this.loopWidth*(level-1) + this.centerY + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.sin(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),offsetX: (-this.loopWidth/3*2/5*2+4) * Math.sin(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),offsetY: (this.loopWidth/3*2/5*2-5) * Math.cos(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),width: this.loopWidth/3*2/5*2,height: this.loopWidth / 9,rotation: i * itemAngle + 117,around: 'center',});groundHtbg.add(yaoYangOne);const yaoYangTwo = Rect.one({zIndex:  10,fill: '#fff',draggable: false,y: this.loopWidth*(level-1) + this.centerY + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.sin(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),x: this.loopWidth*(level-1) + this.centerX + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.cos(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),offsetX: (this.loopWidth/3*2/3/5*2 + 5) * Math.sin(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),offsetY: (- this.loopWidth/3*2/5*2 + 4) * Math.cos(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),width: this.loopWidth/3*2/5*2,height: this.loopWidth / 9,rotation: i * itemAngle + 117,around: 'center',});groundHtbg.add(yaoYangTwo);}}groundHtbg.add(item);const tempRadius = this.tjRadius - this.loopWidth/9*6-4 + this.loopWidth;const text = new Text({fill: '#000',text: "     "+htbg[i].txt,draggable: false,x: this.loopWidth + this.centerX + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.cos(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 4)),y: this.loopWidth + this.centerY + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.sin(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 4)),fontSize: 16,rotation: i * itemAngle + 290,});groundHtbg.add(text);}leafer.add(groundHtbg);return groundHtbg;},drewLoopXtbg(leafer,num, xtbg, level) {const groundXtbg = new Group({x: this.centerX+this.tjRadius,y: this.centerY+this.tjRadius,around: 'center',animation:{keyframes: [{x: this.centerX+this.tjRadius,y: this.centerY+this.tjRadius,rotation: 360,cornerRadius: 0}],easing: 'linear',duration: this.xtbg_v, // 自动分配剩余的时长给未设置 duration 的关键帧: (3 - 0.5 - 0.2 - 0.1) / 2loop: true},});// 画框for (let i = 0; i < num; i++) {const itemAngle = 360/num;const item = Ellipse.one({zIndex: 10,fill: 'rgba(255,255,255,0.2)',draggable: false,x: this.centerX + this.tjRadius,y: this.centerY + this.tjRadius,width: this.tjRadius * 2 + this.loopWidth*2,height: this.tjRadius * 2 + this.loopWidth*2,startAngle: i*itemAngle,endAngle: (i+1)*itemAngle,innerRadius: this.tjRadius/(this.loopWidth+this.tjRadius),hoverStyle: { // // 鼠标悬停 样式fill: 'rgba(255,255,255, 0.8)',shadow: {x: 0,y: 0,blur: 30,color: 'rgba(255,255,255,0.97)',box: true // box-shadow}}});// 画爻var xtbgItem = xtbg[i];var xtbgItemCode = xtbgItem['code'];var xtbgItemTxt = xtbgItem['txt'];for (let j = 0; j < 3; j++) {var arry = xtbgItemCode.split("");var arryElement = arry[j];const tempRadius = this.tjRadius - j*this.loopWidth/5 - this.loopWidth/3 + this.loopWidth*(level-1);if(arryElement == '1'){const yaoYang = Rect.one({zIndex: 10,fill: '#fff',draggable: false,x: this.centerX + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.cos(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),y: this.centerY + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.sin(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),width: this.loopWidth/3*2,height: this.loopWidth / 9,rotation: i * itemAngle + 118,around: 'center',});groundXtbg.add(yaoYang);}else{const yaoYangOne = Rect.one({zIndex: 10,fill: '#fff',draggable: false,x: this.loopWidth*(level-1) + this.centerX + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.cos(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),y: this.loopWidth*(level-1) + this.centerY + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.sin(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),offsetX: (-this.loopWidth/3*2/5*2+4) * Math.sin(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),offsetY: (this.loopWidth/3*2/5*2-5) * Math.cos(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),width: this.loopWidth/3*2/5*2,height: this.loopWidth / 9,rotation: i * itemAngle + 117,around: 'center',});groundXtbg.add(yaoYangOne);const yaoYangTwo = Rect.one({fill: '#fff',draggable: false,y: this.loopWidth*(level-1) + this.centerY + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.sin(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),x: this.loopWidth*(level-1) + this.centerX + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.cos(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),offsetX: (this.loopWidth/3*2/3/5*2 + 5) * Math.sin(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),offsetY: (- this.loopWidth/3*2/5*2 + 4) * Math.cos(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 3)),width: this.loopWidth/3*2/5*2,height: this.loopWidth / 9,rotation: i * itemAngle + 117,around: 'center',});groundXtbg.add(yaoYangTwo);}}groundXtbg.add(item);const tempRadius = this.tjRadius - this.loopWidth/9*6-4 + this.loopWidth*(level-1);const text = new Text({fill: '#000',text: "     "+xtbg[i].txt,draggable: false,x: this.loopWidth*(level-1) + this.centerX + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.cos(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 4)),y: this.loopWidth*(level-1) + this.centerY + this.tjRadius * 3 - this.tjRadius / 2 + (this.loopWidth + tempRadius) * Math.sin(Math.PI / 180 * (itemAngle * i + itemAngle / 2 + 4)),fontSize: 16,rotation: i * itemAngle + 290,});groundXtbg.add(text);}leafer.add(groundXtbg);return groundXtbg;},// 画太极drewTaiji(leafer){const groundTaiji = new Group({x: this.centerX+this.tjRadius,y: this.centerY+this.tjRadius,around: 'center',animation:{keyframes: [{x: this.centerX+this.tjRadius,y: this.centerY+this.tjRadius,rotation: 360,cornerRadius: 0}],easing: 'linear',duration: this.tj_v, // 自动分配剩余的时长给未设置 duration 的关键帧: (3 - 0.5 - 0.2 - 0.1) / 2loop: true}});//太极大扇形-右边黑const tjBai = Ellipse.one({fill: '#000',draggable: false,x: this.centerX+this.tjRadius,y: this.centerY+this.tjRadius,width: this.tjRadius*2,height: this.tjRadius*2,startAngle: -90,endAngle: 90,shadow: {x: 0,y: 0,blur: 20,color: 'rgba(255,255,255,0.97)',box: true // box-shadow},});groundTaiji.add(tjBai);//太极大扇形-左边白const tjHei = Ellipse.one({fill: '#fff',draggable: false,x: this.centerX+this.tjRadius,y: this.centerY+this.tjRadius,width: this.tjRadius*2,height: this.tjRadius*2,startAngle: 90,endAngle: 270,shadow: {x: 0,y: 0,blur: 20,color: 'rgba(255,255,255,0.97)',box: true // box-shadow},})groundTaiji.add(tjHei);//太极中圆-白const tjZhongyuanBai = Rect.one({fill: '#fff',draggable: false,x: this.centerX+this.tjRadius*3/2,y: this.centerY+this.tjRadius,width: this.tjRadius,height: this.tjRadius,cornerRadius: this.tjRadius/2,});groundTaiji.add(tjZhongyuanBai);//太极中圆-黑const tjZhongyuanHei = Rect.one({fill: '#000',draggable: false,x: this.centerX+this.tjRadius*3/2,y: this.centerY+this.tjRadius*2,width: this.tjRadius,height: this.tjRadius,cornerRadius: this.tjRadius/2,});groundTaiji.add(tjZhongyuanHei);//太极小圆-白const tjXiaoyuanBai = Rect.one({fill: '#000',draggable: false,x: this.centerX+this.tjRadius*2 - this.tjRadius/6,y: this.centerY+this.tjRadius*3/2-this.tjRadius/6,width: this.tjRadius/6*2,height: this.tjRadius/6*2,cornerRadius: this.tjRadius/6,});groundTaiji.add(tjXiaoyuanBai);//太极小圆-黑const tjXiaoyuanHei = Rect.one({fill: '#fff',draggable: false,x: this.centerX+this.tjRadius*2 - this.tjRadius/6,y: this.centerY+this.tjRadius*2+this.tjRadius/2-this.tjRadius/6,width: this.tjRadius/6*2,height: this.tjRadius/6*2,cornerRadius: this.tjRadius/6,});groundTaiji.add(tjXiaoyuanHei);leafer.add(groundTaiji);}}};</script><style scoped>#info{position: absolute;right: 100px;top: 10px;width: 200px;background-color: rgba(50, 205, 120, 0.5);color: white;padding-left: 10px;}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/bicheng/86951.shtml
繁体地址,请注明出处:http://hk.pswp.cn/bicheng/86951.shtml
英文地址,请注明出处:http://en.pswp.cn/bicheng/86951.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Python开源项目月排行 2025年5月

#2025年5月2025年6月1日1scrapy一个开源的、基于 Python 的高性能网络爬虫和数据抓取框架。Scrapy 项目最初由伦敦的网络聚合和电子商务公司 Mydeco 的员工以及乌拉圭蒙得维的亚的网络咨询公司 Insophia 的开发者共同创建。目前&#xff0c;Scrapy 由 Zyte&#xff08;原名 Scr…

Debezium日常分享系列之:在 Kubernetes 中使用 Debezium 的 CDC

Debezium日常分享系列之&#xff1a;在 Kubernetes 中使用 Debezium 的 CDC 架构源数据库创建数据库凭证密钥Debezium 自定义镜像构建并推送镜像Kafka Connect 集群Debezium Postgres 连接器Debezium 创建的 Kafka 主题 Debezium 是一个开源的分布式变更数据捕获 (CDC) 平台。D…

tf serving和torch serve哪个耗时更低

TensorFlow Serving&#xff08;TF Serving&#xff09;和 TorchServe 的耗时对比需结合具体场景&#xff08;如硬件配置、模型类型、优化策略等&#xff09;&#xff0c;以下从多维度分析两者的性能差异及适用场景。 ⏱️ 1. 标准性能基准对比 根据公开压测数据&#xff08;…

Java面试宝典:基础六

133. 二进制小数点位移 答案:C(乘以2) 解析: 原理:二进制小数点右移一位等价于乘以 (2^1)(左移则除以 (2))。示例: 101.1(5.5)右移 → 1011(11)验证:(5.5 \times 2 = 11)说明:位移前:1 0 1 . 1 (值 = 2+2⁰+2⁻ = 5.5) 位移后:1 0 1 1 . (值 = 2+2+2⁰ =…

04-React中绑定this并给函数传参的几种方式

前言绑定 this 的方式一&#xff1a;bind()绑定 this 并给函数传参 的方式二&#xff1a;构造函数里设置 bind()绑定 this 并给函数传参 的方式三&#xff1a;箭头函数【荐】 前言 我们先来看下面这段代码&#xff1a; components/MyComponent.jsx import React from "…

Docker拉取不兼容的镜像解决办法

错误提示如下&#xff1a; WARNING: The requested images platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested295ef35cfefe0dce6904e017e89218695d9a9c092b45496218f4476357be4f9c 这个警告表明你…

android14 未充电状态电量低于15%弹框提示 10%直接关机

上层接收电量变化广播&#xff0c;添加未充电判断&#xff0c;做出弹框或关机动作 SystemUI\src\com\android\systemui\power\PowerUI.java Overridepublic void onReceive(Context context, Intent intent) {String action intent.getAction();if (PowerManager.ACTION_POWE…

ASP.NET Core 中 Kestrel 的应用及在前后端分离项目中的角色

目录 一、Kestrel 基础&#xff1a;轻量级且高性能的 Web 服务器 二、前后端分离项目架构&#xff1a;Vue、.NET Core API、Nginx 与 Kestrel 2.1 交互流程图 2.2 流程详解 三、Kestrel 在架构中的核心作用 四、launchSettings.json 与 Kestrel 配置的关系及底层机制 4.1…

Kotlin 退出循环总结

文章目录 Kotlin 退出循环总结for循环forEach()嵌套for循环lambda函数inline函数 Kotlin 退出循环总结 for循环 for ((index, value) in list.withIndex()) {if (value "c") {break // 退出循环}println("$index - $value") }// 0 - a // 1 - bfo…

再看C语言

目录 与Java的差异化 编程范式 跨平台 编译过程 包管理 基本类型 内存结构 重点掌握 进制、字节与计算 指针 结构体 关键词 动态内存 模块化 高级特性 动态链接 虚拟内存 打包编译 并发编程 现在需要参与到存储软件开发工作&#xff0c;存储层比较接近OS系统…

机器学习入门 | 训练、推理与其他机器学习活动(预处理、测试与评估)

在训练阶段&#xff0c;训练算法通过优化目标/损失函数在训练数据集上的表现&#xff0c;不断更新模型参数θ。在监督学习场景中&#xff0c;训练数据集由输入-标签对&#xff08;真实输出值&#xff09;组成。目标函数应当奖励模型根据训练输入成功预测真实输出的行为&#xf…

Node.js特训专栏-实战进阶:11. Redis缓存策略与应用场景

&#x1f525; 欢迎来到 Node.js 实战专栏&#xff01;在这里&#xff0c;每一行代码都是解锁高性能应用的钥匙&#xff0c;让我们一起开启 Node.js 的奇妙开发之旅&#xff01; Node.js 特训专栏主页 专栏内容规划详情 Redis 缓存策略与应用场景&#xff1a;从理论到实战的高…

【stm32】HAL库开发——Cube配置基本定时器

目录 一、Cube配置基本定时器 1.定时器CubeMX配置介绍 2.定时器中断控制LED 3.定时器常用函数 4.定时器从模式&#xff08;Reset Mode&#xff09; 5.定时器的从模式&#xff08;Gated Mode&#xff09; 6.定时器的编码器接口 一、Cube配置基本定时器 1.定时器CubeMX配置…

nginx反向代理后端服务restful及token处理

#user nobody; worker_processes 1;#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024; } #代理mysql服务 stream {upstream mysql_backend {server 192.168…

正确理解Cola StateMachine不内置事务管理机制

✅ 正确理解&#xff1a;Cola StateMachine 并非“不支持”事务一致性&#xff0c;而是“不内置”事务管理机制 因为&#xff1a; Cola StateMachine 是轻量级、无状态、不依赖 Spring 的框架&#xff0c;它本身 不绑定任何事务上下文。它不像 Spring StateMachine 那样自动与…

AudioTrack使用

** AudioTrack ** AudioTrack 是 Android 音频系统中的核心类&#xff0c;用于播放原始音频数据&#xff08;PCM&#xff09;或压缩音频&#xff08;如 MP3、AAC&#xff09;。它提供了低级别的音频播放控制&#xff0c;适合需要精细管理的场景&#xff08;如游戏音效、实时音…

解密:MySQL 的常见存储引擎

在数据库领域&#xff0c;MySQL 作为一款广受欢迎的关系型数据库管理系统&#xff0c;提供了多种存储引擎以满足不同应用场景的需求。每种存储引擎都有其独特的特性、优势和适用场景。本文将深入探讨 MySQL 中几种常见的存储引擎&#xff0c;包括 InnoDB、MyISAM、MEMORY 和 AR…

qt和qtcreator版本关系

实例展示&#xff1a; 如图所示的qtcreator是使用qt5.15安装过程选择勾选了qtcreator 14.0.2&#xff0c;安装完成qtcreator版本信息&#xff1a; 安装过程中选择了这些构件kits&#xff0c;会自动识别到&#xff1a; 使用qt5.9.9另外安装的kits&#xff0c;需要手动设置才能识…

2个任务同时提交到YARN后2个都卡住(CDH)

文章目录 问题描述解决方案1、增加资源2、调整ApplicationMaster资源3、关闭YARN调度器的资源抢占4、不使用公平调度器 问题描述 在CDH集群上&#xff0c;同时提交2个任务到YARN后&#xff0c;2个任务都卡住 解决方案 1、增加资源 增加服务器的内存和CPU 2、调整Applicatio…

web3区块链-ETH以太坊

一. 以太坊概述 以太坊&#xff08;Ethereum&#xff09;作为区块链技术的代表性项目之一&#xff0c;自2015年发布以来&#xff0c;迅速成为全球区块链行业的核心基础设施。相比比特币&#xff0c;以太坊不仅支持点对点的价值转移&#xff0c;还引入了智能合约&#xff0c;使…