原文:WPF 实现繁花曲线

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/nihang1234/article/details/83346919

XAML:

<Window x:Class="FlowerCurve.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FlowerCurve"
mc:Ignorable="d"
Title="MainWindow" Height="800" Width="800" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Canvas>
<Path Name="path" Stroke="Red" StrokeThickness="1"/>
</Canvas>
</Window>

后台代码:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
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;
using System.Windows.Threading; namespace FlowerCurve
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private Point _bigCircleCenter = new Point(400, 400);
private double _bigRadius = 400;
private double _smallRadius = 260;
private double _d = 110;
DispatcherTimer timer = new DispatcherTimer();
private double _angle = 0;
private PathFigure _figure;
private double _step = 0.05D;
List<Point> _points = new List<Point>(); public MainWindow()
{
InitializeComponent();
} private void Draw(PathFigure figure, Point point, bool isStartPoint)
{
if (isStartPoint)
{
figure.StartPoint = point;
}
else
{
figure.Segments.Add(new LineSegment(point, true));
}
} private void Window_Loaded(object sender, RoutedEventArgs e)
{
timer.Interval = TimeSpan.FromMilliseconds(5);
timer.Tick += Timer_Tick;
timer.Start(); PathGeometry curve = new PathGeometry();
path.Data = curve;
//curve.StartPoint = new Point(_bigRadius - _smallRadius - _d, 0);
//curve.mo
_figure = new PathFigure();
curve.Figures.Add(_figure);
} private void Timer_Tick(object sender, EventArgs e)
{
Point p = Calculate(_angle);
Draw(_figure, p, _angle == 0);
_points.Add(p);
if (_points.Count > 10)
{
bool finished =Math.Abs(p.X-_points[0].X)<2 && Math.Abs(p.Y - _points[0].Y) < 2;
Debug.WriteLine($"{_points[0].X - p.X} || {_points[0].Y - p.Y}");
if (finished)
{
MessageBox.Show("绘制完成");
timer.Stop();
}
} _angle += _step;
} private Point Calculate(double angle)
{
double xr = _bigCircleCenter.X + (_bigRadius - _smallRadius) * Math.Cos(angle);
double yr = _bigCircleCenter.Y - (_bigRadius - _smallRadius) * Math.Sin(angle);
double a = _bigRadius * angle / _smallRadius;
double x = xr + _d * Math.Cos(a);
double y = yr + _d * Math.Sin(a);
Point p = new Point(x, y); return p;
}
}
}

运行效果:

源代码

