当前位置: 首页 > news >正文

040集——CAD中放烟花(CAD—C#二次开发入门)

 效果如下:

单一颜色的烟花:

渐变色的火花:

 

namespace AcTools
{public class HH{public static TransientManager tm = TransientManager.CurrentTransientManager;public static Random rand = new Random();public static Vector3D G = new Vector3D(0,-10,0);// - Vector3D. * 10;public static Document doc => Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;public static Editor ed => doc.Editor;[CommandMethod ("show")]public static void demo(){火花 h = new 火花();var psr = Z.ed.GetPoint("");while (psr.Status == PromptStatus.OK){//h.添加火点(new Point3d(500, -100, 0));h.添加火点(new Point3d( psr.Value.X +200,psr.Value .Y-20 ,0));h.添加火点(new Point3d(psr.Value.X - 200, psr.Value.Y+20, 0));h.添加火点(new Point3d(psr.Value.X + 400, psr.Value.Y - 20, 0));h.添加火点(new Point3d(psr.Value.X - 400, psr.Value.Y + 20, 0));psr = Z.ed.GetPoint("");}}}public class 火花:IDisposable{ Timer timer;List<火星>火星s=new List<火星> ();//int k = 0;public 火花(){timer = new Timer();火星s = new List<火星>();timer.Interval = 30;//相当于多久更新一下屏幕timer.Tick += 火星飞行事件;timer.Start();}public void 添加火点(Point3d pt){int n = new Random().Next(26, 40);//烟花的个数var sudu = new Random().Next(16,27);//速度int ys = HH.rand.Next(0, 5);//颜色Color cc;switch (ys){case 0:cc  =Color.FromRgb(255,0,0); break;//红case 1: cc = Rainbow(0, 255, 0); break;//绿case 2: cc = Rainbow(255, 255, 0); break;//黄case 3: cc = Rainbow(255, 0, 255); break;//紫case 4: cc = Rainbow(255, 186, 0); break;//橙default: cc = Rainbow(0, 0, 255); break;//蓝}double 衰减速度 = HH.rand.NextDouble() * 0.05 + 0.95;for (int i = 0; i < n; i++){var vt = new Vector3d(HH.rand.NextDouble() - 0.5, HH.rand.NextDouble() - 0.5, HH.rand.NextDouble() - 0.5);火星s.Add(new 火星(pt, vt, sudu, cc, 衰减速度));}}public static Color  Rainbow(int k, int min, int max){return Color.FromRgb((byte)k, (byte)min, (byte)max);}private  void 火星飞行事件(object sender, EventArgs e){foreach (var h in 火星s){h.运动();}List<Circle> cirs = new List<Circle>();for (int i = 火星s.Count-1; i  >=0   ; i--){if (火星s[i].灭){cirs.AddRange(火星s[i].cirs);火星s.RemoveAt(i);}}foreach (var c  in cirs){HH.tm.EraseTransient(c, new IntegerCollection());HH.ed.UpdateScreen();System.Windows .Forms.Application.DoEvents();}}public void Dispose(){timer.Tick -= 火星飞行事件;火星s.Clear();timer.Stop(); timer.Dispose();}}public delegate Autodesk.AutoCAD.Colors.Color 颜色(double k,double min,double max);class 火星{Random rand = new Random();public bool 灭;public List<Circle>cirs = new List<Circle>();Circle cir;int k;double 速度;int 总数量;Color 颜色渐变;double 衰减速度;Vector3D 方向;*
///
///
///public void 运动(){k++;var vt = 方向.GetNormal() * 速度;var g = new Vector3D(0, -10, 0);vt = vt + HH.G;cir.Center = cir.Center + vt;Circle cir1 = cir.Clone() as Circle;cir1.Color = 颜色渐变;cirs.Add(cir1);HH.tm.AddTransient(cir1, TransientDrawingMode.Main, 0, new IntegerCollection());速度 *= 衰减速度;if (k > 总数量 || 速度 < 0.1){灭 = true;}}}
}

finally

http://www.lryc.cn/news/497633.html

相关文章:

  • 一文理解多模态大语言模型——下
  • ROS2创建 base 包用于其他模块的参数配置和头文件依赖
  • 自然语言处理期末试题汇总
  • 前端热门面试题目(四)——计算机网路篇
  • kubenetes流水线实施清单
  • Redis4——持久化与集群
  • 【LeetCode: 94. 二叉树的中序遍历 + 栈】
  • Python系列 - MQTT协议
  • 同时在github和gitee配置密钥
  • Runway 技术浅析(六):文本到视频(Text-to-Video)
  • 云计算vspere 安装过程
  • QT 实现QStackedWidget切换页面右移动画
  • Android Camera2采集并编码为H.264
  • DHCP和DNS
  • ONES 功能上新|ONES Project 甘特图再度升级
  • <工具 Claude Desktop> 配置 MCP server 连接本地 SQLite, 本机文件夹(目录) 网络驱动器 Windows 11 系统
  • GIT的使用方法以及汉化方法
  • 公因子的数目
  • 数据结构(三)——双向链表的介绍以及实现
  • Webpack开发模式及处理样式资源
  • leetcode--设计链表
  • 【MySQL】:数据库操作
  • 刷蓝桥杯历年考题(更新至15届~)
  • AI与BI的火花:大语言模型如何重塑商业智能的未来
  • Qt 详解QtNFC 读写模式
  • 增删改查文档
  • C语言蓝桥杯2023年省赛真题
  • Python迭代器-大数据量的处理
  • 自动化包括态交互与感交互,而智能化包括势交互与知交互
  • VideoBooth: Diffusion-based Video Generation with Image Prompts