c# Polygon 画多边形,
//随机多边形:
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;
} }
}
钻石图形:
<Canvas>
<Polygon HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Fill"
Points="0,50, 50,0, 100,50"
Stroke="White" StrokeThickness="1" RenderTransformOrigin="0.5,0.5" Canvas.Left="9">
<Polygon.Fill>
<SolidColorBrush x:Name="Color1" Color="Gray" Opacity="0.4"/>
</Polygon.Fill>
</Polygon> <Polygon HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Fill"
Points="0,50, 50,0, 100,50"
Stroke="White" StrokeThickness="1" RenderTransformOrigin="0.5,0.5" Canvas.Left="60">
<Polygon.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="180"/>
<TranslateTransform/>
</TransformGroup>
</Polygon.RenderTransform>
<Polygon.Fill>
<SolidColorBrush x:Name="Color2" Color="Red" Opacity="0.4"/>
</Polygon.Fill>
</Polygon>
<Polygon HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Fill"
Points="0,50, 50,0, 100,50"
Stroke="White" StrokeThickness="1" RenderTransformOrigin="0.5,0.5" Canvas.Left="110">
<Polygon.Fill>
<SolidColorBrush x:Name="Color3" Color="Gray" Opacity="0.4"/>
</Polygon.Fill>
</Polygon> <Polygon HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Fill"
Points="0,0, 50,0, 100,120"
Stroke="White" StrokeThickness="1" RenderTransformOrigin="0.5,0.5" Canvas.Left="9" Canvas.Top="51">
<Polygon.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="0"/>
<TranslateTransform/>
</TransformGroup>
</Polygon.RenderTransform>
<Polygon.Fill>
<SolidColorBrush x:Name="Color4" Color="Gray" Opacity="0.4"/>
</Polygon.Fill>
</Polygon>
<Polygon HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Fill"
Points="0,0, 50,0, 100,120"
Stroke="White" StrokeThickness="1" RenderTransformOrigin="0.5,0.5" Canvas.Left="110" Canvas.Top="51">
<Polygon.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="-1"/>
<SkewTransform/>
<RotateTransform Angle="0"/>
<TranslateTransform/>
</TransformGroup>
</Polygon.RenderTransform>
<Polygon.Fill>
<SolidColorBrush x:Name="Color5" Color="Gray" Opacity="0.4"/>
</Polygon.Fill>
</Polygon>
<Polygon HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Fill"
Points="0,0, 100,0, 50,120"
Stroke="White" StrokeThickness="1" RenderTransformOrigin="0.5,0.5" Canvas.Left="59" Canvas.Top="51"> <Polygon.Fill>
<SolidColorBrush x:Name="Color6" Color="Blue" Opacity="0.4"/>
</Polygon.Fill>
</Polygon> </Canvas>
c# Polygon 画多边形,的更多相关文章
- OpenLayers 根据坐标动态画多边形
找了一上午,发现都是鼠标点击画框的,那为什么不标明了是 “鼠标”点击 呢? 想实现的功能是数据库检索坐标集合,然后根据分组提取4点坐标,最后把多个多边形形成图层放在地图上. 最后的实现: <!D ...
- 最全vue的vue-amap使用高德地图插件画多边形范围
一.在vue-cli的框架下的main.js(或者main.ts)中引入高德插件,代码如下: import Vue from 'vue' import VueAMap from 'vue-amap' ...
- 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数012,polygon,多边形
<zw版·Halcon-delphi系列原创教程> Halcon分类函数012,polygon,多边形 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换 ...
- 使用Java、Matlab画多边形闭合折线图
由于写论文要将“哈密顿回路问题(TSP)”的求解中间结果表示出来,查了一下使用程序画多边形图形.现在在总结一下,这个图是“由给定节点首尾相连的”闭合多边形. 1.使用matlab作闭合多边形图 没有找 ...
- 【编程漫谈】用JAVA画多边形
一门语言只要带图形库就可以编程画图了,用JAVA画图有两种方式,一是在内存中画好然后生成图片,就可以看到画图的效果了.另一个就是在窗口界面上直接画,可以实时看到程序的运行效果.刚开始学编程的时候,我加 ...
- 【原创】pads layout 画多边形copper,出现Self-Intersecting Polygon,解决办法
在做线性位移传感器的电路板时,需要在一个很小的多边形Copper操作,总是提示“Self-Intersecting Polygon”报错,意思是outline线自身交叉,换句话说就是线宽与多边形尺寸没 ...
- [svg 翻译教程]Polyline(折线)polygon(多边形)
原文: http://tutorials.jenkov.com/svg/polygon-element.html Polyline 虽然说这个 元素我没用过,但是还是蛮强大的,也翻译下 示例 < ...
- [javascript svg fill stroke stroke-width points polygon属性讲解] svg fill stroke stroke-width points polygon绘制多边形属性并且演示polyline和polygon区别讲解
<!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...
- 一个给力的html5 画多边形的例子
只需改变参数就能画出你想要的多边形,代码简单!不得不惊叹canvas的强大! 代码奉上 <!doctype html> <html> <head> <meta ...
- qt 画多边形(实现鼠标拖动节点)
---恢复内容开始--- 2018-01-06 这个小例子实现了移动鼠标,鼠标的坐标信息跟随鼠标移动,多边形的实现,鼠标点击可以拖动多边形点的位置,(其中有个问题?我在QMainWindow下,用mo ...
随机推荐
- Kafka社区KIP-500中文译文(去除ZooKeeper)
原文链接:https://cwiki.apache.org/confluence/display/KAFKA/KIP-500%3A+Replace+ZooKeeper+with+a+Self-Mana ...
- HarmonyOS-Chat聊天室|纯血鸿蒙Next5 api12聊天app|ArkUI仿微信
自研原生鸿蒙NEXT5.0 API12 ArkTS仿微信app聊天模板HarmonyOSChat. harmony-wechat原创重磅实战纯血鸿蒙OS ArkUI+ArkTs仿微信App聊天实例.包 ...
- Selenium IDE使用指南一(爬虫脚本录制器)
安装 从Chrome或Firefox网络商店安装Selenium IDE . 启动IDE 安装后,通过从浏览器菜单栏中单击其图标来启动它. 故障排除 在菜单栏中没有看到Selenium IDE的图标? ...
- 定时任务监控服务Healthchecks
GitHub地址:https://github.com/healthchecks/healthchecks 官方文档:https://healthchecks.io/docs/ 按照步骤进行安装: 1 ...
- JDBC【4】-- jdbc预编译与拼接sql对比
在jdbc中,有三种方式执行sql,分别是使用Statement(sql拼接),PreparedStatement(预编译),还有一种CallableStatement(存储过程),在这里我就不介绍C ...
- Threejs入门-灯光
在 Three.js 中,灯光是非常重要的元素之一,它能够模拟现实世界中的光照效果,帮助我们打造更加真实的三维场景.灯光的种类和配置方式可以影响整个场景的视觉效果,在不同的应用中,灯光的使用非常关键. ...
- Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Faile
解决方法: 1.新建一个安卓应用,复制下面路径红色框的代码 去替换 导入应用中的代码,就是修改gradle版本: 2.在导入的应用中如下路径添加信息 代码: android.overridePat ...
- linux 软连接使用
转载请注明出处: 在Linux系统中,软连接(Symbolic Link)是一种特殊类型的文件链接,类似于Windows系统中的快捷方式.它允许用户通过一个文件路径访问另一个文件或目录,而不需要拥有原 ...
- HTML5 进度条
1. <progress>标签 进度条 value属性:规定进程的当前值.默认为0 max属性:规定需要完成的值. PS:这里没有最小值设置,或者说最小值一律为0 <progress ...
- 关于com组件的方法,以AE的IFieldsEdit为例
今天,有小伙伴问我,为什么在调用IFieldsEdit接口时,VS无法自动显示出AddFiled方法,而这个方法是确实存在的 在此,做下解答,因为这个方法被隐藏了.TypeLibFunc属性,被用来指 ...