首页 > Windows开发 > 详细

c# Polygon 画多边形,

时间:2021-07-16 15:30:17      阅读:21      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfMosaic
{
   public  class RandomShape:Grid 
    {
        public RandomShape() {
            Width = 100;
            Height = 100;
            //Background= new SolidColorBrush(Colors.Gray);
            Polygon p = new Polygon();
            p.Stroke = new SolidColorBrush(Colors.White);
            p.StrokeThickness = 1;
            p.Fill = new SolidColorBrush(Color.FromArgb(255, (byte)Utils.rnd.Next(0, 256), (byte)Utils.rnd.Next(0, 256), (byte)Utils.rnd.Next(0, 256)));
            PointCollection ps = GetPoints(new Point(50,50),Utils.rnd.Next(10,50),Utils.rnd.Next(3,25));
            p.Points = ps;

            Children.Add(p);
        }


  
        /// <param name="pointCenter">中心坐标</param>
        /// <param name="r">半径</param>
        /// <param name="count">等分分数</param>
        /// <returns></returns>
        private PointCollection GetPoints(Point pointCenter, int r, int count)
        {
            Point[] point = new Point[count];
            PointCollection pointCollection = new PointCollection();
            for (int i = 0; i < count; i++)
            {
                point[i].X = (int)(r * Math.Cos((i + 1) * 360 / count * Math.PI / 180)) + pointCenter.X;
                point[i].Y = (int)(r * Math.Sin((i + 1) * 360 / count * Math.PI / 180)) + pointCenter.Y;
                pointCollection.Add(point[i]);
            }
   
            return pointCollection;
        }

    }
}

  

 

c# Polygon 画多边形,

原文:https://www.cnblogs.com/wgscd/p/15020037.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!