コード例 #1
0
        public Image DrawGrid(grid grid)
        {
            int maxRows = grid.maxRows;
            int maxCols = grid.maxColumns;

            var image = new Image <Rgba32>(maxRows, maxCols);


            for (int row = 0; row < maxRows; row++)
            {
                for (int column = 0; column < maxCols; column++)
                {
                    pixel pixelToDraw = grid.getPixel(row, column);
                    if (pixelToDraw.isAlive())
                    {
                        image[row, column] = Rgba32.White;
                    }
                    else
                    {
                        image[row, column] = Rgba32.Black;
                    }
                }
            }

            return(image);
        }
コード例 #2
0
ファイル: cam0.cs プロジェクト: s33hunt/VR-Hand-Controller
    void CheckAdjacentRecursive(pixel p, int blobIndex)
    {
        safety++;
        if(safety > maxBlobPasses) { return; }
        //continue if pixel in used list
        if (checkedPixelIndexes.Contains(p.index)) { return; }
        checkedPixelIndexes.Add(p.index);
        //create target blob if not exist
        if (!blobs.ContainsKey(blobIndex)) { blobs.Add(blobIndex, new List<pixel>()); }

        List<pixel> checkList = new List<pixel>();

        //check adjacent pixels
        for (int i = -1; i <= 1; i++) {
            int xval = p.x + i;
            if (pixelMapX.ContainsKey(xval)) {
                foreach (pixel ypix in pixelMapX[xval]) {
                    //get adjacent
                    if (Mathf.Abs(ypix.y - p.y) <= 1) { checkList.Add(ypix); }
                }
            }
        }

        //for those, check and get adjacent
        foreach(pixel c in checkList)
        {
            blobs[blobIndex].Add(c);
            CheckAdjacentRecursive(c, blobIndex);
        }
        //when non left, create blob
        //continue loop
    }
コード例 #3
0
    static void Test1()
    {
        pixel[,,,] myArray = new pixel[4, 4, 4, 4];

        for (int i1 = 0; i1 < myArray.GetLength(0); i1++)
        {
            for (int i2 = 0; i2 < myArray.GetLength(1); i2++)
            {
                for (int i3 = 0; i3 < myArray.GetLength(2); i3++)
                {
                    for (int i4 = 0; i4 < myArray.GetLength(3); i4++)
                    {
                        myArray[i1, i2, i3, i4].x = (i1 + i3) | (i2 + i4);
                        myArray[i1, i2, i3, i4].y = (i1 + i2) ^ (i3 + i4);
                    }
                }
            }
        }


        for (int i1 = 0; i1 < myArray.GetLength(0); i1++)
        {
            for (int i2 = 0; i2 < myArray.GetLength(1); i2++)
            {
                for (int i3 = 0; i3 < myArray.GetLength(2); i3++)
                {
                    for (int i4 = 0; i4 < myArray.GetLength(3); i4++)
                    {
                        Console.WriteLine("myArray[{0}, {1}, {2}, {3}]= ({4} , {5})", i1, i2, i3, i4, myArray[i1, i2, i3, i4].x, myArray[i1, i2, i3, i4].y);
                    }
                }
            }
        }
    }
コード例 #4
0
ファイル: Grid.cs プロジェクト: JDavidMartin/Game-of-Life
        private void handleNeighbours(pixel IndividualPixel)
        {
            int numNeighbours = IndividualPixel.getNumberNeighbours();

            if (IndividualPixel.isAlive())
            {
                switch (numNeighbours)
                {
                case (2):     //2 or 3 just right
                    break;

                case (3):
                    break;

                default:
                    IndividualPixel.SetStatus(false);     // 0,1 underpopulation - 4,5,6,7 overpopulation
                    break;
                }
            }
            else
            {
                switch (numNeighbours)
                {
                case (3):
                    IndividualPixel.SetStatus(true);
                    break;

                default:
                    break;
                }
            }
        }
コード例 #5
0
ファイル: cam0.cs プロジェクト: s33hunt/VR-Hand-Controller
    IEnumerator UpdateStuff()
    {
        while (true)
        {
            yield return(new WaitForSeconds(framerate));

            Color32[] camPixels = webcamTexture.GetPixels32();


            for (int i = 0; i < camPixels.Length; i++)
            {
                //if below threshold, make black
                if (camPixels[i].r < threshold && camPixels[i].g < threshold && camPixels[i].b < threshold)
                {
                    camPixels[i].g = 0;
                    camPixels[i].r = 0;
                    camPixels[i].b = 0;
                    //else add it to pixel list for processing
                }
                else
                {
                    int x   = i % webcamTexture.width,
                        y   = Mathf.FloorToInt((float)i / (float)webcamTexture.width);
                    pixel p = new pixel(x, y, i, camPixels[i]);
                    pixels.Add(p);
                    if (!pixelMapX.ContainsKey(x))
                    {
                        pixelMapX.Add(x, new List <pixel>());
                    }
                    pixelMapX[x].Add(p);
                }
            }

            foreach (var p in pixels)
            {
                if (checkedPixelIndexes.Contains(p.index))
                {
                    continue;
                }
                CheckAdjacentRecursive(p, blobs.Count);
            }


            for (int i = 0; i < blobs.Count; i++)
            {
                foreach (pixel p in blobs[i])
                {
                    float c = (float)blobs.Count / (float)i;
                    camPixels[p.index] = new Color(0, c, 1 - c, 1);
                }
            }

            t.SetPixels32(camPixels);
            t.Apply();
            targetRend.material.mainTexture = t;

            Reset();
        }
    }
コード例 #6
0
ファイル: pixel.cs プロジェクト: bigstupidx/JSBU
 void Awake()
 {
     instance = this;
     if (loadNumber == 0)
     {
         ParseItemJson();
     }
 }
コード例 #7
0
ファイル: Grid.cs プロジェクト: JDavidMartin/Game-of-Life
 private void CalculateAndUpdateNumberNeighbours()
 {
     for (int row = 0; row < maxRows; row++)
     {
         for (int column = 0; column < maxColumns; column++)
         {
             pixel currentPixel  = getPixel(row, column);
             int   numNeighbours = getNumNeighbours(row, column);
             currentPixel.SetNumNeighbours(numNeighbours);
         }
     }
 }
コード例 #8
0
ファイル: Grid.cs プロジェクト: JDavidMartin/Game-of-Life
        public void initiateGrid(int percentageLiving)
        {
            Random livingRNG = new Random();

            for (int i = 0; i <= maxRows; i++)
            {
                for (int j = 0; j <= maxColumns; j++)
                {
                    bool livingbool = (livingRNG.Next(0, 101) > percentageLiving);
                    Pixels[i, j] = new pixel(i, j, livingbool);
                }
            }
        }
コード例 #9
0
ファイル: Grid.cs プロジェクト: JDavidMartin/Game-of-Life
        public void UpdateGrid()
        {
            CalculateAndUpdateNumberNeighbours();

            for (int row = 0; row < maxRows; row++)
            {
                for (int column = 0; column < maxColumns; column++)
                {
                    pixel currentPixel = getPixel(row, column);
                    handleNeighbours(currentPixel);
                }
            }
        }
