コード例 #1
0
 public GeoDisplayIco(int width, int height, GeoGrid grid)
 {
     this.grid   = grid;
     this.width  = width;
     this.height = height;
     this.ASPECT = width / height;
 }
コード例 #2
0
        public static GeoGrid seaLevel(GeoGrid input, Project proj)
        {
            float   sea       = proj.SeaLevel;
            int     freq      = input.getFrequency();
            GeoGrid landForms = new GeoGrid(proj.Frequency);

            for (int par = 0; par < GeoGrid.NUMPARA; par++)
            {
                for (int r = 0; r < freq - 1; r++)
                {
                    for (int c = 0; c < 2 * freq - 1; c++)
                    {
                        if (input.getTile(par, r, c).Value <= sea)
                        {
                            landForms.getTile(par, r, c).Value = 0f;
                        }
                        else
                        {
                            landForms.getTile(par, r, c).Value = 1f;
                        }
                        if (r == 0 && c == 0)
                        {
                            landForms.getTile(par, r, c).Value = 1f;
                        }
                        else if (r == 0 && c == freq - 1)
                        {
                            landForms.getTile(par, r, c).Value = 1f;
                        }
                        else if (r == 0 && c == 2 * freq - 2)
                        {
                            landForms.getTile(par, r, c).Value = 1f;
                        }
                        else if (r == freq - 1 && c == 0)
                        {
                            landForms.getTile(par, r, c).Value = 1f;
                        }
                        else if (r == freq - 1 && c == freq - 1)
                        {
                            landForms.getTile(par, r, c).Value = 1f;
                        }
                        else if (r == freq - 1 && c == 2 * freq - 2)
                        {
                            landForms.getTile(par, r, c).Value = 1f;
                        }
                    }
                }
            }
            return(landForms);
        }
コード例 #3
0
        public GeoGrid deepCopy(int numsubs)
        {
            GeoGrid dup = new GeoGrid(numsubs);

            for (int i = 0; i < NUMPARA; i++)
            {
                for (int j = 0; j < frequency - 1; j++)
                {
                    for (int k = 0; k < 2 * frequency - 1; k++)
                    {
                        dup.getTile(i, j, k).Value = grid[i][j][k].Value;
                        dup.getTile(i, j, k).Rank  = grid[i][j][k].Rank;
                    }
                }
            }
            return(dup);
        }
コード例 #4
0
        public void RectToGeo(RectGrid input, GeoGrid g)
        {
            LoadGrid(g);
            int   nearestX;
            int   nearestY;
            float curAverage;

            for (int i = 0; i < hexList.Length; i++)
            {
                curAverage = 0;
                for (int j = 0; j < 6; j++)
                {
                    nearestX    = (int)(((input.Width - 1) / 2) * (hexList[i].equiVec[j].X + 1));
                    nearestY    = (int)(((input.Height - 1) / 2) * (hexList[i].equiVec[j].Y + 1));
                    curAverage += input.getTile(nearestY, nearestX).Value;
                }
                hexList[i].tile.Value = curAverage / 6.0f;
            }
        }
コード例 #5
0
        public void LoadGrid(GeoGrid g)
        {
            int edgeLen = (int)Math.Pow(2, numSubs);
            //Number of hexagons on an even face
            int even = Triangular(edgeLen) - 1;
            //Number of hexagons on an odd face
            int odd    = Triangular(edgeLen - 1);
            int hexDex = 0;

            //This loop assigns the display hexagons to an index in the data representation
            //While there's five parallelograms, I end up doing the same thing twice in each one, so I did some simple integer division trickery.
            //Hopefully it doesn't f**k me in the butt down the road.

            //I'm down the road and pretty sure I'm being f****d in the butt

            System.Console.WriteLine("HexLen: " + hexList.Length);
            System.Console.WriteLine("Even: " + even);
            System.Console.WriteLine("Odd: " + odd);
            for (int par = 0; par < 10; par++)
            {
                int start = (par % 2) * edgeLen;
                for (int col = 1; col < edgeLen; col++)
                {
                    for (int row = 0; row <= edgeLen - col; row++)
                    {
                        hexList[hexDex++].tile = g.getTile(par / 2, row, col + start);
                        //hexDex++;
                    }
                }
                for (int row = edgeLen - 1; row > 0; row--)
                {
                    int iter = 0;
                    for (int col = edgeLen; col > row; col--)
                    {
                        hexList[hexDex++].tile = g.getTile(par / 2, row + iter, col + start);
                        iter++;
                    }
                }
            }
        }
コード例 #6
0
        public void GeoToRect(RectGrid input, GeoGrid g, int ig)
        {
            LoadGrid(g);
            int nearestX;
            int nearestY;

            for (int i = 0; i < hexList.Length; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    nearestX = (int)(((input.Width - 1) / 2) * (hexList[i].equiVec[j].X + 1));
                    nearestY = (int)(((input.Height - 1) / 2) * (hexList[i].equiVec[j].Y + 1));
                    input.getTile(nearestY, nearestX).Value = hexList[i].tile.Value;
                    input.getTile(nearestY, nearestX).Rank  = input.getTile(nearestY, nearestX).Rank + 1;
                }
            }
            for (int row = 0; row < input.Height; row++)
            {
                for (int col = 0; col < input.Width; col++)
                {
                    input.getTile(row, col).Value = input.getTile(row, col).Value / input.getTile(row, col).Rank;
                }
            }
        }
