- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我找到了a fun program这使您可以overlay snowflakes over your desktop and windows 。作为一项编程挑战,我有兴趣尝试弄清楚如何自己做到这一点。更不用说这个程序有点占用内存(如果它没有内存泄漏)。下面是我的开始。我试图用一张图片来了解基础知识,然后进行扩展。
我真正需要帮助的是让图像移动得更加流畅和自然。
<小时/>编辑:
我在下面的答案部分发布了一个解决方案,但它的 CPU 密集程度超出了我的预期,有什么想法吗?
<小时/>WPF XAML 代码:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
AllowsTransparency="True"
WindowStyle="None"
Title="MainWindow" Height="350" Width="525" Background="Transparent" Topmost="True" WindowState="Maximized" ResizeMode="NoResize">
<Grid Name="grid1">
<Image Height="26" HorizontalAlignment="Left" Margin="{Binding flakeMargin}" Name="Image1" Stretch="Fill" VerticalAlignment="Top" Width="28" Source="/snowTest;component/Images/blue-pin-md.png" />
</Grid>
</Window>
VB代码:
Imports System.ComponentModel
Class MainWindow
Dim bw As BackgroundWorker = New BackgroundWorker
Dim flake0 As New flake
Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
grid1.DataContext = flake0
AddHandler bw.DoWork, AddressOf backgroundMover
bw.RunWorkerAsync()
End Sub
Private Sub backgroundMover(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
While (True)
flake0.move()
System.Threading.Thread.Sleep(100)
End While
End Sub
End Class
薄片类:
Imports System.ComponentModel
Public Class flake
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(ByVal info As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub
Private Property startLeft As Integer = 300
Private Property left As Integer = left
Private Property top As Integer = 100
Private Property speed As Integer = 1
Public ReadOnly Property flakeMargin As Thickness
Get
Return New Thickness(left, top, 0, 0)
End Get
End Property
Public Sub move()
top += speed
left = (Math.Cos(top - 100)) * 6 + startLeft
NotifyPropertyChanged("flakeMargin")
End Sub
End Class
最佳答案
这是我目前提出的解决方案:最终最大的修正因素是我使用了 Canvas ,它允许我以非整数增量移动,而且我还更有效地使用了 cos 函数。它的 CPU 密集程度超出了我的预期 (25-30%)。有没有人有任何减少对 CPU 影响的想法?
WPF/XAML:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
AllowsTransparency="True"
WindowStyle="None"
Title="MainWindow" Height="350" Width="525" Background="Transparent" Topmost="True" WindowState="Maximized" ResizeMode="NoResize">
<Canvas Name="canvas1">
</Canvas>
</Window>
VB.NET 主窗口:
Imports System.ComponentModel
Class MainWindow
Dim bw As New BackgroundWorker
Dim flakes(17) As flake
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
For i = 0 To flakes.Count - 1
flakes(i) = New flake
flakes(i).image.DataContext = flakes(i)
flakes(i).image.SetBinding(Canvas.LeftProperty, "left")
flakes(i).image.SetBinding(Canvas.TopProperty, "top")
canvas1.Children.Add(flakes(i).image)
Next
AddHandler bw.DoWork, AddressOf backgroundMover
bw.RunWorkerAsync()
End Sub
Private Sub backgroundMover()
While (True)
For Each f In flakes
f.move()
Next
System.Threading.Thread.Sleep(50)
End While
End Sub
End Class
VB.Net 薄片类:
Imports System.ComponentModel
Public Class flake
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(ByVal info As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub
Private Property startLeft As Double
Private Property _left As Double
Private Property _top As Double
Private Property speed As Double
Private Property amplitude As Double
Private Property period As Double
Public Property image As New Image
Private Shared Property r As New Random
Public Sub New()
_image.Width = 28
_image.Height = 26
_image.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("/snowTest;component/Images/blue-pin-md.png", UriKind.Relative))
startFresh()
End Sub
Public ReadOnly Property left As Double
Get
Return _left
End Get
End Property
Public ReadOnly Property top As Double
Get
Return _top
End Get
End Property
Public Sub startFresh()
_top = -30
amplitude = r.Next(5, 35)
period = 1 / r.Next(20, 60)
speed = r.Next(15, 25) / 10
startLeft = r.Next(0, System.Windows.SystemParameters.PrimaryScreenWidth)
End Sub
Public Sub move()
If _top > System.Windows.SystemParameters.PrimaryScreenHeight Then
startFresh()
Else
_top += speed
_left = amplitude * Math.Cos(period * _top) + startLeft
End If
NotifyPropertyChanged("top")
NotifyPropertyChanged("left")
End Sub
End Class
关于wpf - 像飘落的雪花一样移动元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13693694/
我有一张 table ADS像这样在雪花中(每天插入数据),请注意第 3 行和第 4 行有重复的条目: 身份证REPORT_DATE点击次数印象11月1日2040011月2日2560011月03日80
我正在尝试将 Azure Active Directory 与 Snowflake 集成。我已按照本文档中的说明设置了所有内容:https://learn.microsoft.com/en-us/az
我正在尝试使用 Snowflake 的 match_recognize 工具跨行匹配特定模式。该模式由 a 和 b 的任意序列组成,前提是排除了 b 的长串。在我的测试用例中,我希望允许最多 4 个
我有一个使用SQLAlchemy引擎和to_sql函数写给Snowflake的Pandas数据框。它工作正常,但由于某些Snowflake限制,我必须使用chunksize选项。这对于较小的数据帧也很
我需要将一个表的列作为一条记录插入到另一个表中 结构如下: table_name Column_name Distinct_Count 这是代码,但我无法插入数据: create or
我看过其他问题,但似乎雪花不支持 if/else in sql,至少不是其他 sql 服务器支持它的方式。 有些人建议使用 javascript,但我想尽可能避免使用它。 我正在尝试使用 snowfl
我看过其他问题,但似乎雪花不支持 if/else in sql,至少不是其他 sql 服务器支持它的方式。 有些人建议使用 javascript,但我想尽可能避免使用它。 我正在尝试使用 snowfl
我想知道是否可以创建 UDF 来解密通过使用私钥作为加密值插入到表中的值。我用谷歌搜索真的找不到任何东西。我发现的唯一一件事是,可能有一个使用 JavaScript UDF 和 CryptoJS 的选
我正在尝试使用 snowflake.connector 库和 OKTA 身份验证将 python 连接到雪花。我正在使用以下代码执行但出现错误: Failed to execute request:
如何在模式或数据库中的所有 future View 上授予选择权。 这工作正常,但我希望该角色也可以访问所有 future 的 View : grant select on view . to rol
当从 snowsql shell 运行查询时,我可以在 UI 上看到生成的查询 ID。稍后,如果我必须在历史记录中搜索相同的内容,我想搜索我可以定义的查询 ID 或以某种方式标记查询。 运行查询时是否
学习神奇的粒子发射器,雪花纷纷落下的动画效果,就是通过CAEmitterLayer来实现的,这个layer还能创建火焰,河流,蒸汽的动画效果,常用于游戏开发。 Creating your emit
我有一个变体数据类型,我正在对其执行横向展平,但随后我需要左连接其中一个 json 元素,以从 Snowflake 中的另一个关系表中查找相应 ID 的值。当我这样做时,它给我错误“横向 View 不
我有一位客户,他们的 Snowflake 实例要求列名称包含双引号。示例:从“lk_category”中选择“类别名称”;有谁知道如何关闭此功能吗? 最佳答案 雪花documentation确实解释了
我用下面的脚本创建了一个简单的任务,但由于某种原因它从未运行过。 CREATE OR REPLACE TASK dbo.tab_update WAREHOUSE = COMPUTE_WH SCHEDU
我想在 javascript 过程本身中访问 Snowflake 中当前正在执行的过程的名称,并将其存储在一个变量中。 当我询问“this”对象时,我可以在 Variant 返回中看到名称,但就 JS
我用下面的脚本创建了一个简单的任务,但由于某种原因它从未运行过。 CREATE OR REPLACE TASK dbo.tab_update WAREHOUSE = COMPUTE_WH SCHEDU
TLDR 如何确保 parquet 文件中的日期时间值正确复制到雪花表中? 描述 我正在使用 parquet 文件将数据更新插入到 snowflake 中的阶段。 。然后该文件用于 COPY INTO
我有雪花列,其中包含 yyyy-mm-dd hh:MM:ss 格式的日期。 我使用下面的函数 date_trunc('DAY', '2019-09-23 12:33:25') 输出:2019-09-
有人可以帮助理解根据雪花文档的以下含义 -“表阶段不支持在加载数据时转换数据(即使用查询作为 COPY 命令的源)。” - 文档链接:- https://docs.snowflake.com/en/u
我是一名优秀的程序员,十分优秀!