コード例 #10
0
        public void UpdateParamsIfNeed(double[,] image)
        {
            int _size0 = image.GetUpperBound(0);
            int _size1 = image.GetUpperBound(1);

            if (size1 == _size1 && size0 == _size0)
            {
                return;
            }
            size0  = _size0;
            size1  = _size1;
            pixels = new pixel[size0 + 1, size1 + 1];
            for (int i = 0; i <= size0; i++)
            {
                for (int j = 0; j <= size1; j++)
                {
                    pixels[i, j] = new pixel()
                    {
                        reliability = 0, i = i, j = j
                    };
                }
            }
            List <edge> edges = new List <edge>()
            {
                new edge()
                {
                    pixel1 = pixels[0, 0], pixel2 = pixels[0, 1]
                },
                new edge()
                {
                    pixel1 = pixels[0, 0], pixel2 = pixels[1, 0]
                }
            };

            for (int i = 1; i <= size0; i++)
            {
                for (int j = 1; j <= size1; j++)
                {
                    edges.Add(new edge()
                    {
                        pixel1 = pixels[i - 1, j], pixel2 = pixels[i, j]
                    });
                    edges.Add(new edge()
                    {
                        pixel1 = pixels[i, j - 1], pixel2 = pixels[i, j]
                    });
                }
            }
            _edges = edges.ToArray();
            edges_reliabilities = (from e in _edges select e.reaibility).ToArray();
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: Lexxn0x3/Raytracing-Engine
        static void render()
        {
            int    width      = 1920;
            int    height     = 1080;
            int    colorDepth = 255;
            float  fov        = (float)(Math.PI / 3);
            Sphere sphere     = new Sphere();

            sphere.center = new Vector3(0, 0, -10);
            sphere.radius = (float)3;
            List <pixel> framebuffer = new List <pixel>();

            //for (int i = 0; i < height; i ++)
            //{
            //    for (int j = 0; j < width; j++)
            //    {
            //        pixel newPixel = new pixel();

            //        newPixel.r = (i* colorDepth) / height;
            //        newPixel.g = ((width - j)* colorDepth) / width;
            //        newPixel.b = ((height - i) * colorDepth) / height;

            //        framebuffer.Add(newPixel);
            //    }
            //}

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    pixel newPixel = new pixel();

                    float x = (float)((2 * (i + 0.5) / (float)width - 1) * Math.Tan(fov / 2) * width / (float)height);
                    float y = (float)(-(2 * (j + 0.5) / (float)height - 1) * Math.Tan(fov / 2));

                    Vector3 dir = Vector3.Normalize(new Vector3(x, y, -1));

                    Vector3 color = cast_ray(new Vector3(0, 0, 0), dir, sphere);

                    newPixel.r = (int)color.X;
                    newPixel.g = (int)color.Y;
                    newPixel.b = (int)color.Z;

                    framebuffer.Add(newPixel);
                }
            }

            savePPM(framebuffer, width, height, colorDepth);
        }
コード例 #12
0
    void CheckAdjacentRecursive(pixel p, int blobIndex)
    {
        safety++;
        if (safety > maxBlobPasses)
        {
            return;
        }
        //continue if pixel in used list
        if (checkedPixelIndexes.Contains(p.index))
        {
            return;
        }
        checkedPixelIndexes.Add(p.index);
        //create target blob if not exist
        if (!blobs.ContainsKey(blobIndex))
        {
            blobs.Add(blobIndex, new List <pixel>());
        }

        List <pixel> checkList = new List <pixel>();

        //check adjacent pixels
        for (int i = -1; i <= 1; i++)
        {
            int xval = p.x + i;
            if (pixelMapX.ContainsKey(xval))
            {
                foreach (pixel ypix in pixelMapX[xval])
                {
                    //get adjacent
                    if (Mathf.Abs(ypix.y - p.y) <= 1)
                    {
                        checkList.Add(ypix);
                    }
                }
            }
        }

        //for those, check and get adjacent
        foreach (pixel c in checkList)
        {
            blobs[blobIndex].Add(c);
            CheckAdjacentRecursive(c, blobIndex);
        }
        //when non left, create blob
        //continue loop
    }
コード例 #13
0
 static bool hasBlackAround(pixel curr, ref List <pixel> veryfied, Bitmap img)
 {
     for (float i = curr.a - 1; i < curr.a - 1 + 3; i++)
     {
         for (float j = curr.b - 1; j < curr.b - 1 + 3; j++)
         {
             try
             {
                 if (!colorEquals(img.GetPixel((int)i, (int)j), Color.White) && !veryfied.Exists(x => x.a == i && x.b == j))
                 {
                     return(true);
                 }
             }
             catch (Exception ex) { }
         }
     }
     return(false);
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: NiallMcCann10/Snake
        static void Main(string[] args)
        {
            Console.WindowHeight = 24;
            Console.WindowWidth  = 48;
            int    screenwidth  = Console.WindowWidth;
            int    screenheight = Console.WindowHeight;
            Random randomnummer = new Random();
            int    score        = 5;
            int    gameover     = 0;
            pixel  pix          = new pixel();

            pix.possx  = screenwidth / 2;
            pix.possy  = screenheight / 2;
            pix.leader = ConsoleColor.Yellow;
            string     movement      = "UP";
            List <int> possxlijf     = new List <int>();
            List <int> possylijf     = new List <int>();
            int        capturex      = randomnummer.Next(0, screenwidth);
            int        capturey      = randomnummer.Next(0, screenheight);
            DateTime   time          = DateTime.Now;
            DateTime   time2         = DateTime.Now;
            string     buttonpressed = "no";

            while (true)
            {
                Console.Clear();
                if (pix.possx == screenwidth - 1 || pix.possx == 0 || pix.possy == screenheight - 1 || pix.possy == 0)
                {
                    gameover = 1;
                }
                for (int i = 0; i < screenwidth; i++)
                {
                    Console.SetCursorPosition(i, 0);
                    Console.Write("■");
                }
                for (int i = 0; i < screenwidth; i++)
                {
                    Console.SetCursorPosition(i, screenheight - 1);
                    Console.Write("■");
                }
                for (int i = 0; i < screenheight; i++)
                {
                    Console.SetCursorPosition(0, i);
                    Console.Write("■");
                }
                for (int i = 0; i < screenheight; i++)
                {
                    Console.SetCursorPosition(screenwidth - 1, i);
                    Console.Write("■");
                }
                Console.ForegroundColor = ConsoleColor.Green;
                if (capturex == pix.possx && capturey == pix.possy)
                {
                    score++;
                    capturex = randomnummer.Next(1, screenwidth - 2);
                    capturey = randomnummer.Next(1, screenheight - 2);
                }
                for (int i = 0; i < possxlijf.Count(); i++)
                {
                    Console.SetCursorPosition(possxlijf[i], possylijf[i]);
                    Console.Write("■");
                    if (possxlijf[i] == pix.possx && possylijf[i] == pix.possy)
                    {
                        gameover = 1;
                    }
                }
                if (gameover == 1)
                {
                    break;
                }
                Console.SetCursorPosition(pix.possx, pix.possy);
                Console.ForegroundColor = pix.leader;
                Console.Write("■");
                Console.SetCursorPosition(capturex, capturey);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("■");
                time          = DateTime.Now;
                buttonpressed = "no";
                while (true)
                {
                    time2 = DateTime.Now;
                    if (time2.Subtract(time).TotalMilliseconds > 500)
                    {
                        break;
                    }
                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo toets = Console.ReadKey(true);
                        //Console.WriteLine(toets.Key.ToString());
                        if (toets.Key.Equals(ConsoleKey.UpArrow) && movement != "DOWN" && buttonpressed == "no")
                        {
                            movement      = "UP";
                            buttonpressed = "yes";
                        }
                        if (toets.Key.Equals(ConsoleKey.DownArrow) && movement != "UP" && buttonpressed == "no")
                        {
                            movement      = "DOWN";
                            buttonpressed = "yes";
                        }
                        if (toets.Key.Equals(ConsoleKey.LeftArrow) && movement != "RIGHT" && buttonpressed == "no")
                        {
                            movement      = "LEFT";
                            buttonpressed = "yes";
                        }
                        if (toets.Key.Equals(ConsoleKey.RightArrow) && movement != "LEFT" && buttonpressed == "no")
                        {
                            movement      = "RIGHT";
                            buttonpressed = "yes";
                        }
                    }
                }
                possxlijf.Add(pix.possx);
                possylijf.Add(pix.possy);
                switch (movement)
                {
                case "UP":
                    pix.possy--;
                    break;

                case "DOWN":
                    pix.possy++;
                    break;

                case "LEFT":
                    pix.possx--;
                    break;

                case "RIGHT":
                    pix.possx++;
                    break;
                }
                if (possxlijf.Count() > score)
                {
                    possxlijf.RemoveAt(0);
                    possylijf.RemoveAt(0);
                }
            }
            Console.SetCursorPosition(screenwidth / 5, screenheight / 2);
            Console.WriteLine("Game over, Score: " + score);
            Console.SetCursorPosition(screenwidth / 5, screenheight / 2 + 1);
        }