WPF 实现繁花曲线的更多相关文章

  1. 使用python和pygame绘制繁花曲线

    前段时间看了一期<最强大脑>,里面展示了各种繁花曲线组合成的非常美丽的图形,一时心血来潮,想尝试自己用代码绘制繁花曲线,想怎么组合就怎么组合. 真实的繁花曲线使用一种称为繁花曲线规的小玩意 ...

  2. WPF贝塞尔曲线示例

    WPF贝塞尔曲线示例 贝塞尔曲线在之前使用SVG的时候其实就已经有接触到了,但应用未深,了解的不是很多,最近在进行图形操作的时候需要用到贝塞尔曲线,所以又重新来了解WPF中贝塞尔曲线的绘制. 一阶贝塞 ...

  3. 缓动公式整理(附:C#实现及WPF原版对比)

    前言 缓动在动画效果中应用非常广泛,在合适的时候使用一些缓动效果会使得效果更加符合人的直观感受,简单来说,会显得更加自然. WPF提供了11种缓动效果,涵盖了大部分的使用场景.不过如果需要在非WPF下 ...

  4. WPF绘制光滑连续贝塞尔曲线

    1.需求 WPF本身没有直接把点集合绘制成曲线的函数.可以通过贝塞尔曲线函数来绘制. 贝塞尔曲线类是:BezierSegment,三次贝塞尔曲线,通过两个控制点来控制开始和结束方向. Quadrati ...

  5. 贝塞尔曲线 WPF MVVM N阶实现 公式详解+源代码下载

    源代码下载 效果图: 本程序主要实现: N阶贝塞尔曲线(通用公式) 本程序主要使用技术 MVVM InterAction 事件绑定 动态添加Canvas的Item 第一部分公式: n=有效坐标点数量 ...

  6. WPF 曲线图表控件(自制)(二)

    原文:WPF 曲线图表控件(自制)(二) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/koloumi/article/details/775218 ...

  7. WPF 曲线图表控件(自制)(一)

    原文:WPF 曲线图表控件(自制)(一) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/koloumi/article/details/775092 ...

  8. C#WPF 如何绘制几何图形 图示教程 绘制sin曲线 正弦 绘制2D坐标系 有图有代码

    原文:C#WPF 如何绘制几何图形 图示教程 绘制sin曲线 正弦 绘制2D坐标系 有图有代码 C#WPF 如何绘制几何图形? 怎么绘制坐标系?绘制sin曲线(正弦曲线)? 这离不开Path(Syst ...

  9. WPF使用DynamicDataDisplay.dll显示CPU及内存使用曲线

    原文:WPF使用DynamicDataDisplay.dll显示CPU及内存使用曲线 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wangshub ...

随机推荐

  1. 把git仓库从码云迁到github,及git常用命令

    前言 刚开始建仓库的时候,因为网络的原因选择了国内的码云.后来又想换成github,毕竟平时github使用率比较高. 替换远程仓库地址方式如下: git remote set-url origin ...

  2. 【例题 6-10 UVA - 699】The Falling Leaves

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 递归模拟就好. [代码] #include <bits/stdc++.h> using namespace std; c ...

  3. 【AtCoder ABC 075 C】Bridge

    [链接] 我是链接,点我呀:) [题意] 让你求出桥的个数 [题解] 删掉这条边,然后看看1能不能到达其他所有的点就可以了 [代码] #include <bits/stdc++.h> us ...

  4. POJ 3628 Bookshelf 2 0-1背包

    传送门:http://poj.org/problem?id=3628 题目看了老半天,牛来叠罗汉- -|||和书架什么关系啊.. 大意是:一群牛来叠罗汉,求超过书架的最小高度. 0-1背包的问题,对于 ...

  5. 在Eclipse中运行Nutch2.3 分类: H3_NUTCH 2015-01-28 16:41 3175人阅读 评论(13) 收藏

    参考http://wiki.apache.org/nutch/RunNutchInEclipse 一.环境准备 1.下载nutch2.3源代码 wget http://mirror.bit.edu.c ...

  6. Longest Increasing Subsequences(最长递增子序列)的两种DP实现

    一.本文内容 最长递增子序列的两种动态规划算法实现,O(n^2)及O(nlogn).     二.问题描述 最长递增子序列:给定一个序列,从该序列找出最长的 升序/递增 子序列. 特点:1.子序列不要 ...

  7. centos7 安装php环境和安装swoole

    这仅是我在网上找了多个解决方法,搞定了我遇到的问题,做的一个记录,买这个服务器就是为了测试swoole,结果快到期了,swoole还没装好 感谢https://www.cnblogs.com/phpw ...

  8. iOS调试 - 基本技巧

    在程序中,无论是你想弄清楚为什么数组中有3个对象而不是5个,或者为什么一个新的玩家开始之后,游戏在倒退——调试在这些处理过程中是比较重要的一部 分.通过本文的学习,我们将知道在程序中,可以使用的大多数 ...

  9. PHP文件处理--操作文件

    除了能够对文件内容进行读写,对文件本身相同也能够进行操作,如拷贝文件.又一次命名.查看改动日期等. PHP内置了大量的文件操作函数,经常使用的文件函数例如以下表: 函数原型 函数说明 举例 bool ...

  10. [AngularFire2] Build a Custom Node Backend Using Firebase Queue

    In this lesson we are going to learn how to build a custom Node process for batch processing of Fire ...