Esempio n. 1
0
        /// <summary>
        /// Visualizes the Simulation using an unsafe Bitmap - fast, but with the danger of memory leaks
        /// </summary>
        /// <param name="positionMap"></param>
        /// <param name="wallMap"></param>
        /// <param name="massMap"></param>
        /// <param name="xMax"></param>
        /// <param name="yMax"></param>
        /// <returns></returns>
        public Bitmap VisualizePositionMap(double[,] positionMap, bool[,] wallMap, bool[,] addonWallMap, double[,] massMap, double[,] addonMassMap, int xMax, int yMax)
        {
            Bitmap res = new Bitmap(xMax, yMax);

            UnsafeBitmap usb = new UnsafeBitmap(res);

            usb.LockBitmap();

            for (int ix = 0; ix < xMax; ix++)
            {
                for (int iy = 0; iy < yMax; iy++)
                {
                    try
                    { //Sometimes there are array bound exceptions (after resize)
                        Color c = GenerateColor(positionMap, wallMap, addonWallMap, massMap, addonMassMap, ix, iy);
                        //res.SetPixel(ix, iy, c);

                        PixelData d = new PixelData();
                        d.red   = c.R;
                        d.green = c.G;
                        d.blue  = c.B;
                        usb.SetPixel(ix, iy, d);
                    }
                    catch (Exception)
                    {
                        return(res);
                    }
                }
            }

            _lastPosMap = positionMap;
            lastX       = xMax;
            lastY       = yMax;

            usb.UnlockBitmap();

            return(usb.Bitmap);
            //return res;
        }
Esempio n. 2
0
        /// <summary>
        /// Visualizes the Simulation using an unsafe Bitmap - fast, but with the danger of memory leaks
        /// </summary>
        /// <param name="positionMap"></param>
        /// <param name="wallMap"></param>
        /// <param name="massMap"></param>
        /// <param name="xMax"></param>
        /// <param name="yMax"></param>
        /// <returns></returns>
        public Bitmap VisualizePositionMap(double[,] positionMap, bool[,] wallMap, bool[,] addonWallMap, double[,] massMap, double[,] addonMassMap, int xMax, int yMax)
        {
            Bitmap res = new Bitmap(xMax, yMax);

            UnsafeBitmap usb = new UnsafeBitmap(res);
            usb.LockBitmap();

            for (int ix = 0; ix < xMax; ix++)
            {
                for (int iy = 0; iy < yMax; iy++)
                {
                    try
                    { //Sometimes there are array bound exceptions (after resize)
                        Color c = GenerateColor(positionMap, wallMap, addonWallMap, massMap, addonMassMap, ix, iy);
                        //res.SetPixel(ix, iy, c);

                        PixelData d = new PixelData();
                        d.red = c.R;
                        d.green = c.G;
                        d.blue = c.B;
                        usb.SetPixel(ix, iy, d);
                    }
                    catch (Exception)
                    {
                        return res;
                    }

                }
            }

            _lastPosMap = positionMap;
            lastX = xMax;
            lastY = yMax;

            usb.UnlockBitmap();

            return usb.Bitmap;
            //return res;
        }