コード例 #1
0
ファイル: MainWindow.cs プロジェクト: Yinigma/cliMate
        private void UpdateMapDisplay()
        {
            //Updates the map display in the map tab

            selectedNode = nodePanel.Selected;
            if (selectedNode != null)
            {
                if (DisplayOptionBox.SelectedIndex == 0)
                {
                    mapDisplay.Image = selectedNode.getOutputGrid().gridToBitmapOcean(ColorGrad.LandGradient, ColorGrad.OceanGradient, currentProject.SeaLevel);
                }
                else if (DisplayOptionBox.SelectedIndex == 1)
                {
                    if (SeasonSwitcher.SelectedIndex == 1)
                    {
                        mapDisplay.Image = Biomes.Temperature(selectedNode.getOutputGrid(), 0.4f).gridToBitmap(ColorGrad.tempGradient);
                    }
                    else if (SeasonSwitcher.SelectedIndex == 2)
                    {
                        mapDisplay.Image = Biomes.Temperature(selectedNode.getOutputGrid(), 0.6f).gridToBitmap(ColorGrad.tempGradient);
                    }
                    else
                    {
                        mapDisplay.Image = Biomes.Temperature(selectedNode.getOutputGrid()).gridToBitmap(ColorGrad.tempGradient);
                    }
                }
                else if (DisplayOptionBox.SelectedIndex == 2)
                {
                    RectGrid moisture = Biomes.moisture(selectedNode.getOutputGrid(), currentProject, 3 * currentProject.Frequency);
                    mapDisplay.Image = moisture.gridToBitmap(ColorGrad.MoistureGradient);
                }
                else if (DisplayOptionBox.SelectedIndex == 3)
                {
                    replacements[0] = tundraBox.SelectedIndex;
                    replacements[1] = grassBox.SelectedIndex;
                    replacements[2] = woodBox.SelectedIndex;
                    replacements[3] = borBox.SelectedIndex;
                    replacements[4] = seasonBox.SelectedIndex;
                    replacements[5] = temperBox.SelectedIndex;
                    replacements[6] = tropBox.SelectedIndex;
                    replacements[7] = savBox.SelectedIndex;
                    replacements[8] = desertBox.SelectedIndex;
                    if (SeasonSwitcher.SelectedIndex == 1)
                    {
                        RectGrid biome = Biomes.BiomeMap(selectedNode.getOutputGrid(), currentProject, 3 * currentProject.Frequency, .4f, replacements);
                        mapDisplay.Image = Biomes.renderBiomes(biome);
                    }
                    else if (SeasonSwitcher.SelectedIndex == 2)
                    {
                        RectGrid biome = Biomes.BiomeMap(selectedNode.getOutputGrid(), currentProject, 3 * currentProject.Frequency, .6f, replacements);
                        mapDisplay.Image = Biomes.renderBiomes(biome);
                    }
                    else
                    {
                        RectGrid biome = Biomes.BiomeMap(selectedNode.getOutputGrid(), currentProject, 3 * currentProject.Frequency, .5f, replacements);
                        mapDisplay.Image = Biomes.renderBiomes(biome);
                    }
                }
            }
        }
コード例 #2
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;
                }
            }
        }
コード例 #3
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
コード例 #4
0
ファイル: Node.cs プロジェクト: Yinigma/cliMate
        public Node(NodeMap map)
        {
            int needed = getNeeded();
            int opt    = getOptional();

            enableMask = false;
            //This is here to make sure that setInput can always be called
            children = new Node[needed + opt];
            this.map = map;
            outGrid  = new RectGrid(map.Height, map.Width);
            setDefault();
        }
コード例 #5
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);
        }
コード例 #6
0
ファイル: Canvas.cs プロジェクト: Yinigma/cliMate
        //Events
        private void Canvas_Load(object sender, EventArgs e)
        {
            if (!node.editedOnce)   //If this is the first time editing, create a new image.
            {
                WidthHeightDialog dialog = new WidthHeightDialog();
                dialog.ShowDialog();

                image = new RectGrid(dialog.height, dialog.width);
            }
            else                    //If we've already made one, copy the existing one so we can edit it.
            {
                image = new RectGrid(node.Grid.Height, node.Grid.Width);

                for (int r = 0; r < node.Grid.Height; r++)
                {
                    for (int c = 0; c < node.Grid.Width; c++)
                    {
                        float val = node.Grid.getTile(r, c).Value;
                        image.setTile(r, c, val);
                    }
                }
            }

            //Put the image in the picbox
            tempPicBox.Image = image.gridToBitmap();

            //Enable the timer
            tickTimer.Enabled = true;

            //Set default brush params
            brushSpeedBox.Minimum = (decimal)MIN_BRUSH_SPEED;
            brushSpeedBox.Maximum = (decimal)MAX_BRUSH_SPEED;

            brushSize  = DEFAULT_SIZE;
            brushSpeed = DEFAULT_SPEED;

            //Add all brush types
            AddBrushType("Circle", new CircleBrush()).Checked = true;

            AddBrushType("Square", new SquareBrush());

            //Add all tools
            AddTool("Paint Brush", PaintBrushTool).Checked = true;
            AddTool("Eraser", EraserTool);
        }
コード例 #7
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;
            }
        }
コード例 #8
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);
        }
コード例 #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
ファイル: 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());
                }
            }
        }
コード例 #11
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);
        }
コード例 #12
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;
                }
            }
        }
コード例 #13
0
ファイル: Canvas.cs プロジェクト: Yinigma/cliMate
 public abstract void Apply(RectGrid targetGrid, Bitmap targetBitmap, int x, int y, double size, double speed, double deltaTime);
コード例 #14
0
ファイル: Canvas.cs プロジェクト: Yinigma/cliMate
 private void button1_Click(object sender, EventArgs e)
 {
     //Reset the image
     image            = new ProjectCeres.RectGrid(image.Width, image.Height);
     tempPicBox.Image = image.gridToBitmap();
 }
コード例 #15
0
 public static RectGrid Temperature(RectGrid input)
 {
     return(Temperature(input, 0.5f));
 }
コード例 #16
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);
        }
コード例 #17
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();
        }