Example #1
0
        private static void TestGenerateBasicMap()
        {
            var buffer = new Rgba32[width * height];

            fn.SetFractalOctaves(6);
            fn.SetFrequency(0.0007f);

            for (int i = 0; i < buffer.Length; i++)
            {
                var p0         = ArrayIndex.From1DTo2D(i, width);
                var pixelValue = fn.GetCellular(p0.X, p0.Y);

                if (pixelValue > 0)
                {
                    buffer[i] = new Rgba32(pixelValue, 10 + 1.0f * pixelValue, 0.0f);
                }
                else
                {
                    buffer[i] = new Rgba32(pixelValue, 0.0f, 10 + 1.0f * pixelValue);
                }
            }

            var time = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture).Replace(":", "-");

            CreateDirectoryIfNotExists("./data");
            //ImageWriter.FastWrite(ref buffer, $"./data/TestGenerateBasicMap-{time}.png", width, height);
        }
Example #2
0
        private static void TestIntensityImage()
        {
            var buffer = new Rgba32[width * height];

            Func <double, double, double, double> getCentralIntensity = (r, i0, k) => i0 *Math.Exp(-k *Math.Pow(r, 0.25));

            Func <double, double, double, double> getOuterIntensity = (r, i0, a) => i0 *Math.Exp(-r / a);

            Func <double, double> getSurfaceBrightness = (r) => {
                double i0 = 1.0, k = 0.02, a = 200;
                double bulgeradius = (width + height) * 0.05;
                return(r < bulgeradius?getCentralIntensity(r, i0, k) :
                           getOuterIntensity(r - bulgeradius, getCentralIntensity(bulgeradius, i0, k), a));
            };

            for (int i = 0; i < width * height; i++)
            {
                var p0        = ArrayIndex.From1DTo2D(i, width);
                var distance  = (p0 - new Vector2(width / 2, height / 2)).Length();
                var intensity = (float)Math.Clamp(getSurfaceBrightness(distance), 0, 1);
                var color     = new Rgba32(intensity, intensity, intensity);
                buffer[i] = color;
            }

            var time = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture).Replace(":", "-");

            CreateDirectoryIfNotExists("./data");
            // ImageWriter.FastWrite(ref buffer, $"./data/TestIntensityImage-{time}.png", width, height);
        }
Example #3
0
File: Image.cs Project: kenwi/simd
        public static void Write(ref int[] buffer, string file, int width, int height)
        {
            var image = new System.Drawing.Bitmap(width, height);

            for (int i = 0; i < buffer.Length - 1; i++)
            {
                var index = ArrayIndex.From1DTo2D(i, width);
                var color = Color.FromArgb(buffer[i], buffer[i], buffer[i]);
                image.SetPixel((int)index.X, (int)index.Y, color);
            }
            image.Save(file);
        }
Example #4
0
 public void UpdateCanvas(ref Rgba32[] canvas, ref float[] positionX, ref float[] positionY)
 {
     for (int i = 0; i < numParticles; i++)
     {
         var x = (int)positionX[i];
         var y = (int)positionY[i];
         if (x < width && y < height)
         {
             var index = ArrayIndex.From2DTo1D(x, y, width);
             canvas[index] = new Rgba32(255, 255, 255, 255);
         }
     }
 }
Example #5
0
        internal void Update(ref float[] positionX, ref float[] positionY)
        {
            frame = new Image <Rgba32>(width, height);
            var pixels = frame.GetPixelSpan();

            for (int i = 0; i < positionX.Length; i++)
            {
                var px = wrapAround(positionX[i], width - 1);
                var py = wrapAround(positionY[i], height - 1);

                var index = ArrayIndex.From2DTo1D((int)px, (int)py, width);
                pixels[index] = new Rgba32(255, 255, 255);
            }
        }