Пример #1
0
        //TODO: Take in previous hue's and have a slight chance of 120 or 90 degree offset instead of always 0 and 180
        private static double GetRandomHue(double hue)
        {
            // Randomly choose a new hue that is similar to the one passed in
            double retVal = hue + StaticRandom.NextPow(3d, 18d, true);

            if (retVal < 0d)
            {
                retVal += 360d;
            }
            else if (retVal > 360d)
            {
                retVal -= 360d;
            }

            // Maybe rotate 180 degrees
            if (StaticRandom.Next(2) == 0)
            {
                retVal += 180d;

                if (retVal < 0d)
                {
                    retVal += 360d;
                }
                else if (retVal > 360d)
                {
                    retVal -= 360d;
                }
            }

            return(retVal);
        }
Пример #2
0
        private void AddBot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                const double DISTANCE = 3;

                Point3D position = _camera.Position + (_camera.LookDirection.ToUnit() * DISTANCE);
                position += Math3D.GetRandomVector_Spherical(DISTANCE / 3);

                double radius;
                if (chkRandBotSize.IsChecked.Value)
                {
                    double percent = StaticRandom.NextPow(3, isPlusMinus: true);
                    //double percent = StaticRandom.NextBool() ? 1d : -1d;      // use to test the extremes
                    percent *= SWARMBOTRANDSIZEPERCENT;

                    if (percent > 0)
                    {
                        radius = SWARMBOTRADIUS * (1d + percent);
                    }
                    else
                    {
                        radius = SWARMBOTRADIUS / (1d + Math.Abs(percent));
                    }
                }
                else
                {
                    radius = SWARMBOTRADIUS;
                }

                SwarmBot1a bot = new SwarmBot1a(radius, position, _world, _map, _strokes, _material_Bot);

                SetBotConstraints(bot);

                bot.PhysicsBody.AngularVelocity = Math3D.GetRandomVector_Spherical(3d);

                _map.AddItem(bot);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }