Пример #1
0
        private void ResetButton_Click(object sender, EventArgs e)
        {
            BoidCalculations.Reset(AreaWidth / 2, AreaHeight / 2);

            for (int x = 1; x < RenderArea.Width; x++)
            {
                for (int y = 1; y < RenderArea.Height; y++)
                {
                    image.SetPixel(x, y, Color.Black);
                }
            }
        }
Пример #2
0
        public Form1()
        {
            InitializeComponent();

            AreaWidth  = RenderArea.Width;
            AreaHeight = RenderArea.Height;

            image            = new Bitmap(AreaWidth, AreaHeight, PixelFormat.Format32bppRgb);
            RenderArea.Image = image;

            BoidCalculations.Reset(AreaWidth / 2, AreaHeight / 2);
        }
Пример #3
0
        private void RenderArea_MouseMove(object sender, MouseEventArgs e)
        {
            MouseEventArgs mevent = e as MouseEventArgs;

            if (RenderArea.ClientRectangle.Contains(mevent.Location)) // check if mouse inside render area ( prevents crashing)
            {
                if (mevent.Button == MouseButtons.Left)
                {
                    BoidCalculations.GenerateBoids(mevent.X, mevent.Y);
                }
            }
        }
Пример #4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            stopwatch.Restart();


            switch (flavor)
            {
            case Flavors.CPUpar:
                BoidCalculations.CalcBoidsCPUPAR();     // this is the CPU parallel version
                break;

            case Flavors.CPUseq:
            default:
                BoidCalculations.CalcBoidsCPUSEQ();     // this is the CPU sequential version // comment this out if you want to validate parallel calculations
                // BoidCalculations.ValidateParCPU(); // uncomment this if you want to validate parallel calculations
                break;
            }

            foreach (BoidObject Boid in BoidCalculations.BoidArray)
            {
                image.SetPixel(Boid.OldIntPosX, Boid.OldIntPosY, Color.Black);
                image.SetPixel(Boid.IntPosX, Boid.IntPosY, Color.White);
            }

            RenderArea.Refresh();
            double fps = (double)stopwatch.ElapsedTicks / Stopwatch.Frequency;

            FPSLabel.Text = $"FPS: {1 / fps:0.00} ";

            BoidCountLabel.Text = $"Boids on screen: {BoidCalculations.BoidArray.Length:0}";

            if (Recording)
            {
                file.WriteLine($"{flavor}, {fps}, {1/fps}, {BoidCalculations.BoidArray.Length}"); // Flavour, Time since last tick, Framerate, Boids on screen
            }
        }