public DxInstancedLineSingleColorViewModel() { Positions = new DxInstancePoint[] { new DxInstancePoint(0, 0.2f), new DxInstancePoint(0, 0), new DxInstancePoint(0, -0.2f) }; StartCalculatingPoints1(); }
private void StartArrayUpdate() { Task.Factory.StartNew(() => { // Create the random directions var rnd = random.Value; Vector[] directions = Enumerable.Range(0, _pointCount).Select(i => { var angle = rnd.NextDouble() * Math.PI * 2; Vector dxdy = new Vector(Math.Sin(angle), Math.Cos(angle)); return(dxdy); }).ToArray(); while (!_hasBeenDisposed) { if (_doReset) { DoReset(); _doReset = false; } if (_animationRunning) { // Update the position of every point according to its direction var positions = Positions as DxInstancePoint[]; for (int i = 0; i < _pointCount; ++i) { var dxdy = new Vector(directions[i].X * Width1Px, directions[i].Y * Height1Px); var newX = dxdy.X + positions[i].X; var newY = dxdy.Y + positions[i].Y; // Point has hit an east or west wall. Reverse direction vector X component if (newX < 0 || newX > 1) { newX = Math.Min(1, Math.Max(0, newX)); directions[i] = new Vector(-directions[i].X, directions[i].Y); } // Point has hit a north or south wall. Reverse direction vector Y component if (newY < 0 || newY > 1) { newY = Math.Min(1, Math.Max(0, newY)); directions[i] = new Vector(directions[i].X, -directions[i].Y); } _currentArray[i] = new DxInstancePoint(new Point(newX, newY)); } var temp = (Positions as DxInstancePoint[]) ?? new DxInstancePoint[_pointCount]; Positions = _currentArray; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Positions))); _currentArray = temp; } Thread.Sleep(10); } }); }
private void DoReset() { var rnd = random.Value; HSBPalette palette = new HSBPalette(); // Create a new array of points for (int i = 0; i < _pointCount; i++) { var point = new Point(rnd.NextDouble(), rnd.NextDouble()); _currentArray[i] = new DxInstancePoint(new Point(point.X, point.Y)); } // Replace the old array of points with the new array var temp = (Positions as DxInstancePoint[]) ?? new DxInstancePoint[_pointCount]; Positions = _currentArray; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Positions))); _currentArray = temp; }