示例#1
0
文件: Canvas.cs 项目: Yinigma/cliMate
        public override void Apply(RectGrid targetGrid, Bitmap targetBitmap, int x, int y, double size, double speed, double deltaTime)
        {
            double radius = size;

            //Make a bounding box around the circle
            int startX = (int)((double)x - size);
            int endX   = (int)((double)x + size);

            int startY = (int)((double)y - size);
            int endY   = (int)((double)y + size);

            //Make sure the corners are in bounds
            startX = Utils.CapBounds(startX, 0, targetGrid.Width);
            endX   = Utils.CapBounds(endX, 0, targetGrid.Width);

            startY = Utils.CapBounds(startY, 0, targetGrid.Height);
            endY   = Utils.CapBounds(endY, 0, targetGrid.Height);

            //Loop through the bounding box, skipping any pixels that fall outside the circle

            int centerX = x;
            int centerY = y;    //Save x and y, since we're using those variable names in the loop

            for (x = startX; x < endX; x++)
            {
                for (y = startY; y < endY; y++)
                {
                    //Skip this pixel if it's not within the radius
                    double squaredDist = (x - centerX) * (x - centerX) + (y - centerY) * (y - centerY);
                    if (squaredDist > radius * radius)
                    {
                        continue;
                    }

                    //Make it so the speed decreases as it gets further from the center
                    double distPercent = squaredDist / (radius * radius);
                    float  scaledSpeed = (float)Utils.Lerp(speed, 0, distPercent);

                    //Change the height at this position
                    float val = targetGrid.getTile(y, x).Value;
                    val += scaledSpeed * (float)deltaTime;

                    //Ensure the value stays within the limits
                    if (Math.Abs(val) > RectGrid.MAX)
                    {
                        val = Math.Sign(val) * RectGrid.MAX;
                    }

                    //Apply the height change
                    targetGrid.getTile(y, x).Value = val;
                    targetBitmap.SetPixel(x, y, targetGrid.getTile(y, x).getColor());
                }
            } //End of double for loop
        }     //End of function
示例#2
0
文件: Node.cs 项目: Yinigma/cliMate
        public virtual Bitmap ToBitmap()
        {
            Bitmap bmp = new Bitmap(map.Width, map.Height);

            for (int col = 0; col < map.Width; col++)
            {
                for (int row = 0; row < map.Height; row++)
                {
                    bmp.SetPixel(col, row, outGrid.getTile(row, col).getColor());
                }
            }
            return(bmp);
        }
示例#3
0
        //The data loaded into the rectGrid is whatever is already loaded in
        public void GeoToRect(RectGrid input)
        {
            Bitmap     img = new Bitmap(input.Width, input.Height);
            Graphics   g   = Graphics.FromImage(img);
            SolidBrush b   = new SolidBrush(Color.Red);

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

            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 * (img.Width / 2.0f), offY + hexList[i].equiVec[j].Y * (img.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(img.Width + offX + hexList[i].equiVec[j].X * (img.Width / 2.0f), offY + hexList[i].equiVec[j].Y * (img.Height / 2.0f));
                        }
                        else
                        {
                            curHex[j] = new PointF(offX + hexList[i].equiVec[j].X * (img.Width / 2.0f), offY + hexList[i].equiVec[j].Y * (img.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(-img.Width + offX + hexList[i].equiVec[j].X * (img.Width / 2.0f), offY + hexList[i].equiVec[j].Y * (img.Height / 2.0f));
                        }
                        else
                        {
                            curHex[j] = new PointF(offX + hexList[i].equiVec[j].X * (img.Width / 2.0f), offY + hexList[i].equiVec[j].Y * (img.Height / 2.0f));
                        }
                    }
                    g.FillPolygon(b, curHex);
                }
            }
            for (int row = 0; row < input.Height; row++)
            {
                for (int col = 0; col < input.Width; col++)
                {
                    input.getTile(row, col).Value = (float)(img.GetPixel(col, row).R) / 255;
                }
            }
        }
