Exemple #1
0
        public void Update()
        {
            if (_field == null)
            {
                return;
            }



            _visualHost.Update();



            //double[] xVel = _field.XVel;
            //double[] yVel = _field.YVel;

            //if (xVel.Length != yVel.Length)
            //{
            //    throw new ApplicationException("X and Y arrays aren't the same size: " + xVel.Length.ToString() + ", " + yVel.Length.ToString());
            //}
            //if (xVel.Length != _lineVisuals.Length)
            //{
            //    ResetField();
            //    return;     // try again next update
            //}

            //for (int cntr = 0; cntr < xVel.Length; cntr++)
            //{
            //    _lineVisuals[cntr].X2 = _lineVisuals[cntr].X1 + xVel[cntr];
            //    _lineVisuals[cntr].Y2 = _lineVisuals[cntr].Y1 + yVel[cntr];
            //}
        }
Exemple #2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            const double ONEOVER256 = 1d / 256d;

            try
            {
                if (_field == null)
                {
                    _timer.IsEnabled = false;
                    return;
                }

                //TODO: Populate the space between mouse locations from the last tick (instead of drawing spots)

                //TODO: Allow for some keyboard modifiers, brush buttons, etc for more options:
                // Shape
                // Fade/Grow

                if (_isLeftDown || _isRightDown)
                {
                    double radius           = trkBrushSize.Value * .5d;
                    int[]  clickFieldPoints = GetFieldCircle(_mousePointHistory[_mousePointHistory.Count - 1], radius, radius, _field);

                    if (radColorBrush.IsChecked.Value)
                    {
                        #region Color Brush

                        Random rand = StaticRandom.GetRandomForThread();

                        Color  color  = GetRandomColor(rand, _brushColorType);
                        double colorR = color.R * ONEOVER256;
                        double colorG = color.G * ONEOVER256;
                        double colorB = color.B * ONEOVER256;

                        double velScale      = trkVelocityMultiplier.Value;
                        Vector dragVelocity  = GetDragVelocity() ?? new Vector(0, 0);
                        double velX          = dragVelocity.X * velScale;
                        double velY          = dragVelocity.Y * velScale;
                        bool   applyVelocity = _isRightDown || (_isLeftDown && chkVelocityOnLeftDrag.IsChecked.Value);
                        bool   randPerPixel  = chkRandColorPerPixel.IsChecked.Value;

                        foreach (int point in clickFieldPoints)
                        {
                            if (_isLeftDown)
                            {
                                if (randPerPixel)
                                {
                                    color  = GetRandomColor(rand, _brushColorType);
                                    colorR = color.R * ONEOVER256;
                                    colorG = color.G * ONEOVER256;
                                    colorB = color.B * ONEOVER256;
                                }

                                // Add color
                                _field.SetInk(0, point, colorR);
                                _field.SetInk(1, point, colorG);
                                _field.SetInk(2, point, colorB);
                            }

                            if (applyVelocity)
                            {
                                // Add velocity
                                _field.AddVel(point, velX, velY);
                            }
                        }

                        #endregion
                    }
                    else if (radWall.IsChecked.Value)
                    {
                        #region Wall

                        foreach (int point in clickFieldPoints)
                        {
                            _field.SetBlockedCell(point, _isLeftDown);      // if both are down, left wins (execution only gets here if left or right are down, so if left is up, right must be down - or both down, which let left win)
                        }

                        #endregion
                    }
                    else
                    {
                        throw new ApplicationException("Unknown tool brush");
                    }
                }

                if (chkPauseResume.IsChecked.Value)
                {
                    _field.Update();
                }

                DrawField(_bitmap, _field, chkShowWalls.IsChecked.Value);

                // Velocity Viewer
                if (chkVelocityOverlay.IsChecked.Value)
                {
                    _velocityVisualizerPanel.Update();
                }

                if (_velocityVisualizerWindow != null)
                {
                    _velocityVisualizerWindow.Update();
                }

                #region Analyze Field

                // Colors > 1
                if (chkFlagColor.IsChecked.Value)
                {
                    if (_field.Layers.SelectMany(o => o).Any(o => Math.Abs(o) > 1))
                    {
                        chkFlagColor.Background = Brushes.Tomato;
                        chkFlagColor.Foreground = Brushes.Tomato;
                    }
                    else
                    {
                        chkFlagColor.Background = null;
                        chkFlagColor.Foreground = SystemColors.WindowTextBrush;
                    }
                }

                // Velocities > 1
                if (chkFlagVelocity.IsChecked.Value)
                {
                    if (Enumerable.Range(0, _field.KSize).Any(o => _field.XVel[o] * _field.XVel[o] + _field.YVel[o] * _field.YVel[o] > 1))
                    {
                        chkFlagVelocity.Background = Brushes.Tomato;
                        chkFlagVelocity.Foreground = Brushes.Tomato;
                    }
                    else
                    {
                        chkFlagVelocity.Background = null;
                        chkFlagVelocity.Foreground = SystemColors.WindowTextBrush;
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }