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

039集——渐变色之:CAD中画彩虹()(CAD—C#二次开发入门)

(来左边儿 跟我一起画个龙,在你右边儿 画一道彩虹    ~~~~~~~~~~~            

效果如下:

 

 以下展示部分颜色源码:

namespace AcTools
{
    public class Class1
    {
        public Wform.Timer timer;//定时器需建在类下面
        public static DateTime startTime;
        [CommandMethod("xx")]
        public void Demo()
        {
            红到黄(255, 1000.0);
            黄到绿(255, 1000.0 + 255 * 1);
            绿到蓝(255, 1000.0 + 255 * 2);
            蓝到紫(255, 1000.0 + 255 * 3);
            timer = new Wform.Timer();
            timer.Interval = 2500;//相当于多久更新一下屏幕
            timer.Tick += Timer_Tick;//定时器关联事件;
            startTime = DateTime.Now;
            timer.Start(); 
            //红到紫(255, 1000.0 + 255 * 4);
        }
        public void Timer_Tick(object sender, EventArgs e)//一定时间间隔触发的事件
        {
            
            TimeSpan elapsed = DateTime.Now - startTime;
            红到紫(255, 1000.0 + 255 * 4);
            if (elapsed.TotalSeconds > 10)
            {
                timer.Stop();
                timer.Dispose();
                Z.ed.WriteMessage("over\n");
            }
            Z.ed.UpdateScreen();
        }
        public void 红到紫(double num, double radius)
        {
            //红到紫 255, 0 ,0 ---- 255  ,0, 255

            List<Circle> circles = new List<Circle>();//画圆
            List<Arc> arcs = new List<Arc>();//画弧
            for (int i = 1; i <= num; i++)
            {
                Circle circle = new Circle()
                {
                    Center = new Point3d(500, 1000, 0),
                    Radius = radius + i,
                    Color = (i == 0) ? Color.FromRgb(255, 0, 0) : Color.FromRgb(255, 0,(byte)(0 + i / num * 255) ),
                };
                circles.Add(circle);
            }
            arcs = Halfcircle(circles);
            for (int i = 0; i < 5; i++)
            {

            List<Entity> ents = arcs.Cast<Entity>().ToList();//list类型强转
            Flash flash = new Flash(ents );//创建瞬态
            flash.FlashUpdate(ents);//更新瞬态
               //Z.ed.GetPoint("");//
             
                foreach (Entity item in ents)
                {
                    item.ChangeEntityColor(i);

                }
                flash.FlashUpdate(ents);//更新瞬态
                Thread.Sleep(500);
                Z.ed.UpdateScreen();
                flash.FlashlistErase();//删除瞬态
             
            }
           
            //Z.db.AddEntityToModeSpace(arcs.ToArray());
        }
        public void 红到黄(double num,double radius)
        {//红到黄 255 0 0 - 255 255 0
            List<Circle> circles = new List<Circle>();//画圆
            List<Arc> arcs = new List<Arc>();//画弧
            for (int i = 1; i <= num; i++)
            {
                Circle circle = new Circle()
                {
                    Center = new Point3d(500, 1000, 0),
                    Radius = radius +  i ,
                  Color = (i ==0)? Color.FromRgb(255, 0, 0) : Color.FromRgb(255, (byte)(0 + i/ num* 255), 0),
                };
                circles.Add(circle);
            }
            arcs = Halfcircle(circles);
            Z.db.AddEntityToModeSpace(arcs.ToArray());
        }  
        public void 黄到绿(double num, double radius)
        {//黄到绿255 ,255 ,0 -  0, 255,0 
            List<Circle> circles = new List<Circle>();//画圆
            List<Arc> arcs = new List<Arc>();//画弧
            for (int i = 1; i <= num; i++)
            {
                Circle circle = new Circle()
                {
                    Center = new Point3d(500, 1000, 0),
                    Radius = radius + i,
                    Color = (i == 1) ? Color.FromRgb(255, 255, 0) : Color.FromRgb((byte)(255 - i / num * 255), 255,0),
                };
                circles.Add(circle);
            }
            arcs = Halfcircle(circles);
            Z.db.AddEntityToModeSpace(arcs.ToArray());
        }
        public void 绿到蓝(double num, double radius)
        {//绿到蓝0, 255,0  ----   0 ,0 ,255
            List<Circle> circles = new List<Circle>();//画圆
            List<Arc> arcs = new List<Arc>();//画弧
            for (int i = 1; i <= num; i++)
            {
                Circle circle = new Circle()
                {
                    Center = new Point3d(500, 1000, 0),
                    Radius = radius + i,
                    Color = (i == 1) ? Color.FromRgb(0,255, 255 ) : Color.FromRgb(0,(byte)(255 - i / num * 255), (byte)(0 + i  / num * 255)),
                };
                circles.Add(circle);
            }
            arcs = Halfcircle(circles);
            Z.db.AddEntityToModeSpace(arcs.ToArray());
        }
        public void 蓝到紫(double num, double radius)
        {//蓝到紫 0 ,0 ,255 - 255, 0, 255 
            List<Circle> circles = new List<Circle>();//画圆
            List<Arc> arcs = new List<Arc>();//画弧
            for (int i = 1; i <= num; i++)
            {
                Circle circle = new Circle()
                {
                    Center = new Point3d(500, 1000, 0),
                    Radius = radius +  i,
                    Color = (i == 1) ? Color.FromRgb(0, 0, 255) : Color.FromRgb((byte)(0 + i / num * 255), 0, 255),
                };
                circles.Add(circle);
            }
            arcs = Halfcircle(circles);
            Z.db.AddEntityToModeSpace(arcs.ToArray());
        }
        public static List<Arc> Halfcircle(List<Circle> circles)
        { 
            List<Arc> arcs = new List<Arc>();//画弧
            if (!( circles is null )&& circles.Count >0)
            {
               
                foreach (Circle circle in circles)
                {
                    arcs.Add(new Arc() { Center = circle.Center,Radius = circle .Radius,
                        StartAngle = 0,Color = circle .Color, EndAngle = Math.PI });
                }
               
            }
           return arcs;
        }
    }
}

namespace AcTools
{
    public class Class1
    {
        [CommandMethod("xx")]
        public void Demo()
        {
            红到黄(255, 1000.0);
            黄到绿(255, 1000.0 + 255 * 1);
            绿到蓝(255, 1000.0 + 255 * 2);
            蓝到紫(255, 1000.0 + 255 * 3);
        }
        public void 红到紫(double num, double radius)
        {//红到紫 255, 0 ,0 ---- 255  ,0, 255
            List<Circle> circles = new List<Circle>();//画圆
            List<Arc> arcs = new List<Arc>();//画弧
            for (int i = 1; i <= num; i++)
            {
                Circle circle = new Circle()
                {
                    Center = new Point3d(500, 1000, 0),
                    Radius = radius + i,
                    Color = (i == 0) ? Color.FromRgb(255, 0, 0) : Color.FromRgb(255, 0,(byte)(0 + i / num * 255) ),
                };
                circles.Add(circle);
            }
            arcs = Halfcircle(circles);
            Z.db.AddEntityToModeSpace(arcs.ToArray());
        }
        public void 红到黄(double num,double radius)
        {//红到黄 255 0 0 - 255 255 0
            List<Circle> circles = new List<Circle>();//画圆
            List<Arc> arcs = new List<Arc>();//画弧
            for (int i = 1; i <= num; i++)
            {
                Circle circle = new Circle()
                {
                    Center = new Point3d(500, 1000, 0),
                    Radius = radius +  i ,
                  Color = (i ==0)? Color.FromRgb(255, 0, 0) : Color.FromRgb(255, (byte)(0 + i/ num* 255), 0),
                };
                circles.Add(circle);
            }
            arcs = Halfcircle(circles);
            Z.db.AddEntityToModeSpace(arcs.ToArray());
        }  
        public void 黄到绿(double num, double radius)
        {//黄到绿255 ,255 ,0 -  0, 255,0 
            List<Circle> circles = new List<Circle>();//画圆
            List<Arc> arcs = new List<Arc>();//画弧
            for (int i = 1; i <= num; i++)
            {
                Circle circle = new Circle()
                {
                    Center = new Point3d(500, 1000, 0),
                    Radius = radius + i,
                    Color = (i == 1) ? Color.FromRgb(255, 255, 0) : Color.FromRgb((byte)(255 - i / num * 255), 255,0),
                };
                circles.Add(circle);
            }
            arcs = Halfcircle(circles);
            Z.db.AddEntityToModeSpace(arcs.ToArray());
        }
        public void 绿到蓝(double num, double radius)
        {//绿到蓝0, 255,0  ----   0 ,0 ,255
            List<Circle> circles = new List<Circle>();//画圆
            List<Arc> arcs = new List<Arc>();//画弧
            for (int i = 1; i <= num; i++)
            {
                Circle circle = new Circle()
                {
                    Center = new Point3d(500, 1000, 0),
                    Radius = radius + i,
                    Color = (i == 1) ? Color.FromRgb(0,255, 255 ) : Color.FromRgb(0,(byte)(255 - i / num * 255), (byte)(0 + i  / num * 255)),
                };
                circles.Add(circle);
            }
            arcs = Halfcircle(circles);
            Z.db.AddEntityToModeSpace(arcs.ToArray());
        }
        public void 蓝到紫(double num, double radius)
        {//蓝到紫 0 ,0 ,255 - 255, 0, 255 
            List<Circle> circles = new List<Circle>();//画圆
            List<Arc> arcs = new List<Arc>();//画弧
            for (int i = 1; i <= num; i++)
            {
                Circle circle = new Circle()
                {
                    Center = new Point3d(500, 1000, 0),
                    Radius = radius +  i,
                    Color = (i == 1) ? Color.FromRgb(0, 0, 255) : Color.FromRgb((byte)(0 + i / num * 255), 0, 255),
                };
                circles.Add(circle);
            }
            arcs = Halfcircle(circles);
            Z.db.AddEntityToModeSpace(arcs.ToArray());
        }
        public static List<Arc> Halfcircle(List<Circle> circles)
        { 
            List<Arc> arcs = new List<Arc>();//画弧
            if (!( circles is null )&& circles.Count >0)
            {
               
                foreach (Circle circle in circles)
                {
                    arcs.Add(new Arc() { Center = circle.Center,Radius = circle .Radius,
                        StartAngle = 0,Color = circle .Color, EndAngle = Math.PI });
                }
               
            }
           return arcs;
        }
    }
}

      public static ObjectId[] AddEntityToModeSpace(this Database db, params Entity[] ent)
      {
          // 声明ObjectId 用于返回
          ObjectId[] entId = new ObjectId[ent.Length];
          // 开启事务处理
          using (DocumentLock acLckDoc = Z.doc.LockDocument())
          {
              using (Transaction trans = db.TransactionManager.StartTransaction())
              {
                  // 打开块表
                  BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                  // 打开块表记录
                  BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                  for (int i = 0; i < ent.Length; i++)
                  {
                      // 将图形添加到块表记录
                      if (ent[i].IsNewObject)
                      {
                         entId[i] = btr.AppendEntity(ent[i]);
                        // 更新数据信息
                        trans.AddNewlyCreatedDBObject(ent[i], true);
                      }
                      
                     // Z.ed.Redraw(ent[i]);//动态显示
                  }
                  // 提交事务
                  trans.Commit();
              }
          }
          return entId;
      }



 public static Database db 
 {
     get { return  HostApplicationServices.WorkingDatabase; }
 }   

 

  Arc arc = new Arc()
 {
     Center  = new Point3d(500,500+i,0),
     Radius = 500,StartAngle = Math.PI*0.1+i*0.01,
     EndAngle=Math.PI*0.9+i * 0.01,
     //StartPoint = new Point3d(0, i, 0),
     //EndPoint = new Point3d(1000, i, 0),
     Color = Color.FromRgb(255, (byte)i, 0),
 };

 public void xx()
 {//红到黄 255 0 0 - 255 255 0
     List<Line> lines = new List<Line>();//画线
     for (int i = 0; i < 255; i++)
     {
         Line line = new Line() { StartPoint = new Point3d(0,i,0),
         EndPoint = new Point3d(1000,i, 0),
         Color = Color .FromRgb(255, (byte)i, 0),
         };    
         lines.Add(line);
     }
     Z.db.AddEntityToModeSpace(lines.ToArray());
     List<Arc> arcs = new List<Arc>();//画圆弧
     for (int i = 0; i < 255; i++)
     {
         Arc arc = new Arc()
         {
             Center  = new Point3d(500,1000+i,0),
             Radius = 500,StartAngle = Math.PI*0.1-i*0.01,
             EndAngle=Math.PI*0.9+i * 0.01,
             //StartPoint = new Point3d(0, i, 0),
             //EndPoint = new Point3d(1000, i, 0),
             Color = Color.FromRgb(255, (byte)i, 0),
         };
         arcs.Add(arc);
     }
     Z.db.AddEntityToModeSpace(arcs.ToArray());
 }

finally:


http://www.kler.cn/a/420119.html

相关文章:

  • Ubuntu22.04上kdump和crash的使用
  • 十,[极客大挑战 2019]Secret File1
  • c++预编译头文件
  • Java 基于Spring AI RAG组件做AI智能问答_rag检索增强_AI智能问答
  • 040集——CAD中放烟花(CAD—C#二次开发入门)
  • 【机器学习】CatBoost 模型实践:回归与分类的全流程解析
  • 12月2日星期一今日早报简报微语报早读
  • 如何实现一套键盘鼠标控制两台计算机(罗技Options+ Flow功能快速实现演示)
  • Ubuntu 20.04中的文件删除操作:详解与实用示例
  • AI运用落地思考:如何用AI进行物料条码的识别及异常检测?
  • 基于SpringBoot+Vue的美妆购物网站
  • 单片机学习笔记 17. 串口通信-发送汉字
  • 2024-11-30 二叉树的存储结构
  • Python语法1
  • .NET8/.NETCore 依赖注入:自动注入项目中所有接口和自定义类
  • HarmonyOS NEXT应用开发,关于useNormalizedOHMUrl选项的坑
  • ES6-14面试题
  • STM32G4系列MCU的Direct memory access controller (DMA)功能介绍之二
  • mysql 5.7安装及安装后无法启动问题处理
  • C++:unordered_map与unordered_set详解
  • 2-jsp-实现增删改功能
  • 【从0学英语】形容词性/名词性物主代词是什么?
  • 深入理解计算机系统,源码到可执行文件翻译过程:预处理、编译,汇编和链接
  • 一.准备环境,从零开始搭建项目
  • Hive学习基本概念
  • Java 中 ArrayList 与 LinkedList 的详细比较