private void confirmButton_Click(object sender, EventArgs e) { //Set the image to the project's main input if (!forMask) { Form1.currentOpenProject.SetFirstHeightmap(image); } else { Form1.currentOpenProject.CreateMask(image.width, image.height); int[,] mask = Form1.currentOpenProject.GetMask(); Bitmap bit = image.ToBitmap(); for (int i = 0; i < bit.Width; i++) { for (int j = 0; j < bit.Height; j++) { Color pixel = bit.GetPixel(i, j); if (pixel == Heightmap.ValueToColor(0)) { mask[i, j] = 0; } else { mask[i, j] = 1; } } } } this.Close(); }
//Events private void Canvas_Load(object sender, EventArgs e) { //Get the image dimensions WidthHeightDialog dialog = new WidthHeightDialog(); dialog.ShowDialog(); //Create the image and picbox image = new Heightmap(dialog.width, dialog.height); tempPicBox.Image = image.ToBitmap(); //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); }
public ImageFileNode(NodeMap map, Heightmap heightmap) : base(map) { //Creates one from a pre-existing heightmap. image = heightmap.ToBitmap(); this.heightmap = heightmap; }
public override void Apply(Heightmap targetHeightmap, 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, targetHeightmap.width); endX = Utils.CapBounds(endX, 0, targetHeightmap.width); startY = Utils.CapBounds(startY, 0, targetHeightmap.height); endY = Utils.CapBounds(endY, 0, targetHeightmap.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); double scaledSpeed = Utils.Lerp(speed, 0, distPercent); //Change the height at this position double val = targetHeightmap.GetValue(x, y); val += scaledSpeed * deltaTime; //Ensure the value stays within the limits if (Math.Abs(val) > Heightmap.MAX_HEIGHT) { val = Math.Sign(val) * Heightmap.MAX_HEIGHT; } //Apply the height change targetHeightmap.SetValue(x, y, val); targetBitmap.SetPixel(x, y, Heightmap.ValueToColor(val)); } } //End of double for loop } //End of function
private void generateButton_Click(object sender, EventArgs e) { //Get the data from the textboxes int width; int height; int seed; int octave; double persistence; double frequency; double lacunarity; //Catch any errors with the textboxes try { width = int.Parse(widthBox.Text); height = int.Parse(heightBox.Text); seed = int.Parse(seedBox.Text); octave = int.Parse(OctBox.Text); Double.TryParse(PersBox.Text, out persistence); Double.TryParse(LacBox.Text, out lacunarity); Double.TryParse(FreqBox.Text, out frequency); } catch (FormatException err) { MessageBox.Show("ERROR: width, height, seed, and octave count must all be integers.\r\nPersistence, lacunarity, and frequency are doubles"); return; } catch (OverflowException err) { MessageBox.Show("ERROR: One of your values is too long."); return; } //Generate the preview map previewMap = new Heightmap(width, height); PerlinNoise noiseGen = new PerlinNoise(seed, octave, frequency, lacunarity, persistence); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { double value = noiseGen.GetValue((double)x, (double)y) * Heightmap.MAX_HEIGHT; previewMap.SetValue(x, y, value); } } //Update the preview picture previewBox.Image = previewMap.ToBitmap(); //Enable the Okay button OKButton.Enabled = true; }
public override void Apply(Heightmap targetHeightmap, 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, targetHeightmap.width); endX = Utils.CapBounds(endX, 0, targetHeightmap.width); startY = Utils.CapBounds(startY, 0, targetHeightmap.height); endY = Utils.CapBounds(endY, 0, targetHeightmap.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 double val = targetHeightmap.GetValue(x, y); val += speed * deltaTime; //Ensure the value stays within the limits if (Math.Abs(val) > Heightmap.MAX_HEIGHT) { val = Math.Sign(val) * Heightmap.MAX_HEIGHT; } //Apply the height change targetHeightmap.SetValue(x, y, val); targetBitmap.SetPixel(x, y, Heightmap.ValueToColor(val)); } } }
public abstract void Apply(Heightmap targetHeightmap, Bitmap targetBitmap, int x, int y, double size, double speed, double deltaTime);
private void button1_Click(object sender, EventArgs e) { //Reset the image image = new Heightmap(image.width, image.height); tempPicBox.Image = image.ToBitmap(); }
public ImageFileNode(NodeMap map, String fileName) : base(map) { image = new Bitmap(fileName); heightmap = new Heightmap(image); }