コード例 #7
0
ファイル: MainWindow.cs プロジェクト: Yinigma/cliMate
        public void renderGrid()
        {
            if (selectedNode == null)
            {
                return;
            }
            Graphics   g = testPanel.CreateGraphics();
            SolidBrush b = new SolidBrush(Color.Red);

            GridDisplayEquiRect.Hexagon[] hexList = currentProject.EquiDisp.dispHex;
            GeoGrid geo = new GeoGrid(currentProject.Frequency);

            PointF[] curHex = new PointF[6];
            float    offX   = testPanel.Width / 2.0f;
            float    offY   = testPanel.Height / 2.0f;
            int      brightness;

            RectGrid moisture = Biomes.moisture(selectedNode.getOutputGrid(), currentProject, 6);

            currentProject.EquiDisp.RectToGeo(moisture, geo);

            //currentProject.EquiDisp.RectToGeo(selectedNode.getOutputGrid(), geo);


            //geo = Biomes.seaLevel(geo, currentProject);
            //currentProject.EquiDisp.LoadGrid(geo);

            /*Tile[] mates = geo.neighbors(0,geo.getFrequency()-1,1);
             * for(int i=0; i<mates.Length; i++)
             * {
             *  mates[i].Value = 0.1f * i;
             * }*/

            for (int i = 0; i < hexList.Length; i++)
            {
                brightness = (int)(hexList[i].tile.Value * 255);
                b.Color    = Color.FromArgb(brightness, brightness, brightness);
                if (!hexList[i].isEdge)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        curHex[j] = new PointF(offX + hexList[i].equiVec[j].X * (testPanel.Width / 2.0f), offY + hexList[i].equiVec[j].Y * (testPanel.Height / 2.0f));
                    }
                    g.FillPolygon(b, curHex);
                }
                else
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (hexList[i].equiVec[j].X <= 0)
                        {
                            curHex[j] = new PointF(testPanel.Width + offX + hexList[i].equiVec[j].X * (testPanel.Width / 2.0f), offY + hexList[i].equiVec[j].Y * (testPanel.Height / 2.0f));
                        }
                        else
                        {
                            curHex[j] = new PointF(offX + hexList[i].equiVec[j].X * (testPanel.Width / 2.0f), offY + hexList[i].equiVec[j].Y * (testPanel.Height / 2.0f));
                        }
                    }
                    g.FillPolygon(b, curHex);
                    for (int j = 0; j < 6; j++)
                    {
                        if (hexList[i].equiVec[j].X >= 0)
                        {
                            curHex[j] = new PointF(-testPanel.Width + offX + hexList[i].equiVec[j].X * (testPanel.Width / 2.0f), offY + hexList[i].equiVec[j].Y * (testPanel.Height / 2.0f));
                        }
                        else
                        {
                            curHex[j] = new PointF(offX + hexList[i].equiVec[j].X * (testPanel.Width / 2.0f), offY + hexList[i].equiVec[j].Y * (testPanel.Height / 2.0f));
                        }
                    }
                    g.FillPolygon(b, curHex);
                }
            }
            counterDB++;
            testPanel.Update();
        }
コード例 #8
0
        //cutoff determines the amount of steps before moisture reaches its lowest point
        public static RectGrid moisture(RectGrid input, Project proj, int cutoff)
        {
            GeoGrid             geo       = new GeoGrid(proj.Frequency);
            GeoGrid             output    = new GeoGrid(proj.Frequency);
            RectGrid            coastDist = new RectGrid(input.Height, input.Width);
            GridDisplayEquiRect temp      = new GridDisplayEquiRect(proj.Frequency);

            temp.RectToGeo(input, geo);
            GeoGrid landForms = seaLevel(geo, proj);
            int     freq      = landForms.getFrequency();
            int     rank      = 1;

            Tile[] mates;
            bool   clear = false;

            while (!clear)
            {
                clear = true;
                GeoGrid next = landForms.deepCopy(proj.Frequency);
                //Wheeeeeeee~
                for (int par = 0; par < GeoGrid.NUMPARA; par++)
                {
                    for (int r = 0; r < freq - 1; r++)
                    {
                        for (int c = 0; c < 2 * freq - 1; c++)
                        {
                            //If it's a land tile that hasn't been visited...
                            if (landForms.getTile(par, r, c).Value > .5f)
                            {
                                mates = landForms.neighbors(r, c, par);
                                for (int m = 0; m < mates.Length; m++)
                                {
                                    //if it's a sea tile
                                    if (mates[m].Value < .5f)
                                    {
                                        //Remove from next step
                                        next.getTile(par, r, c).Value = 0f;
                                        //set distance away from coast
                                        output.getTile(par, r, c).Rank = Math.Min(rank, cutoff);
                                        clear = false;
                                    }
                                }
                            }
                        }
                    }
                }
                landForms = next;
                rank++;
            }
            //Determine moisture weight by dividing by cutoff (yes, I coulda put this in the loop above)
            for (int par = 0; par < GeoGrid.NUMPARA; par++)
            {
                for (int r = 0; r < freq - 1; r++)
                {
                    for (int c = 0; c < 2 * freq - 1; c++)
                    {
                        output.getTile(par, r, c).Value = 1 - ((float)output.getTile(par, r, c).Rank / cutoff);
                        output.getTile(par, r, c).Rank  = 0;
                    }
                }
            }
            temp.LoadGrid(output);
            temp.GeoToRect(coastDist);
            return(coastDist);
        }