Exemplo n.º 1
0
        public void CalculateThread(int verticalDiv, int horizontalDiv)
        {
            CalculationStopper.Restart();

            List <Thread> threads = new List <Thread>();

            for (int vertical = 0; vertical < verticalDiv; vertical++)
            {
                for (int horizontal = 0; horizontal < horizontalDiv; horizontal++)
                {
                    int vertical_copy   = vertical;
                    int horizontal_copy = horizontal;

                    threads.Add(new Thread(() =>
                    {
                        int _widthBase        = (ArrayWidth / horizontalDiv);
                        int _heightBase       = (ArrayHeight / verticalDiv);
                        int borderWidthLower  = _widthBase * horizontal_copy;
                        int borderWidthUpper  = _widthBase * (horizontal_copy + 1);
                        int borderHeightLower = _heightBase * vertical_copy;
                        int borderHeightUpper = _heightBase * (vertical_copy + 1);

                        for (int i = borderWidthLower; i < borderWidthUpper; i++)
                        {
                            for (int j = borderHeightLower; j < borderHeightUpper; j++)
                            {
                                HeatBlock hb = HeatBlocks[i, j];

                                float left   = i == 0 ? hb.Temperature : HeatBlocks[i - 1, j].Temperature;
                                float right  = i == ArrayWidth - 1 ? hb.Temperature : HeatBlocks[i + 1, j].Temperature;
                                float top    = j == ArrayHeight - 1 ? hb.Temperature : HeatBlocks[i, j + 1].Temperature;
                                float botton = j == 0 ? hb.Temperature : HeatBlocks[i, j - 1].Temperature;

                                hb.CalculateColor(left, right, top, botton);
                            }
                        }
                    }));
                }
            }

            threads.ForEach(t => t.Start());
            threads.ForEach(t => t.Join());

            CalculationStopper.Stop();
            CalculationTime = CalculationStopper.ElapsedTicks;
        }
        public void Calculate()
        {
            for (int i = 0; i < ArrayWidth; i++)
            {
                for (int j = 0; j < ArrayHeight; j++)
                {
                    HeatBlock hb = HeatBlocks[i, j];

                    float left   = i == 0 ? hb.Temperature : HeatBlocks[i - 1, j].Temperature;
                    float right  = i == ArrayWidth - 1 ? hb.Temperature : HeatBlocks[i + 1, j].Temperature;
                    float top    = j == ArrayHeight - 1 ? hb.Temperature : HeatBlocks[i, j + 1].Temperature;
                    float botton = j == 0 ? hb.Temperature : HeatBlocks[i, j - 1].Temperature;

                    hb.CalculateColor(left, right, top, botton);
                }
            }
        }
Exemplo n.º 3
0
        public void Calculate()
        {
            CalculationStopper.Restart();

            for (int i = 0; i < ArrayWidth; i++)
            {
                for (int j = 0; j < ArrayHeight; j++)
                {
                    HeatBlock hb = HeatBlocks[i, j];

                    float left   = i == 0 ? hb.Temperature : HeatBlocks[i - 1, j].Temperature;
                    float right  = i == ArrayWidth - 1 ? hb.Temperature : HeatBlocks[i + 1, j].Temperature;
                    float top    = j == ArrayHeight - 1 ? hb.Temperature : HeatBlocks[i, j + 1].Temperature;
                    float botton = j == 0 ? hb.Temperature : HeatBlocks[i, j - 1].Temperature;

                    hb.CalculateColor(left, right, top, botton);
                }
            }

            CalculationStopper.Stop();
            CalculationTime = CalculationStopper.ElapsedTicks;
        }