コード例 #15
0
        public int ShipMove(int currentplanet)
        {
            //int currentplanet = 5;
            Console.WindowHeight = 32;
            Console.WindowWidth  = 64;
            int    screenwidth  = Console.WindowWidth;
            int    screenheight = Console.WindowHeight;
            Random randomnummer = new Random();
            int    score        = 5;

            pixel ship = new pixel();

            //this is where the ship starts make this the current planet position - 1 or 2 pixels for xpos



            string     movement = "RIGHT";
            List <int> xposlijf = new List <int>();
            List <int> yposlijf = new List <int>();

            //THIS IS THE BERRY start POSITIONING.
            //int berry1x = randomnummer.Next(0, screenwidth);
            //int berry1y = randomnummer.Next(0, screenheight);

            int berry1x = screenwidth / 4;
            int berry1y = screenheight / 4;

            int berry2x = (3 * (screenwidth / 4));
            int berry2y = (3 * (screenheight / 4));

            int berry3x = (2 * (screenwidth / 4));
            int berry3y = (2 * (screenheight / 4));

            int berry4x = (screenwidth / 4);
            int berry4y = (3 * (screenheight / 4));

            int berry5x = (6 * (screenheight / 4));
            int berry5y = (screenwidth / 8);

            if (currentplanet == 1)
            {
                ship.xpos        = (screenwidth / 4) + 1;
                ship.ypos        = (screenheight / 4) + 1;
                ship.schermkleur = ConsoleColor.Red;
            }
            else if (currentplanet == 2)
            {
                ship.xpos        = (3 * (screenwidth / 4)) + 1;
                ship.ypos        = (3 * (screenheight / 4)) + 1;
                ship.schermkleur = ConsoleColor.Red;
            }
            else if (currentplanet == 3)
            {
                ship.xpos        = (2 * (screenwidth / 4)) + 1;
                ship.ypos        = (2 * (screenheight / 4)) + 1;
                ship.schermkleur = ConsoleColor.Red;
            }
            else if (currentplanet == 4)
            {
                ship.xpos        = (screenwidth / 4) + 1;
                ship.ypos        = (3 * (screenheight / 4)) + 1;
                ship.schermkleur = ConsoleColor.Red;
            }
            else if (currentplanet == 5)
            {
                ship.xpos        = (6 * (screenheight / 4)) + 1;
                ship.ypos        = (screenwidth / 8) + 1;
                ship.schermkleur = ConsoleColor.Red;
            }


            DateTime tijd          = DateTime.Now;
            DateTime tijd2         = DateTime.Now;
            string   buttonpressed = "no";

            // We only draw the border once. It doesn't change.
            DrawBorder(screenwidth, screenheight);

            while (true)
            {
                ClearConsole(screenwidth, screenheight);
                if (ship.xpos == screenwidth - 1)
                {
                    ship.xpos = 1;
                }
                if (ship.xpos == 0)
                {
                    ship.xpos = screenwidth - 2;
                }
                if (ship.ypos == screenheight - 1)
                {
                    ship.ypos = 1;
                }
                if (ship.ypos == 0)
                {
                    ship.ypos = screenheight - 2;
                }



                //  THIS IS WHERE THE SHIP HITS THE BERRY

                Console.ForegroundColor = ConsoleColor.Green;
                if (berry1x == ship.xpos && berry1y == ship.ypos)
                {
                    currentplanet = 1;
                    Console.Clear();
                    Console.WriteLine("You are now on earth");
                    Thread.Sleep(1000);
                    break;
                }
                if (berry2x == ship.xpos && berry2y == ship.ypos)
                {
                    currentplanet = 2;
                    Console.Clear();
                    Console.WriteLine("You are now on Jupiter");
                    Thread.Sleep(1000);
                    break;
                }
                if (berry3x == ship.xpos && berry3y == ship.ypos)
                {
                    currentplanet = 3;
                    Console.Clear();
                    Console.WriteLine("You are now on Pluto");
                    Thread.Sleep(1000);
                    break;
                }
                if (berry4x == ship.xpos && berry4y == ship.ypos)
                {
                    currentplanet = 4;
                    Console.Clear();
                    Console.WriteLine("You are now at the Sun Lounge");
                    Thread.Sleep(1000);
                    break;
                }
                if (berry5x == ship.xpos && berry5y == ship.ypos)
                {
                    currentplanet = 5;
                    Console.Clear();
                    Console.WriteLine("You are now on Mars");
                    Thread.Sleep(1000);
                    break;
                }



                //THIS MOVES THE SHIP
                Console.SetCursorPosition(ship.xpos, ship.ypos);
                Console.ForegroundColor = ship.schermkleur;
                Console.Write("■");

                //writes the berry
                Console.SetCursorPosition((berry1x + 1), berry1y);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Earth");
                Console.SetCursorPosition(berry1x, berry1y);
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("■");

                Console.SetCursorPosition((berry2x + 1), berry2y);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Jupiter");
                Console.SetCursorPosition(berry2x, berry2y);
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.Write("■");

                Console.SetCursorPosition((berry3x + 1), berry3y);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Pluto");
                Console.SetCursorPosition(berry3x, berry3y);
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.Write("■");

                Console.SetCursorPosition((berry4x + 1), berry4y);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("The Sun Lounge");
                Console.SetCursorPosition(berry4x, berry4y);
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("■");

                Console.SetCursorPosition((berry5x + 1), berry5y);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Mars");
                Console.SetCursorPosition(berry5x, berry5y);
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.Write("■");


                //THIS MOVES THE SHIP
                Console.CursorVisible = false;
                tijd          = DateTime.Now;
                buttonpressed = "no";

                while (true)
                {
                    tijd2 = DateTime.Now;
                    if (tijd2.Subtract(tijd).TotalMilliseconds > 250)
                    {
                        break;
                    }
                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo toets = Console.ReadKey(true);
                        //Console.WriteLine(toets.Key.ToString());
                        if (toets.Key.Equals(ConsoleKey.UpArrow) && movement != "DOWN" && buttonpressed == "no")
                        {
                            movement      = "UP";
                            buttonpressed = "yes";
                            //(new SoundPlayer(@"c:\Users\knpix\OneDrive\Desktop\SPACEGAME BACKUP LOG\testing_grounds 20190730.1\Slow_Motion_Warp-CouchMango-1259869864.wav")).PlaySync();
                        }
                        if (toets.Key.Equals(ConsoleKey.DownArrow) && movement != "UP" && buttonpressed == "no")
                        {
                            movement      = "DOWN";
                            buttonpressed = "yes";
                            //(new SoundPlayer(@"c:\Users\knpix\OneDrive\Desktop\SPACEGAME BACKUP LOG\testing_grounds 20190730.1\Slow_Motion_Warp-CouchMango-1259869864.wav")).PlaySync();
                        }
                        if (toets.Key.Equals(ConsoleKey.LeftArrow) && movement != "RIGHT" && buttonpressed == "no")
                        {
                            movement      = "LEFT";
                            buttonpressed = "yes";
                            //(new SoundPlayer(@"c:\Users\knpix\OneDrive\Desktop\SPACEGAME BACKUP LOG\testing_grounds 20190730.1\Slow_Motion_Warp-CouchMango-1259869864.wav")).PlaySync();
                        }
                        if (toets.Key.Equals(ConsoleKey.RightArrow) && movement != "LEFT" && buttonpressed == "no")
                        {
                            movement      = "RIGHT";
                            buttonpressed = "yes";
                            //(new SoundPlayer(@"c:\Users\knpix\OneDrive\Desktop\SPACEGAME BACKUP LOG\testing_grounds 20190730.1\Slow_Motion_Warp-CouchMango-1259869864.wav")).PlaySync();
                        }
                    }
                }
                xposlijf.Add(ship.xpos);
                yposlijf.Add(ship.ypos);
                switch (movement)
                {
                case "UP":
                    ship.ypos--;
                    break;

                case "DOWN":
                    ship.ypos++;
                    break;

                case "LEFT":
                    ship.xpos--;
                    break;

                case "RIGHT":
                    ship.xpos++;
                    break;
                }
                if (xposlijf.Count() > score)
                {
                    xposlijf.RemoveAt(0);
                    yposlijf.RemoveAt(0);
                }
            }
            //(new SoundPlayer(@"c:\Users\knpix\OneDrive\Desktop\SPACEGAME BACKUP LOG\testing_grounds 20190730.1\Slow_Motion_Warp-CouchMango-1259869864.wav")).PlaySync();



            //Console.WriteLine(currentplanet);
            return(currentplanet);
            //Console.SetCursorPosition(screenwidth / 5, screenheight / 2);
            //Console.WriteLine("Game over, Score: " + score);
            //Console.SetCursorPosition(screenwidth / 5, screenheight / 2 + 1);
        }