示例#4
0
        public static RectGrid seaLevel(RectGrid input, Project proj)
        {
            float    sea       = proj.SeaLevel;
            RectGrid landForms = new RectGrid(input.Height, input.Width);

            for (int r = 0; r < input.Height; r++)
            {
                for (int c = 0; c < input.Width; c++)
                {
                    if (input.getTile(r, c).Value <= sea)
                    {
                        landForms.getTile(r, c).Value = 0f;
                    }
                    else
                    {
                        landForms.getTile(r, c).Value = 1f;
                    }
                }
            }
            return(landForms);
        }
示例#5
0
文件: Canvas.cs 项目: Yinigma/cliMate
        public override void Apply(RectGrid targetGrid, Bitmap targetBitmap, int x, int y, double size, double speed, double deltaTime)
        {
            //Make a square around the coordinates
            int startX = (int)((double)x - size / 2);
            int endX   = (int)((double)x + size / 2);

            int startY = (int)((double)y - size / 2);
            int endY   = (int)((double)y + size / 2);

            //Make sure the corners of the square are in bounds
            startX = Utils.CapBounds(startX, 0, targetGrid.Width);
            endX   = Utils.CapBounds(endX, 0, targetGrid.Width);

            startY = Utils.CapBounds(startY, 0, targetGrid.Height);
            endY   = Utils.CapBounds(endY, 0, targetGrid.Height);

            //Iterate through the square, applying the logic to it.
            for (x = startX; x < endX; x++)
            {
                for (y = startY; y < endY; y++)
                {
                    //Change the height at this position
                    float val = targetGrid.getTile(y, x).Value;
                    val += (float)(speed * deltaTime);

                    //Ensure the value stays within the limits
                    if (Math.Abs(val) > RectGrid.MAX)
                    {
                        val = Math.Sign(val) * RectGrid.MAX;
                    }

                    //Apply the height change
                    targetGrid.getTile(y, x).Value = val;
                    targetBitmap.SetPixel(x, y, targetGrid.getTile(y, x).getColor());
                }
            }
        }
示例#6
0
        public static Bitmap renderBiomes(RectGrid rg)
        {
            Bitmap img = new Bitmap(rg.Width, rg.Height);
            int    toggle;

            for (int row = 0; row < rg.Height; row++)
            {
                for (int col = 0; col < rg.Width; col++)
                {
                    toggle = rg.getTile(row, col).Rank;
                    img.SetPixel(col, row, colors[toggle]);
                }
            }
            return(img);
        }
示例#7
0
        public static RectGrid BiomeMap(RectGrid input, Project proj, int cutoff, float equator, int[] newRank)
        {
            RectGrid moistureGrid = Biomes.moisture(input, proj, cutoff);
            RectGrid tempGrid     = Biomes.Temperature(input, equator);
            RectGrid biomeGrid    = new RectGrid(input.Height, input.Width);

            int[,] converted = new int[6, 6];

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    converted[i, j] = newRank[biomeTable[i, j]];
                }
            }

            int tempDex;
            int moistDex;

            for (int row = 0; row < input.Height; row++)
            {
                for (int col = 0; col < input.Width; col++)
                {
                    if (input.getTile(row, col).Value < proj.SeaLevel)
                    {
                        biomeGrid.getTile(row, col).Rank = 9;
                        continue;
                    }
                    moistDex = (int)(moistureGrid.getTile(row, col).Value * 5);
                    tempDex  = (int)(tempGrid.getTile(row, col).Value * 5);
                    biomeGrid.getTile(row, col).Rank = converted[moistDex, tempDex];
                }
            }

            return(biomeGrid);
        }
示例#8
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;
            }
        }
示例#9
0
        public static RectGrid Temperature(RectGrid input, float equator)
        {
            Math.Abs(equator);
            equator -= (int)equator;
            int      gridEquator = (int)(input.Height * equator);
            float    dist;
            float    latTemp;
            float    altTemp;
            RectGrid temp = new RectGrid(input.Height, input.Width);

            for (int row = 0; row < input.Height; row++)
            {
                for (int col = 0; col < input.Width; col++)
                {
                    dist    = (float)(gridEquator - row) / (input.Height / 2);
                    latTemp = 1 - dist * dist;
                    altTemp = MAXALTIMPACT * input.getTile(row, col).Value;
                    temp.getTile(row, col).Value = Math.Max(0, latTemp - altTemp);
                }
            }
            return(temp);
        }
示例#10
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;
                }
            }
        }