Beispiel #1
0
        static void Main(string[] args)
        {
            const int NUM_NODES = 65_000;
            const int WIDTH     = 1920;
            const int HEIGHT    = 1080;

            Random             rnd    = new Random();
            Bitmap             bmp    = new Bitmap(WIDTH, HEIGHT);
            List <VoronoiNode> vnodes = new List <VoronoiNode>(NUM_NODES);

            for (int i = 0; i < NUM_NODES; i++)
            {
                vnodes.Add(new VoronoiNode(rnd.Next(0, 1920), rnd.Next(0, 1080)));
            }

            for (int x = 0; x < WIDTH; x++)
            {
                for (int y = 0; y < HEIGHT; y++)
                {
                    VoronoiNode psuedoNode = new VoronoiNode(x, y);
                    VoronoiNode closest    = vnodes[0];

                    for (int i = 1; i < NUM_NODES; i++)
                    {
                        if (Distance(psuedoNode, vnodes[i]) < Distance(psuedoNode, closest))
                        {
                            closest = vnodes[i];
                        }
                    }

                    float rcol = (closest.x - psuedoNode.x) + 128;
                    float gcol = (closest.y - psuedoNode.y) + 128;
                    float bcol = map(Distance(psuedoNode, closest), 0, 182, 0, 255);

                    bmp.SetPixel(x, y, Color.FromArgb((int)rcol, (int)gcol, (int)bcol));
                }
                Console.WriteLine("COL {0}", x);
            }

            bmp.Save("mask.png", System.Drawing.Imaging.ImageFormat.Png);
        }
Beispiel #2
0
 static float Distance(VoronoiNode a, VoronoiNode b)
 {
     return((float)Math.Sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)));
 }