コード例 #16
0
    /// <summary>
    /// This procedure contains the user code. Input parameters are provided as regular arguments,
    /// Output parameters as ref arguments. You don't have to assign output parameters,
    /// they will have a default value.
    /// </summary>
    private void RunScript(Brep x, int y, int U, int u, int z, List<double> Colors, int stX, int stY, ref object A)
    {
        //  if(sign){sign = false;
        double Umin = x.Faces[0].Domain(0).Min;
        double Umax = x.Faces[0].Domain(0).Max;
        double Vmin = x.Faces[0].Domain(1).Min;
        double Vmax = x.Faces[0].Domain(1).Max;
        double t = (Vmax - Vmin) / (Umax - Umin) * u;
        v = (int)t;
        t = (Vmax - Vmin) / (Umax - Umin) * U;
        V = (int)t;
        bitmap1 = new Bitmap(u, v);
        m_shapes = new List<Mesh>();
        m_materials = new List<Rhino.Display.DisplayMaterial>();
        mappixel = new pixel[U, V];
        for (int i = 0; i < U; i++)
        {
            for (int j = 0; j < V; j++)
            {
                double posX = (double)i / (double)U * (double)u;
                double posY = (double)j / (double)V * (double)v;
                mappixel[i, j] = new pixel(posX, posY);
            }
        }
        // }

        Graphics g = Graphics.FromImage(bitmap1);
        g.FillRectangle(new SolidBrush(Color.Black), 0, 0, u, v);
        double iso = 0;
        Random Rnd = new Random();
        for (int j = 0; j < V; j++)
        {
            for (int i = 0; i < U; i++)
            {
                if (j <= y) { mappixel[i, j].color = Color.White; }
                else if (Rnd.NextDouble() > iso) { mappixel[i, j].color = Color.White; }
            }
            if (j > y) iso += 0.02;
        }
        //////////////////////////****************************************
        int count = 0;

        for (int j = stY + z; j > stY; j--)
        {
            for (int i = stX; i < stX + Colors.Count / z; i++)
            {

                if (count > Colors.Count - 1) break;
                if (Colors[count] != 1)
                {
                    mappixel[i, j].color = Color.Gray;
                }
                else
                {
                    //mappixel[i, j].color = Color.Green;
                }
                count++;
            }
        }
        ///////////////////////////////
        for (int i = 0; i < U; i++)
        {
            for (int j = 0; j < V; j++)
            {
                mappixel[i, j].Draw(ref g, (int)(u / 2 / U));
            }
        }
        g.Dispose();
        str = @"C:\maps\temp1.jpg";
        bitmap1.Save(str);
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        Mesh[] meshes = Mesh.CreateFromBrep(x, MeshingParameters.Smooth);
        Mesh M = new Mesh();
        foreach (Mesh partialMesh in meshes)
        {
            M.Append(partialMesh);
        }
        m_shapes.Add(M);
        Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial();
        //  mat.SetTransparencyTexture(str, true);
        // mat.BackTransparency = 0;
        mat.Diffuse = Color.White;
        mat.SetBitmapTexture(str, true);

        m_materials.Clear();
        m_materials.Add(mat);
    }
コード例 #17
0
                       public override bool Equals(object obj)
                       {
                           pixel other = (pixel)obj;

                           return(other.a == a && other.b == b);
                       }
コード例 #18
0
 Horizontal = CalculateHorizontalPixelsPerMillimeter(pixel, physical, scale);
コード例 #19
0
ファイル: cam0.cs プロジェクト: s33hunt/VR-Hand-Controller
    IEnumerator UpdateStuff()
    {
        while (true)
        {
            yield return new WaitForSeconds(framerate);

            Color32[] camPixels = webcamTexture.GetPixels32();

            for (int i = 0; i < camPixels.Length; i++)
            {
                //if below threshold, make black
                if (camPixels[i].r < threshold && camPixels[i].g < threshold && camPixels[i].b < threshold)
                {
                    camPixels[i].g = 0;
                    camPixels[i].r = 0;
                    camPixels[i].b = 0;
                    //else add it to pixel list for processing
                }
                else {
                    int x = i % webcamTexture.width,
                        y = Mathf.FloorToInt((float)i / (float)webcamTexture.width);
                    pixel p = new pixel(x, y, i, camPixels[i]);
                    pixels.Add(p);
                    if (!pixelMapX.ContainsKey(x)) { pixelMapX.Add(x, new List<pixel>()); }
                    pixelMapX[x].Add(p);
                }
            }

            foreach (var p in pixels)
            {
                if (checkedPixelIndexes.Contains(p.index)) { continue; }
                CheckAdjacentRecursive(p, blobs.Count);
            }

            for (int i = 0; i < blobs.Count; i++)
            {
                foreach (pixel p in blobs[i])
                {
                    float c = (float)blobs.Count / (float)i;
                    camPixels[p.index] = new Color(0, c, 1 - c, 1);
                }
            }

            t.SetPixels32(camPixels);
            t.Apply();
            targetRend.material.mainTexture = t;

            Reset();
        }
    }
