|
1 | | -using System; |
2 | | -using System.Drawing; |
3 | | -using System.Xml.Linq; |
| 1 | +namespace ScreenSaverParticles; |
4 | 2 |
|
5 | | -namespace ScreenSaverConections |
| 3 | +class CPoint : IDisposable |
6 | 4 | { |
7 | | - class CPoint : IDisposable |
8 | | - { |
9 | | - private readonly Settings _Settings; |
10 | | - public readonly bool Bound; |
11 | | - public readonly int Group; |
12 | | - public bool Visible = true; |
13 | | - public float Alpha = 1; |
14 | | - private float _AlphaSpeed = 0.025f; |
15 | | - private float _XStart; |
16 | | - private float _YStart; |
17 | | - public float X; |
18 | | - public float Y; |
19 | | - private float _Speed; |
20 | | - private float _Time = 0; |
21 | | - private float _Counter = 0; |
22 | | - private float _Acc = 0; |
23 | | - private float _Direction; |
24 | | - private float _RotateSpeed = 0; |
25 | | - public Color _Color; |
26 | | - private readonly int _Width; |
27 | | - private readonly int _Height; |
28 | | - private readonly Random _Rnd; |
| 5 | + private readonly Settings _settings; |
| 6 | + public readonly bool Bound; |
| 7 | + public readonly int Group; |
| 8 | + public bool Visible = true; |
| 9 | + public float Alpha = 1; |
| 10 | + private readonly float _alphaSpeed = 0.025f; |
| 11 | + private float _xStart; |
| 12 | + private float _yStart; |
| 13 | + public float X; |
| 14 | + public float Y; |
| 15 | + private float _speed; |
| 16 | + private float _time = 0; |
| 17 | + private float _counter = 0; |
| 18 | + private float _acc = 0; |
| 19 | + private float _direction; |
| 20 | + private float _rotateSpeed = 0; |
| 21 | + public Color _Color; |
| 22 | + private readonly int _width; |
| 23 | + private readonly int _height; |
29 | 24 |
|
30 | | - private readonly int _MaxDistanceWhenBound = 10; |
| 25 | + private readonly int _maxDistanceWhenBound = 10; |
31 | 26 |
|
32 | 27 |
|
33 | | - public CPoint(int x, int y, int width, int height, Random rnd, Color color, Settings settings, bool bound, int group = 0) |
34 | | - { |
35 | | - _Settings = settings; |
36 | | - Bound = bound; |
37 | | - Group = group; |
38 | | - _XStart = x; |
39 | | - _YStart = y; |
40 | | - X = x; |
41 | | - Y = y; |
42 | | - _Width = width; |
43 | | - _Height = height; |
44 | | - _Rnd = rnd; |
45 | | - _Speed = _Settings.SpeedMax / 2; |
46 | | - _Direction = (float)(rnd.Next(360) / 180d * Math.PI); |
47 | | - _Color = color; |
48 | | - } |
| 28 | + public CPoint(int x, int y, int width, int height, Color color, Settings settings, bool bound, int group = 0) |
| 29 | + { |
| 30 | + _settings = settings; |
| 31 | + Bound = bound; |
| 32 | + Group = group; |
| 33 | + _xStart = x; |
| 34 | + _yStart = y; |
| 35 | + X = x; |
| 36 | + Y = y; |
| 37 | + _width = width; |
| 38 | + _height = height; |
| 39 | + _speed = _settings.SpeedMax / 2; |
| 40 | + _direction = (float)(Random.Shared.Next(360) / 180d * Math.PI); |
| 41 | + _Color = color; |
| 42 | + } |
49 | 43 |
|
50 | | - public void Update() |
51 | | - { |
52 | | - ChangeSpeed(); |
53 | | - Move(); |
54 | | - if (Visible) Alpha = Math.Min(Alpha + _AlphaSpeed, 1); |
55 | | - else Alpha = Math.Max(Alpha - _AlphaSpeed, 0); |
56 | | - } |
57 | | - private void Move() |
58 | | - { |
59 | | - X += (float)(Math.Cos(_Direction) * _Speed); |
60 | | - Y += (float)(Math.Sin(_Direction) * _Speed); |
| 44 | + public void Update() |
| 45 | + { |
| 46 | + ChangeSpeed(); |
| 47 | + Move(); |
| 48 | + if (Visible) Alpha = Math.Min(Alpha + _alphaSpeed, 1); |
| 49 | + else Alpha = Math.Max(Alpha - _alphaSpeed, 0); |
| 50 | + } |
| 51 | + private void Move() |
| 52 | + { |
| 53 | + X += (float)(Math.Cos(_direction) * _speed); |
| 54 | + Y += (float)(Math.Sin(_direction) * _speed); |
61 | 55 |
|
62 | | - if (X > _Width) _Direction = (float)(Math.PI - _Direction); |
63 | | - if (X < 0) _Direction = (float)(Math.PI - (_Direction - Math.PI) + Math.PI); |
64 | | - if (Y > _Height) _Direction = (float)(Math.PI - (_Direction + Math.PI / 2) - Math.PI / 2); |
65 | | - if (Y < 0) _Direction = (float)(Math.PI - (_Direction + Math.PI / 2) - Math.PI / 2); |
66 | | - X = Math.Max(Math.Min(X, _Width), 0); |
67 | | - Y = Math.Max(Math.Min(Y, _Height), 0); |
| 56 | + if (X > _width) _direction = (float)(Math.PI - _direction); |
| 57 | + if (X < 0) _direction = (float)(Math.PI - (_direction - Math.PI) + Math.PI); |
| 58 | + if (Y > _height) _direction = (float)(Math.PI - (_direction + Math.PI / 2) - Math.PI / 2); |
| 59 | + if (Y < 0) _direction = (float)(Math.PI - (_direction + Math.PI / 2) - Math.PI / 2); |
| 60 | + X = Math.Max(Math.Min(X, _width), 0); |
| 61 | + Y = Math.Max(Math.Min(Y, _height), 0); |
68 | 62 |
|
69 | | - if (Bound) |
70 | | - { |
71 | | - var speed = _Settings.DEV_Presentation_BoundSpeed / Program.SizeMul; |
72 | | - var speedX = speed * (_XStart - X) / _MaxDistanceWhenBound; |
73 | | - var speedY = speed * (_YStart - Y) / _MaxDistanceWhenBound; |
74 | | - X += speedX; |
75 | | - Y += speedY; |
76 | | - } |
| 63 | + if (Bound) |
| 64 | + { |
| 65 | + var speed = _settings.DEV_Presentation_BoundSpeed / Program.SizeMul; |
| 66 | + var speedX = speed * (_xStart - X) / _maxDistanceWhenBound; |
| 67 | + var speedY = speed * (_yStart - Y) / _maxDistanceWhenBound; |
| 68 | + X += speedX; |
| 69 | + Y += speedY; |
77 | 70 | } |
78 | | - private void ChangeSpeed() |
| 71 | + } |
| 72 | + private void ChangeSpeed() |
| 73 | + { |
| 74 | + _speed += _acc; |
| 75 | + _speed = Math.Max(Math.Min(_speed, _settings.SpeedMax), -_settings.SpeedMax); |
| 76 | + _direction += _rotateSpeed; |
| 77 | + if (_counter > _time) |
79 | 78 | { |
80 | | - _Speed += _Acc; |
81 | | - _Speed = Math.Max(Math.Min(_Speed, _Settings.SpeedMax), -_Settings.SpeedMax); |
82 | | - _Direction += _RotateSpeed; |
83 | | - if (_Counter > _Time) |
| 79 | + _time = Random.Shared.Next(_settings.TimeMin, _settings.TimeMax); |
| 80 | + _counter = 0; |
| 81 | + var nextAcc = Random.Shared.Next(0, (int)_settings.SpeedMax) / 10f; |
| 82 | + if (_speed == _settings.SpeedMax) _acc = -nextAcc; |
| 83 | + else if (_speed == -_settings.SpeedMax) _acc = nextAcc; |
| 84 | + else |
84 | 85 | { |
85 | | - _Time = _Rnd.Next(_Settings.TimeMin, _Settings.TimeMax); |
86 | | - _Counter = 0; |
87 | | - var nextAcc = _Rnd.Next(0, (int)_Settings.SpeedMax) / 10f; |
88 | | - if (_Speed == _Settings.SpeedMax) _Acc = -nextAcc; |
89 | | - else if (_Speed == -_Settings.SpeedMax) _Acc = nextAcc; |
90 | | - else |
91 | | - { |
92 | | - if (_Rnd.Next(2) == 1) nextAcc *= -1; |
93 | | - _Acc = nextAcc; |
94 | | - } |
95 | | - _RotateSpeed = (float)(_Rnd.Next(0, (int)(_Settings.RotateSpeedMax * 360)) / 180d / Math.PI); |
96 | | - if (_Rnd.Next(2) == 1) _RotateSpeed *= -1; |
| 86 | + if (Random.Shared.Next(2) == 1) nextAcc *= -1; |
| 87 | + _acc = nextAcc; |
97 | 88 | } |
98 | | - _Counter++; |
| 89 | + _rotateSpeed = (float)(Random.Shared.Next(0, (int)(_settings.RotateSpeedMax * 360)) / 180d / Math.PI); |
| 90 | + if (Random.Shared.Next(2) == 1) _rotateSpeed *= -1; |
99 | 91 | } |
| 92 | + _counter++; |
| 93 | + } |
100 | 94 |
|
101 | | - public void Draw(IGraphics g) |
102 | | - { |
103 | | - if (Alpha == 0) return; |
104 | | - var c = _Color; |
105 | | - if (Alpha != 1) c = Color.FromArgb((int)(Alpha * 255), c); |
106 | | - g.FillEllipse(c, X, Y, _Settings.PointRadius, _Settings.PointRadius); |
107 | | - } |
| 95 | + public void Draw(IGraphics g) |
| 96 | + { |
| 97 | + if (Alpha == 0) return; |
| 98 | + var c = _Color; |
| 99 | + if (Alpha != 1) c = Color.FromArgb((int)(Alpha * 255), c); |
| 100 | + g.FillEllipse(c, X, Y, _settings.PointRadius, _settings.PointRadius); |
| 101 | + } |
108 | 102 |
|
109 | | - public void Dispose() |
110 | | - { |
111 | | - } |
| 103 | + public void Dispose() |
| 104 | + { |
| 105 | + } |
112 | 106 |
|
113 | | - internal void SetStartPos(int x, int y) |
114 | | - { |
115 | | - _XStart = x; |
116 | | - _YStart = y; |
117 | | - } |
| 107 | + public void SetStartPos(int x, int y) |
| 108 | + { |
| 109 | + _xStart = x; |
| 110 | + _yStart = y; |
118 | 111 | } |
119 | 112 | } |
0 commit comments