Exemple #1
0
        public static void DepthSort(Particle[] particles, bool useInsertion)
        {
            // You can select which sorting algorithm you'll be using by uncommenting one of the two function calls below
            // You can visually test both of your algorithms this way

            PerformanceMonitor.TimeExecution(() =>
            {
                if (useInsertion)
                {
                    InsertionDepthSort(particles);
                }
                else
                {
                    QuicksortDepthSort(particles);
                }
            }
                                             );
        }
Exemple #2
0
        /// <summary>
        /// Called when the user presses a key
        /// </summary>
        /// <param name="sender">Ignored</param>
        /// <param name="args">Specifies the key that was pressed</param>
        void KeyboardHandler(object sender, KeyEventArgs args)
        {
            switch (args.KeyCode)
            {
            case Keys.Space:
                isRotating = !isRotating;
                break;

            case Keys.S:
                useInsertion = !useInsertion;
                break;

            case Keys.R:
                PerformanceMonitor.ResetTimes();
                break;
            }
            PerformanceMonitor.ResetTimes();
        }
Exemple #3
0
        /// <summary>
        /// Redraw the window
        /// </summary>
        /// <param name="sender">Ignored</param>
        /// <param name="args">Magic object that includes another magic object that lets you draw in the window</param>
        void DrawFrame(object sender, PaintEventArgs args)
        {
            // Update time information
            var newTime  = Environment.TickCount;
            var interval = newTime - time;

            time = newTime;

            // Update particle positions
            particleSystem.Update(interval);

            // Update screen positions
            if (isRotating)
            {
                Particle.RotateSlightly();
            }

            // Depth sort
            Sorting.DepthSort(particleSystem.Particles, useInsertion);

            // Do the actual drawing
            args.Graphics.Clear(Color.Black);
            particleSystem.Render(args.Graphics);

            // Update performance information in the title bar
            var sort = useInsertion ? "InsertionSort" : "QuickSort";

            // ReSharper disable once LocalizableElement
            Text = $"{sort} MinTime: {PerformanceMonitor.MinTimeString()} MaxTime: {PerformanceMonitor.MaxTimeString()} AvgTime: {PerformanceMonitor.AvgTimeString()}";

            // Tell the OS to schedule another frame redraw
            Invalidate();
        }