コード例 #20
0
        public static void Unwrap(double[,] image)//todo проверки выходов за диапазоны
        {
            int size0 = image.GetUpperBound(0);
            int size1 = image.GetUpperBound(1);

            pixel[,] pixels = new pixel[size0 + 1, size1 + 1];
            List <edge> edges = new List <edge>();

            for (int i = 1; i < size0; i++)
            {
                for (int j = 1; j < size1; j++)
                {
                    double H  = gamma(image[i, j - 1] - image[i, j]) - gamma(image[i, j] - image[i, j + 1]); //wrap(image[i,j-1]-image[i,j])-wrap(image[i,j]-image[i,j+1])
                    double V  = gamma(image[i - 1, j] - image[i, j]) - gamma(image[i, j] - image[i + 1, j]);
                    double D1 = gamma(image[i - 1, j - 1] - image[i, j]) - gamma(image[i, j] - image[i + 1, j + 1]);
                    double D2 = gamma(image[i - 1, j + 1] - image[i, j]) - gamma(image[i, j] - image[i + 1, j - 1]);
                    double R  = (H * H + V * V + D1 * D1 + D2 * D2);
                    pixels[i, j] = new pixel()
                    {
                        reliability = R, image = image, i = i, j = j
                    };
                }
            }

            for (int i = 0; i <= size0; i++)
            {
                int   j1    = 0;
                pixel temp1 = new pixel()
                {
                    reliability = 0, image = image, i = i, j = j1
                };
                pixels[i, j1] = temp1;
                int   j2    = size1;
                pixel temp2 = new pixel()
                {
                    reliability = 0, image = image, i = i, j = j2
                };
                pixels[i, j2] = temp2;
            }

            for (int j = 0; j <= size1; j++)
            {
                int   i1    = 0;
                pixel temp1 = new pixel()
                {
                    reliability = 0, image = image, i = i1, j = j
                };
                pixels[i1, j] = temp1;
                int   i2    = size0;
                pixel temp2 = new pixel()
                {
                    reliability = 0, image = image, i = i2, j = j
                };
                pixels[i2, j] = temp2;
            }

            {
                pixel  pixel1     = pixels[0, 0];
                pixel  pixel2     = pixels[0, 1];
                int    _increment = find_wrap(pixel1.image[pixel1.i, pixel1.j], pixel2.image[pixel2.i, pixel2.j]);
                double r          = pixel1.reliability + pixel2.reliability;
                //  if (r > 0)
                {
                    edge edge = new edge()
                    {
                        pixel1     = pixel1,
                        pixel2     = pixel2,
                        reaibility = r,
                        increment  = _increment
                    };
                    edges.Add(edge);
                }
            }


            {
                pixel  pixel1     = pixels[0, 0];
                pixel  pixel2     = pixels[1, 0];
                int    _increment = find_wrap(pixel1.image[pixel1.i, pixel1.j], pixel2.image[pixel2.i, pixel2.j]);
                double r          = pixel1.reliability + pixel2.reliability;
                //  if (r > 0)
                {
                    edge edge = new edge()
                    {
                        pixel1     = pixel1,
                        pixel2     = pixel2,
                        reaibility = r,
                        increment  = _increment
                    };
                    edges.Add(edge);
                }
            }

            for (int i = 1; i <= size0; i++)
            {
                for (int j = 1; j <= size1; j++)
                {
                    {
                        pixel  pixel1     = pixels[i - 1, j];
                        pixel  pixel2     = pixels[i, j];
                        int    _increment = find_wrap(pixel1.image[pixel1.i, pixel1.j], pixel2.image[pixel2.i, pixel2.j]);
                        double r          = pixel1.reliability + pixel2.reliability;
                        //  if (r > 0)
                        {
                            edge edge = new edge()
                            {
                                pixel1     = pixel1,
                                pixel2     = pixel2,
                                reaibility = r,
                                increment  = _increment
                            };
                            edges.Add(edge);
                        }
                    }

                    {
                        pixel  pixel1     = pixels[i, j - 1];
                        pixel  pixel2     = pixels[i, j];
                        int    _increment = find_wrap(pixel1.image[pixel1.i, pixel1.j], pixel2.image[pixel2.i, pixel2.j]);
                        double r          = pixel1.reliability + pixel2.reliability;
                        // if (r > 0)
                        {
                            edge edge = new edge()
                            {
                                pixel1     = pixel1,
                                pixel2     = pixel2,
                                reaibility = r,
                                increment  = _increment
                            };
                            edges.Add(edge);
                        }
                    }
                }
            }

            double val = ((double)edges.Count) / ((double)pixels.Length);

            edges.Sort(new edgeComparer());
            foreach (edge _edge in edges)
            {
                pixel PIXEL1 = _edge.pixel1;
                pixel PIXEL2 = _edge.pixel2;
                pixel group1;
                pixel group2;
                int   incremento;

                if (PIXEL2.head != PIXEL1.head)
                {
                    // PIXELM 2 is alone in its group
                    // merge this pixel with PIXELM 1 group and find the number of 2 pi to add
                    // to or subtract to unwrap it
                    if ((PIXEL2.next == null) && (PIXEL2.head == PIXEL2))
                    {
                        PIXEL1.head.last.next = PIXEL2;
                        PIXEL1.head.last      = PIXEL2;
                        (PIXEL1.head.number_of_pixels_in_group)++;
                        PIXEL2.head      = PIXEL1.head;
                        PIXEL2.increment = PIXEL1.increment - _edge.increment;
                    }

                    // PIXELM 1 is alone in its group
                    // merge this pixel with PIXELM 2 group and find the number of 2 pi to add
                    // to or subtract to unwrap it
                    else if ((PIXEL1.next == null) && (PIXEL1.head == PIXEL1))
                    {
                        PIXEL2.head.last.next = PIXEL1;
                        PIXEL2.head.last      = PIXEL1;
                        (PIXEL2.head.number_of_pixels_in_group)++;
                        PIXEL1.head      = PIXEL2.head;
                        PIXEL1.increment = PIXEL2.increment + _edge.increment;
                    }

                    // PIXELM 1 and PIXELM 2 both have groups
                    else
                    {
                        group1 = PIXEL1.head;
                        group2 = PIXEL2.head;
                        // if the no. of pixels in PIXELM 1 group is larger than the
                        // no. of pixels in PIXELM 2 group.  Merge PIXELM 2 group to
                        // PIXELM 1 group and find the number of wraps between PIXELM 2
                        // group and PIXELM 1 group to unwrap PIXELM 2 group with respect
                        // to PIXELM 1 group.  the no. of wraps will be added to PIXELM 2
                        // group in the future
                        if (group1.number_of_pixels_in_group >
                            group2.number_of_pixels_in_group)
                        {
                            // merge PIXELM 2 with PIXELM 1 group
                            group1.last.next = group2;
                            group1.last      = group2.last;
                            group1.number_of_pixels_in_group =
                                group1.number_of_pixels_in_group +
                                group2.number_of_pixels_in_group;
                            incremento =
                                PIXEL1.increment - _edge.increment - PIXEL2.increment;
                            // merge the other pixels in PIXELM 2 group to PIXELM 1 group
                            while (group2 != null)
                            {
                                group2.head       = group1;
                                group2.increment += incremento;
                                group2            = group2.next;
                            }
                        }

                        // if the no. of pixels in PIXELM 2 group is larger than the
                        // no. of pixels in PIXELM 1 group.  Merge PIXELM 1 group to
                        // PIXELM 2 group and find the number of wraps between PIXELM 2
                        // group and PIXELM 1 group to unwrap PIXELM 1 group with respect
                        // to PIXELM 2 group.  the no. of wraps will be added to PIXELM 1
                        // group in the future
                        else
                        {
                            // merge PIXELM 1 with PIXELM 2 group
                            group2.last.next = group1;
                            group2.last      = group1.last;
                            group2.number_of_pixels_in_group =
                                group2.number_of_pixels_in_group +
                                group1.number_of_pixels_in_group;
                            incremento =
                                PIXEL2.increment + _edge.increment - PIXEL1.increment;
                            // merge the other pixels in PIXELM 2 group to PIXELM 1 group
                            while (group1 != null)
                            {
                                group1.head       = group2;
                                group1.increment += incremento;
                                group1            = group1.next;
                            } // while
                        }     // else
                    }         // else
                }             // if
            }

            foreach (pixel pixel in pixels)
            {
                if (pixel.i == 0 && pixel.j == 0)
                {
                    int q = 0;
                }
                pixel.image[pixel.i, pixel.j] += TWOPI * ((double)pixel.increment);
            }
            //return result;
        }
