WPF test animation robot(simulate blink,mouse talk)
WPF 动画,模拟机器人眨眼,说话。

using System;
using System.Collections.Generic;
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.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes; namespace WpfApplication9
{
/// <summary>
/// Interaction logic for RobotWindow.xaml
/// </summary>
public partial class RobotWindow : Window
{
public RobotWindow()
{
InitializeComponent();
sbTalk = Resources["sbTalk"] as Storyboard;
aTalk = sbTalk.Children[0] as DoubleAnimation; sbEyeBlink = Resources["sbEyeBlink"] as Storyboard; TestDisplay();
} Storyboard sbTalk;
DoubleAnimation aTalk;
Storyboard sbEyeBlink; Random rnd = new Random(); void TestDisplay()
{ Talk();
EyeBlink(); } /// <summary>
/// 随机眨眼
/// </summary>
void EyeBlink()
{
Task.Run(() =>
{
while (true)
{
Thread.Sleep(1000* rnd.Next(1,5));
Dispatcher.Invoke(() =>
{
sbEyeBlink.Begin(); }); } }); }
/// <summary>
/// 说话
/// </summary>
void Talk() {
Task.Run(() =>
{
while (true)
{
Thread.Sleep(600);
Dispatcher.Invoke(() =>
{
aTalk.From = 0;
aTalk.To = rnd.NextDouble();
sbTalk.Begin(); }); } }); } }
} UI: <Window x:Class="WpfApplication9.RobotWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="RobotWindow" Height="377" Width="535">
<Window.Resources>
<Storyboard x:Key="sbTalk">
<DoubleAnimation AutoReverse="True" Duration="0:0:0.3" To="1" Storyboard.TargetName="t1" Storyboard.TargetProperty="ScaleY" />
</Storyboard> <Storyboard x:Key="sbEyeBlink">
<DoubleAnimation AutoReverse="True" Duration="0:0:0.3" To="0" Storyboard.TargetName="eye1" Storyboard.TargetProperty="ScaleY" />
<DoubleAnimation AutoReverse="True" Duration="0:0:0.3" To="0" Storyboard.TargetName="eye2" Storyboard.TargetProperty="ScaleY" />
</Storyboard> </Window.Resources>
<Grid>
<Grid Margin="0,32,74,0" HorizontalAlignment="Right" Width="388" Height="270" VerticalAlignment="Top"> <Ellipse Name="Head" Width="245" Height="235" Stroke="#FFCDCDC2" StrokeThickness="4"
Fill="#FFFBEDF3" HorizontalAlignment="Center" Margin="22,10,25,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" > </Ellipse>
<Ellipse Name="lEye" Width="64" Stroke="#FFCDCDC2" StrokeThickness="4"
Fill="#FFCDCDC2" HorizontalAlignment="Center" Margin="97,100,227,0" RenderTransformOrigin="0.5,0.5" Height="44" VerticalAlignment="Top" >
<Ellipse.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="eye1" ScaleY="1"/>
<SkewTransform/>
<TranslateTransform/>
</TransformGroup>
</Ellipse.RenderTransform>
</Ellipse>
<Ellipse Name="rEye" Width="64" Stroke="#FFCDCDC2" StrokeThickness="4"
Fill="#FFCDCDC2" HorizontalAlignment="Center" Margin="220,100,104,0" RenderTransformOrigin="0.5,0.5" Height="44" VerticalAlignment="Top" >
<Ellipse.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="eye2" ScaleY="1"/>
<SkewTransform/>
<TranslateTransform/>
</TransformGroup>
</Ellipse.RenderTransform>
</Ellipse> <Ellipse Name="mouse" Width="100" Height="58" Stroke="Yellow" StrokeThickness="4"
Fill="#FFE2055F" HorizontalAlignment="Center" Margin="96,151,96,61" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" >
<Ellipse.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="t1" ScaleY="0.1"/>
<SkewTransform/>
<TranslateTransform/>
</TransformGroup>
</Ellipse.RenderTransform>
</Ellipse>
</Grid>
</Grid>
</Window>
WPF test animation robot(simulate blink,mouse talk)的更多相关文章
- 【笔记】WPF实现ViewPager引导界面效果及问题汇总
最近在开发项目的首次使用引导界面时,遇到了问题,引导界面类似于安卓手机ViewPager那样的效果,希望通过左右滑动手指来实现切换不同页面,其间伴随动画. 实现思路: 1.界面布局:新建一个UserC ...
- WPF与缓动(一) N次缓动
原文:WPF与缓动(一) N次缓动 WPF与缓动(一) N次缓动 ...
- WPF 程序鼠标在窗口之外的时候,控件拿到的鼠标位置在哪里?
原文:WPF 程序鼠标在窗口之外的时候,控件拿到的鼠标位置在哪里? 在 WPF 程序中,我们有 Mouse.GetPosition(IInputElement relativeTo) 方法可以拿到鼠标 ...
- WPF中属性经动画处理后无法更改的问题
在WPF的Animation中,有一个属性为FillBehavior,用于指定时间线在其活动周期结束后但其父时间线仍处于活动周期或填充周期时的行为方式.如果希望动画在活动周期结束时保留其值,则将动画F ...
- Vector人工智能机器人SDK使用笔记
Cozmo是2016年推出的,2两年后的2018年Vector上市,具备语音助手和更多功能,元件数由300+升级到700+. Vector的SDK具体说明在:developer.anki.com/ve ...
- Gazebo機器人仿真學習探索筆記(七)连接ROS
中文稍后补充,先上官方原版教程.ROS Kinetic 搭配 Gazebo 7 附件----官方教程 Tutorial: ROS integration overview As of Gazebo 1 ...
- Python 库汇总英文版
Awesome Python A curated list of awesome Python frameworks, libraries, software and resources. Insp ...
- .Net程序员面试所需要的一些技术准备
夜已经很深了,但却毫无睡意,最近找工作和面试感触良多,所以想记录下来这段过程. 作为一个.Net程序员,不可否认是比JAVA要难混的.甚至在智联招聘或者大街网都没有.NET程序员的备用选项.真是令人悲 ...
- 自动化测试: sikuli,一个基于界面图像的gui测试框架
http://www.sikuli.org/ license: MIT script language: Python 下面是他的一个hello world的例子,看看也挺有意思的. 开源的世界里有很 ...
- Server-Side UI Automation Provider - WinForm Sample
Server-Side UI Automation Provider - WinForm Sample 2014-09-14 源代码 目录 引用程序集提供程序接口公开服务器端 UI 自动化提供程序从 ...
随机推荐
- 2.9 使用系统光盘修复Linux系统
如果系统错误已经导致单用户模式不能进入了,那么是否需要重新安装Linux 系统?不用着急,为了应对单用户模式也无法修复的错误,Linux 系统提供了 rescue 救援(光盘修复)模式. rescue ...
- (系列十一)Vue3框架中路由守卫及请求拦截(实现前后端交互)
说明 该文章是属于OverallAuth2.0系列文章,每周更新一篇该系列文章(从0到1完成系统开发). 该系统文章,我会尽量说的非常详细,做到不管新手.老手都能看懂. 说明:OverallAuth2 ...
- 第三篇:低功耗模组Air724UG硬件设计手册
今天我们分享最后一篇. 3.20 省电功能 根据系统需求,有两种方式可以使模块进入到低功耗的状态.对于AT版本使用"AT+CFUN"命令可以使模块 进入最少功能状态. 具体的功 ...
- 国产数据库oceanBbase,达梦,金仓与mysql数据库的性能对比 四、python读mysql写入达梦数据库
一.说明 安装达梦的驱动 pip install dmPython==2.5.5 参数接收那里,其他数据库都是用%,达梦要用? 二.源码 #coding=utf-8 import pymysql im ...
- Abp Vnext Vue版本(Vben Admin5.0)
前言 之前有提供免费开源的基于vben2.8版本的abp vnext pro版本 abp vnext pro vben admin 2.8 vben2.8作者已经重构一个版本,命名为vben5,而vb ...
- vue 使用 application/x-www-form-urlencoded格式提交数据
const params = new URLSearchParams();//前端在传参时需要先新建一个URLSearchParams对象,然后将参数append到这个对象中 params.appen ...
- COS 音视频实践|给你的视频加把锁
导语 为了保障视频内容安全,防止视频被非法下载和传播,对象存储(Cloud Object Storage,COS)数据处理基于数据万象 CI 提供了 HLS 视频加密的功能,拥有相比于私有读文件更高的 ...
- 关于 Span 的一切:探索新的 .NET 明星: 4. Span<T> 和 Memory<T> 是如何与 .NET 库集成的?
4. Span<T> 和 Memory<T> 是如何与 .NET 库集成的? 1. Span<T> 是什么? 2. Span<T> 是如何实现的? 3. ...
- 黑苹果 - 搭建python自动化测试环境
通用环境 1. 安装 xcode 从 AppStore 安装 安装完成之后,打开 xcode,同意各种协议 不用新建项目 注意: xcode下载完成后,安装的过程很慢,需要等待.我是12.5版本,差不 ...
- https://gitlab.com/volian/nala/-/wikis/Installation
Installation Debian Testing/Sid Nala is officially in the testing and sid repos. sudo apt install ...