コード例 #1
0
ファイル: Form1.cs プロジェクト: beentaken/DigiPen
        private void RemoveRegion(int x, int y)
        {
            Point clicked = new Point();

            clicked.X = x;
            clicked.Y = y;
            VRegion clickedRegion = GetRegion(clicked);
            VRegion found         = regions.Find(
                delegate(VRegion val)
            {
                for (int i = 0; i < k; ++i)
                {
                    if (val.indices[i] != clickedRegion.indices[i])
                    {
                        return(false);
                    }
                }
                return(true);
            });

            List <Point> toRemove = new List <Point>(k);

            foreach (int i in found.indices)
            {
                toRemove.Add(points[i]);
            }
            foreach (Point p in toRemove)
            {
                points.Remove(p);
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: beentaken/DigiPen
        private void FillRegions(int width, int height)
        {
            Point tester = new Point();

            toolStripProgressBar1.Visible = true;

            // For each pixel method
            for (int y = 0; y < height; ++y)
            {
                toolStripProgressBar1.Value = (int)((float)y / (float)height);
                for (int x = 0; x < width; ++x)
                {
                    tester.X = x;
                    tester.Y = y;
                    VRegion region = GetRegion(tester);

                    int found = -1;
                    int index = 0;
                    foreach (VRegion r in regions)
                    {
                        bool regionAlreadyExists = false;
                        for (int i = 0; i < k; ++i)
                        {
                            if (r.indices[i] != region.indices[i])
                            {
                                regionAlreadyExists = true;
                                break;
                            }
                        }
                        if (regionAlreadyExists == false)
                        {
                            found = index;
                            break;
                        }
                        index++;
                    }

                    if (found != -1)
                    {
                        for (int i = 0; i < 3; ++i)
                        {
                            rgbs[3 * (y * width + x) + i] = regions[found].color[i];
                        }
                    }
                    else
                    {
                        region.color = Rainbow.GetNext();
                        regions.Add(region);
                        for (int i = 0; i < 3; ++i)
                        {
                            rgbs[3 * (y * width + x) + i] = region.color[i];
                        }
                    }
                }
            }

            toolStripStatusLabel2.Text    = "Regions: " + regions.Count.ToString();
            toolStripProgressBar1.Visible = false;
        }