/// <summary> /// 添加内部气泡 /// </summary> private void AddInnerBubble() { //小气泡 半径4-8 在整个Canvers随机分散5-45 速率0.05-0.1 距离5-15 if (_innerBubbleInfoList.Count < _maxInnerBubbleCount) { int size = _rd.Next(4, 9); Viewbox bubble = GetBubble(size); Canvas.SetLeft(bubble, _rd.Next(5, 46) - size / 2); Canvas.SetTop(bubble, 100 - rec_Water.Height - size / 2); cvs_Inner.Children.Add(bubble); BubbleInfo info = new BubbleInfo(); info.Velocity = _rd.Next(5, 11) / 100.00; info.Distance = _rd.Next(5, 16); info.Bubble = bubble; _innerBubbleInfoList.Add(info); } }
/// <summary> /// 添加外部大气泡 /// </summary> private void AddOuterBigBubble() { //大气泡 半径6-10 在Canvers中部20-30 速率0.2-0.5 距离30-60 if (_outerBigBubbleInfoList.Count < _maxOuterBigBubbleCount) { int size = _rd.Next(6, 11); Viewbox bubble = GetBubble(size); Canvas.SetLeft(bubble, _rd.Next(20, 31) - size / 2); Canvas.SetTop(bubble, 100 - size / 2); cvs_Outer.Children.Add(bubble); BubbleInfo info = new BubbleInfo(); info.Velocity = _rd.Next(20, 51) / 100.00; info.Distance = _rd.Next(30, 61); info.Bubble = bubble; _outerBigBubbleInfoList.Add(info); } }
/// <summary> /// 内部气泡动画 /// </summary> private void InnerBubbleAnimation() { for (int i = 0; i < _innerBubbleInfoList.Count; i++) { BubbleInfo info = _innerBubbleInfoList[i]; UIElement bubble = info.Bubble; if (info.Moved <= info.Distance) { double cvsTop = Canvas.GetTop(bubble); Canvas.SetTop(bubble, cvsTop - info.Velocity); info.Moved += info.Velocity; } else { cvs_Inner.Children.Remove(bubble); _innerBubbleInfoList.Remove(info); i--; } } }
/// <summary> /// 添加外部小气泡 /// </summary> private void AddOuterSmallBubble() { //小气泡 半径2-5 在整个Canvers随机分散0-50 速率0.4-1.0 距离10-100 if (_outerSmallBubbleInfoList.Count < _maxOuterSmallBubbleCount) { int size = _rd.Next(2, 6); Ellipse bubble = new Ellipse() { Width = size, Height = size, Fill = new SolidColorBrush(Color.FromRgb(15, 190, 9)) }; Canvas.SetLeft(bubble, _rd.Next(0, 51) - size / 2); Canvas.SetTop(bubble, 100 - size / 2); cvs_Outer.Children.Add(bubble); BubbleInfo info = new BubbleInfo(); info.Velocity = _rd.Next(40, 101) / 100.00; info.Distance = _rd.Next(10, 101); info.Bubble = bubble; _outerSmallBubbleInfoList.Add(info); } }