コード例 #21
0
            static void Main(string[] args)
            {
                Console.WindowHeight = 32;
                Console.WindowWidth  = 64;
                int screenwidth  = Console.WindowWidth;
                int screenheight = Console.WindowHeight;

                Random randomnummer = new Random();

                int score    = 5;
                int gameover = 0;

                pixel px = new pixel();

                px.xposition = screenwidth / 2;
                px.yposition = screenheight / 2;

                px.shead = ConsoleColor.Red;

                string movement = "RIGHT";

                List <int> xpositionlist = new List <int>();
                List <int> ypositionlist = new List <int>();

                int berryx = randomnummer.Next(0, screenwidth);
                int berryy = randomnummer.Next(0, screenheight);

                DateTime time  = DateTime.Now;
                DateTime time2 = DateTime.Now;

                string buttonpressed = "no";

                // We only draw the border once. It doesn't change.
                DrawBorder(screenwidth, screenheight);

                while (true)
                {
                    ClearConsole(screenwidth, screenheight);
                    if (px.xposition == screenwidth - 1 || px.xposition == 0 || px.yposition == screenheight - 1 || px.yposition == 0)
                    {
                        gameover = 1;
                    }

                    Console.ForegroundColor = ConsoleColor.Green;
                    if (berryx == px.xposition && berryy == px.yposition)
                    {
                        score++;
                        berryx = randomnummer.Next(1, screenwidth - 2);
                        berryy = randomnummer.Next(1, screenheight - 2);
                    }
                    for (int i = 0; i < xpositionlist.Count(); i++)
                    {
                        Console.SetCursorPosition(xpositionlist[i], ypositionlist[i]);
                        Console.Write("¦");
                        if (xpositionlist[i] == px.xposition && ypositionlist[i] == px.yposition)
                        {
                            gameover = 1;
                        }
                    }
                    if (gameover == 1)
                    {
                        break;
                    }

                    Console.SetCursorPosition(px.xposition, px.yposition);
                    Console.ForegroundColor = px.shead;
                    Console.Write("■");
                    Console.SetCursorPosition(berryx, berryy);
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write("■");
                    Console.CursorVisible = false;
                    time          = DateTime.Now;
                    buttonpressed = "no";
                    while (true)
                    {
                        time2 = DateTime.Now;
                        if (time2.Subtract(time).TotalMilliseconds > 500)
                        {
                            break;
                        }
                        if (Console.KeyAvailable)
                        {
                            ConsoleKeyInfo toets = Console.ReadKey(true);
                            //Console.WriteLine(toets.Key.ToString());
                            if (toets.Key.Equals(ConsoleKey.UpArrow) && movement != "DOWN" && buttonpressed == "no")
                            {
                                movement      = "UP";
                                buttonpressed = "yes";
                            }
                            if (toets.Key.Equals(ConsoleKey.DownArrow) && movement != "UP" && buttonpressed == "no")
                            {
                                movement      = "DOWN";
                                buttonpressed = "yes";
                            }
                            if (toets.Key.Equals(ConsoleKey.LeftArrow) && movement != "RIGHT" && buttonpressed == "no")
                            {
                                movement      = "LEFT";
                                buttonpressed = "yes";
                            }
                            if (toets.Key.Equals(ConsoleKey.RightArrow) && movement != "LEFT" && buttonpressed == "no")
                            {
                                movement      = "RIGHT";
                                buttonpressed = "yes";
                            }
                        }
                    }
                    xpositionlist.Add(px.xposition);
                    ypositionlist.Add(px.yposition);
                    switch (movement)
                    {
                    case "UP":
                        px.yposition--;
                        break;

                    case "DOWN":
                        px.yposition++;
                        break;

                    case "LEFT":
                        px.xposition--;
                        break;

                    case "RIGHT":
                        px.xposition++;
                        break;
                    }
                    if (xpositionlist.Count() > score)
                    {
                        xpositionlist.RemoveAt(0);
                        ypositionlist.RemoveAt(0);
                    }
                }
                Console.SetCursorPosition(screenwidth / 5, screenheight / 2);
                Console.WriteLine("Game over, Score: " + score);
                Console.SetCursorPosition(screenwidth / 5, screenheight / 2 + 1);
            }
コード例 #22
0
 Vertical   = CalculateVerticalPixelsPerMillimeter(pixel, physical, scale);
