WPF 心形线算法

原文: WPF 心形线算法

今天在网上查找下心形算法公式,自己便按照公式写下来标记在博客,主要是方便以后查看!

private int maxStep = 520; private double radius; private double centerPt; private void CreateHeartLine() { /*RootCvs是Canvas控件*/ centerPt = RootCvs.Width / 2; radius = RootCvs.Width / 6; for (int i = 0; i < maxStep; i++) { var rect = new Rectangle { Height = 5, Width = 5, Fill = Brushes.Red }; double angle = 2 * Math.PI / maxStep * i; double r = 2 * radius * (1 - Math.Sin(angle)); //圆形心 //double x = centerPt + radius * (2 * Math.Cos(angle) - Math.Cos(2 * angle)); //double y = centerPt + radius * (2 * Math.Sin(angle) - Math.Sin(2 * angle)); //桃形心 double x = centerPt + 16 * (Math.Sin(angle) * Math.Sin(angle) * Math.Sin(angle)) * 10;// double y = centerPt + (13 * Math.Cos(angle) - 5 * Math.Cos(2 * angle) - 2 * Math.Cos(3 * angle) - Math.Cos(4 * angle)) * 10;// Canvas.SetLeft(rect, x); Canvas.SetTop(rect, y); RootCvs.Children.Add(rect); } }

 

WPF(Windows Presentation Foundation)时间线是一个可视化控件,用于创建动画效果。它是一个可自定义和可扩展的控件,可以在时间轴上添加关键帧来控制属性的变化,使其随着时间的推移而动态变化。WPF时间线可以在XAML中定义,也可以在代码中以编程方式创建和操作。 以下是一个简单的WPF时间线示例,其中一个元素的颜色会随着时间的推移而渐变: ```xml <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <Storyboard x:Key="myStoryboard"> <ColorAnimation Storyboard.TargetName="myRectangle" Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)" From="Red" To="Blue" Duration="0:0:5" /> </Storyboard> </Window.Resources> <Grid> <Rectangle x:Name="myRectangle" Fill="Red" Width="100" Height="100"/> </Grid> </Window> ``` 在这个示例中,我们定义了一个Storyboard,其中包含一个ColorAnimation,它将目标属性(myRectangle的Fill属性)从红色变为蓝色,持续时间为5秒。我们可以在代码中启动这个Storyboard,如下所示: ```csharp private void Button_Click(object sender, RoutedEventArgs e) { Storyboard myStoryboard = (Storyboard)this.Resources["myStoryboard"]; myStoryboard.Begin(); } ``` 当我们点击按钮时,WPF时间线将开始播放动画,使矩形的颜色从红色渐变为蓝色。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值