コード例 #23
0
        public void Unwrap(double[,] image, out UwrReport score)//todo проверки выходов за диапазоны
        {
            score = new UwrReport();
            DateTime dt1 = DateTime.UtcNow;

            for (int i = 1; i < size0; i++)
            {
                for (int j = 1; j < size1; j++)
                {
                    double H  = gamma(image[i, j - 1] - image[i, j]) - gamma(image[i, j] - image[i, j + 1]);
                    double V  = gamma(image[i - 1, j] - image[i, j]) - gamma(image[i, j] - image[i + 1, j]);
                    double D1 = gamma(image[i - 1, j - 1] - image[i, j]) - gamma(image[i, j] - image[i + 1, j + 1]);
                    double D2 = gamma(image[i - 1, j + 1] - image[i, j]) - gamma(image[i, j] - image[i + 1, j - 1]);
                    pixels[i, j].reliability = (H * H + V * V + D1 * D1 + D2 * D2);
                }
            }

            for (int i = 1; i < size0; i++)//left and right borders
            {
                int j = 0;

                double H  = gamma(image[i, size1 - 1] - image[i, j]) - gamma(image[i, j] - image[i, j + 1]);
                double V  = gamma(image[i - 1, j] - image[i, j]) - gamma(image[i, j] - image[i + 1, j]);
                double D1 = gamma(image[i - 1, size1 - 1] - image[i, j]) - gamma(image[i, j] - image[i + 1, j + 1]);
                double D2 = gamma(image[i - 1, j + 1] - image[i, j]) - gamma(image[i, j] - image[i + 1, size1 - 1]);
                pixels[i, 0].reliability = (H * H + V * V + D1 * D1 + D2 * D2);

                j  = size1;
                H  = gamma(image[i, j - 1] - image[i, j]) - gamma(image[i, j] - image[i, 0]);
                V  = gamma(image[i - 1, j] - image[i, j]) - gamma(image[i, j] - image[i + 1, j]);
                D1 = gamma(image[i - 1, j - 1] - image[i, j]) - gamma(image[i, j] - image[i + 1, 0]);
                D2 = gamma(image[i - 1, 0] - image[i, j]) - gamma(image[i, j] - image[i + 1, j - 1]);
                pixels[i, size1].reliability = (H * H + V * V + D1 * D1 + D2 * D2);
            }

            for (int j = 1; j < size1; j++)
            {
                int    i  = 0;
                double H  = gamma(image[i, j - 1] - image[i, j]) - gamma(image[i, j] - image[i, j + 1]);
                double V  = gamma(image[size0, j] - image[i, j]) - gamma(image[i, j] - image[i + 1, j]);
                double D1 = gamma(image[size0, j - 1] - image[i, j]) - gamma(image[i, j] - image[i + 1, j + 1]);
                double D2 = gamma(image[size0, j + 1] - image[i, j]) - gamma(image[i, j] - image[i + 1, j - 1]);
                pixels[0, j].reliability = (H * H + V * V + D1 * D1 + D2 * D2);
                //pixels[i, j].value = image[i, j];

                i  = size0;
                H  = gamma(image[i, j - 1] - image[i, j]) - gamma(image[i, j] - image[i, j + 1]);
                V  = gamma(image[i - 1, j] - image[i, j]) - gamma(image[i, j] - image[0, j]);
                D1 = gamma(image[i - 1, j - 1] - image[i, j]) - gamma(image[i, j] - image[0, j + 1]);
                D2 = gamma(image[i - 1, j + 1] - image[i, j]) - gamma(image[i, j] - image[0, j - 1]);
                pixels[size0, j].reliability = (H * H + V * V + D1 * D1 + D2 * D2);
            }

            score.GammasCalc = DateTime.UtcNow.Subtract(dt1).TotalSeconds;
            dt1 = DateTime.UtcNow;
            for (int i = 0; i < _edges.Length; i++)
            {
                _edges[i].increment = find_wrap(image[_edges[i].pixel1.i, _edges[i].pixel1.j], image[_edges[i].pixel2.i, _edges[i].pixel2.j]);
                double val = Math.Round(_edges[i].pixel1.reliability + _edges[i].pixel2.reliability, 3);
                _edges[i].reaibility   = val;
                edges_reliabilities[i] = val;
            }
            score.EdgesCalc = DateTime.UtcNow.Subtract(dt1).TotalSeconds;

            dt1 = DateTime.UtcNow;
            //Array.Sort(_edges, new edgeComparer());
            Array.Sort(edges_reliabilities, _edges);
            //HibridSort2(edges_reliabilities, _edges, 2);


            score.Sorting = DateTime.UtcNow.Subtract(dt1).TotalSeconds;

            dt1 = DateTime.UtcNow;
            foreach (edge _edge in _edges)
            {
                pixel PIXEL1 = _edge.pixel1;
                pixel PIXEL2 = _edge.pixel2;
                pixel group1;
                pixel group2;
                int   incremento;

                if (PIXEL2.head != PIXEL1.head)
                {
                    // PIXELM 2 is alone in its group
                    // merge this pixel with PIXELM 1 group and find the number of 2 pi to add
                    // to or subtract to unwrap it
                    if ((PIXEL2.next == null) && (PIXEL2.head == PIXEL2))
                    {
                        PIXEL1.head.last.next = PIXEL2;
                        PIXEL1.head.last      = PIXEL2;
                        (PIXEL1.head.number_of_pixels_in_group)++;
                        PIXEL2.head      = PIXEL1.head;
                        PIXEL2.increment = PIXEL1.increment - _edge.increment;
                    }

                    // PIXELM 1 is alone in its group
                    // merge this pixel with PIXELM 2 group and find the number of 2 pi to add
                    // to or subtract to unwrap it
                    else if ((PIXEL1.next == null) && (PIXEL1.head == PIXEL1))
                    {
                        PIXEL2.head.last.next = PIXEL1;
                        PIXEL2.head.last      = PIXEL1;
                        (PIXEL2.head.number_of_pixels_in_group)++;
                        PIXEL1.head      = PIXEL2.head;
                        PIXEL1.increment = PIXEL2.increment + _edge.increment;
                    }

                    // PIXELM 1 and PIXELM 2 both have groups
                    else
                    {
                        group1 = PIXEL1.head;
                        group2 = PIXEL2.head;
                        // if the no. of pixels in PIXELM 1 group is larger than the
                        // no. of pixels in PIXELM 2 group.  Merge PIXELM 2 group to
                        // PIXELM 1 group and find the number of wraps between PIXELM 2
                        // group and PIXELM 1 group to unwrap PIXELM 2 group with respect
                        // to PIXELM 1 group.  the no. of wraps will be added to PIXELM 2
                        // group in the future
                        if (group1.number_of_pixels_in_group >
                            group2.number_of_pixels_in_group)
                        {
                            // merge PIXELM 2 with PIXELM 1 group
                            group1.last.next = group2;
                            group1.last      = group2.last;
                            group1.number_of_pixels_in_group =
                                group1.number_of_pixels_in_group +
                                group2.number_of_pixels_in_group;
                            incremento =
                                PIXEL1.increment - _edge.increment - PIXEL2.increment;
                            // merge the other pixels in PIXELM 2 group to PIXELM 1 group
                            while (group2 != null)
                            {
                                group2.head       = group1;
                                group2.increment += incremento;
                                group2            = group2.next;
                            }
                        }

                        // if the no. of pixels in PIXELM 2 group is larger than the
                        // no. of pixels in PIXELM 1 group.  Merge PIXELM 1 group to
                        // PIXELM 2 group and find the number of wraps between PIXELM 2
                        // group and PIXELM 1 group to unwrap PIXELM 1 group with respect
                        // to PIXELM 2 group.  the no. of wraps will be added to PIXELM 1
                        // group in the future
                        else
                        {
                            // merge PIXELM 1 with PIXELM 2 group
                            group2.last.next = group1;
                            group2.last      = group1.last;
                            group2.number_of_pixels_in_group =
                                group2.number_of_pixels_in_group +
                                group1.number_of_pixels_in_group;
                            incremento =
                                PIXEL2.increment + _edge.increment - PIXEL1.increment;
                            // merge the other pixels in PIXELM 2 group to PIXELM 1 group
                            while (group1 != null)
                            {
                                group1.head       = group2;
                                group1.increment += incremento;
                                group1            = group1.next;
                            } // while
                        }     // else
                    }         // else
                }             // if
            }

            score.PathFinding = DateTime.UtcNow.Subtract(dt1).TotalSeconds;
            dt1 = DateTime.UtcNow;
            foreach (pixel pixel in pixels)
            {
                image[pixel.i, pixel.j] += TWOPI * ((double)pixel.increment);
            }
            score.Unwrap = DateTime.UtcNow.Subtract(dt1).TotalSeconds;
            dt1          = DateTime.UtcNow;
            foreach (pixel pixel in pixels)
            {
                pixel.Refresh();
            }
            score.Refresh = DateTime.UtcNow.Subtract(dt1).TotalSeconds;
        }
コード例 #24
0
 Diagonal   = CalculateDiagonalPixelsPerMillimeter(pixel, physical, scale);
コード例 #25
0
        static void Main(string[] args)
        {
            Console.WindowHeight = 16;
            Console.WindowWidth  = 32;
            int    screenwidth  = Console.WindowWidth;
            int    screenheight = Console.WindowHeight;
            Random randomnummer = new Random();
            int    score        = 5;
            int    gameover     = 0;
            pixel  hoofd        = new pixel();

            hoofd.xpos        = screenwidth / 2;
            hoofd.ypos        = screenheight / 2;
            hoofd.schermkleur = ConsoleColor.Red;
            string     movement      = "RIGHT";
            List <int> xposlijf      = new List <int>();
            List <int> yposlijf      = new List <int>();
            int        berryx        = randomnummer.Next(0, screenwidth);
            int        berryy        = randomnummer.Next(0, screenheight);
            DateTime   tijd          = DateTime.Now;
            DateTime   tijd2         = DateTime.Now;
            string     buttonpressed = "no";

            while (true)
            {
                Console.Clear();
                if (hoofd.xpos == screenwidth - 1 || hoofd.xpos == 0 || hoofd.ypos == screenheight - 1 || hoofd.ypos == 0)
                {
                    gameover = 1;
                }
                for (int i = 0; i < screenwidth; i++)
                {
                    Console.SetCursorPosition(i, 0);
                    Console.Write("■");
                }
                for (int i = 0; i < screenwidth; i++)
                {
                    Console.SetCursorPosition(i, screenheight - 1);
                    Console.Write("■");
                }
                for (int i = 0; i < screenheight; i++)
                {
                    Console.SetCursorPosition(0, i);
                    Console.Write("■");
                }
                for (int i = 0; i < screenheight; i++)
                {
                    Console.SetCursorPosition(screenwidth - 1, i);
                    Console.Write("■");
                }
                Console.ForegroundColor = ConsoleColor.Green;
                if (berryx == hoofd.xpos && berryy == hoofd.ypos)
                {
                    score++;
                    berryx = randomnummer.Next(1, screenwidth - 2);
                    berryy = randomnummer.Next(1, screenheight - 2);
                }
                for (int i = 0; i < xposlijf.Count(); i++)
                {
                    Console.SetCursorPosition(xposlijf[i], yposlijf[i]);
                    Console.Write("■");
                    if (xposlijf[i] == hoofd.xpos && yposlijf[i] == hoofd.ypos)
                    {
                        gameover = 1;
                    }
                }
                if (gameover == 1)
                {
                    break;
                }
                Console.SetCursorPosition(hoofd.xpos, hoofd.ypos);
                Console.ForegroundColor = hoofd.schermkleur;
                Console.Write("■");
                Console.SetCursorPosition(berryx, berryy);
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.Write("■");
                tijd          = DateTime.Now;
                buttonpressed = "no";
                while (true)
                {
                    tijd2 = DateTime.Now;
                    if (tijd2.Subtract(tijd).TotalMilliseconds > 500)
                    {
                        break;
                    }
                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo toets = Console.ReadKey(true);
                        //Console.WriteLine(toets.Key.ToString());
                        if (toets.Key.Equals(ConsoleKey.UpArrow) && movement != "DOWN" && buttonpressed == "no")
                        {
                            movement      = "UP";
                            buttonpressed = "yes";
                        }
                        if (toets.Key.Equals(ConsoleKey.DownArrow) && movement != "UP" && buttonpressed == "no")
                        {
                            movement      = "DOWN";
                            buttonpressed = "yes";
                        }
                        if (toets.Key.Equals(ConsoleKey.LeftArrow) && movement != "RIGHT" && buttonpressed == "no")
                        {
                            movement      = "LEFT";
                            buttonpressed = "yes";
                        }
                        if (toets.Key.Equals(ConsoleKey.RightArrow) && movement != "LEFT" && buttonpressed == "no")
                        {
                            movement      = "RIGHT";
                            buttonpressed = "yes";
                        }
                    }
                }
                xposlijf.Add(hoofd.xpos);
                yposlijf.Add(hoofd.ypos);
                switch (movement)
                {
                case "UP":
                    hoofd.ypos--;
                    break;

                case "DOWN":
                    hoofd.ypos++;
                    break;

                case "LEFT":
                    hoofd.xpos--;
                    break;

                case "RIGHT":
                    hoofd.xpos++;
                    break;
                }
                if (xposlijf.Count() > score)
                {
                    xposlijf.RemoveAt(0);
                    yposlijf.RemoveAt(0);
                }
            }
            Console.SetCursorPosition(screenwidth / 5, screenheight / 2);
            Console.WriteLine("Game over, Score: " + score);
            Console.SetCursorPosition(screenwidth / 5, screenheight / 2 + 1);
        }
コード例 #26
0
        static void Main(string[] args)
        {
            int screenwidth  = Console.WindowWidth - 10;
            int screenheight = Console.WindowHeight - 10;


            //Console.WriteLine("Welcome To Sanke Game");
            //screenwidth = returnWidth(screenwidth);
            //screenheight = returnHeight(screenheight);


            //use Random Class to generate Random number
            Random randomNumber = new Random();

            int score    = 3;
            int gameover = 0;

            pixel snakeHead = new pixel();

            snakeHead.xpos = screenwidth / 2;
            snakeHead.ypos = screenheight / 2;

            // default movement is RIGHT
            string movement = "RIGHT";

            // speed of snake
            int speed = 100;

            // use list to save x and y position of snake
            List <int> snakeXposition = new List <int>();
            List <int> snakeYposition = new List <int>();

            //x position and y position of apple(berry)
            int appleX = randomNumber.Next(0 + 5, screenwidth - 5);
            int appleY = randomNumber.Next(0 + 5, screenheight - 5);

            // use Datetime to change speed of snake
            DateTime timeBeforeWhile = DateTime.Now;
            DateTime timeInWhile     = DateTime.Now;

            string buttonpressed = "no";

            Boolean pause = false;

            //print the border

            //Console.BackgroundColor = ConsoleColor.White;

            Console.Clear();
            Console.ForegroundColor = ConsoleColor.White;
            printBorder(screenwidth, screenheight);
            while (true)
            {
                //clear the screen
                //Console.Clear();

                //check that snake hit the border or not
                if (snakeHead.xpos == screenwidth - 1 ||
                    snakeHead.xpos == 0 ||
                    snakeHead.ypos == screenheight - 1 ||
                    snakeHead.ypos == 0)
                {
                    gameover = 1;
                }



                //change the color of snake
                Console.ForegroundColor = ConsoleColor.Green;

                //check snake eat the apple
                if (appleX == snakeHead.xpos && appleY == snakeHead.ypos)
                {
                    score++;

                    do
                    {
                        appleX = randomNumber.Next(0 + 5, screenwidth - 5);
                        appleY = randomNumber.Next(0 + 5, screenheight - 5);
                    } while (IsAppleInSnake(snakeXposition, snakeYposition, appleX, appleY));
                }



                //print snake
                for (int i = 0; i < snakeXposition.Count(); i++)
                {
                    Console.SetCursorPosition(snakeXposition[i], snakeYposition[i]);
                    Console.Write("0");
                    if (snakeXposition[i] == snakeHead.xpos && snakeYposition[i] == snakeHead.ypos)
                    {
                        gameover = 1;
                    }
                }


                // print sanke head
                Console.SetCursorPosition(snakeHead.xpos, snakeHead.ypos);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("@");


                // if gameover==1 go outside of the while loop
                if (gameover == 1)
                {
                    break;
                }


                // print the apple
                Console.SetCursorPosition(appleX, appleY);
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.Write("@");


                timeBeforeWhile = DateTime.Now;
                buttonpressed   = "no";

                while (true && buttonpressed == "no")
                {
                    // change speed of snake
                    //printStatistics(snakeHead.xpos, snakeHead.ypos);
                    timeInWhile = DateTime.Now;

                    if (timeInWhile.Subtract(timeBeforeWhile).TotalMilliseconds > speed)
                    {
                        break;
                    }

                    //check keyboard press
                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo inputKey = Console.ReadKey(true);

                        //Console.WriteLine(inputKey.Key.ToString());
                        if (inputKey.Key.Equals(ConsoleKey.Escape) && buttonpressed == "no")
                        {
                            gameover      = 1;
                            buttonpressed = "yes";
                        }
                        if (inputKey.Key.Equals(ConsoleKey.Spacebar) && buttonpressed == "no")
                        {
                            pause         = !pause;
                            buttonpressed = "yes";
                        }
                        if ((inputKey.Key.Equals(ConsoleKey.UpArrow) || inputKey.Key.Equals(ConsoleKey.W)) && movement != "DOWN" && buttonpressed == "no")
                        {
                            movement      = "UP";
                            buttonpressed = "yes";
                        }
                        if ((inputKey.Key.Equals(ConsoleKey.DownArrow) || inputKey.Key.Equals(ConsoleKey.S)) && movement != "UP" && buttonpressed == "no")
                        {
                            movement      = "DOWN";
                            buttonpressed = "yes";
                        }
                        if ((inputKey.Key.Equals(ConsoleKey.LeftArrow) || inputKey.Key.Equals(ConsoleKey.A)) && movement != "RIGHT" && buttonpressed == "no")
                        {
                            movement      = "LEFT";
                            buttonpressed = "yes";
                        }
                        if ((inputKey.Key.Equals(ConsoleKey.RightArrow) || inputKey.Key.Equals(ConsoleKey.D)) && movement != "LEFT" && buttonpressed == "no")
                        {
                            movement      = "RIGHT";
                            buttonpressed = "yes";
                        }
                    }
                }


                if (!pause)
                {
                    //add the new direction to move the snake
                    snakeXposition.Add(snakeHead.xpos);
                    snakeYposition.Add(snakeHead.ypos);

                    switch (movement)
                    {
                    case "UP":
                        snakeHead.ypos--;
                        break;

                    case "DOWN":
                        snakeHead.ypos++;
                        break;

                    case "LEFT":
                        snakeHead.xpos--;
                        break;

                    case "RIGHT":
                        snakeHead.xpos++;
                        break;
                    }


                    if (snakeXposition.Count() > score)
                    {
                        //printStatistics(snakeXposition.First<int>() ,snakeYposition.First<int>());
                        int xlast = snakeXposition.First <int>();
                        int ylast = snakeYposition.First <int>();

                        printSnakeSize(snakeXposition.Count());

                        Console.SetCursorPosition(xlast, ylast);
                        Console.Write(" ");

                        snakeXposition.RemoveAt(0);
                        snakeYposition.RemoveAt(0);
                    }

                    printPause(false);
                }
                else
                {
                    printPause(true);
                }
            }

            Console.SetCursorPosition(25, 27);
            score++;
            Console.Write("Game over, Score: " + score);
            //Console.SetCursorPosition(25, 27);


            Console.ReadLine();

            Console.Clear();
            Console.ForegroundColor = ConsoleColor.White;
        }