private void button1_Click(object sender, EventArgs e) { DiamondSquare d = new DiamondSquare(512, trackBar1.Value, 5); double[,] map = d.getData(); drawMap(d, map); }
private void button2_Click(object sender, EventArgs e) { DiamondSquare d = new DiamondSquare(512, trackBar1.Value, 5); double[][,] map = d.getDataStepByStep(); for (int j = 0; j < d.countSteps(); j++) { drawMap(d, map[j]); pictureBox1.Refresh(); System.Threading.Thread.Sleep(500); } }
private void drawMap(DiamondSquare d, double[,] map) { double[] map_cpy = new double[513 * 513]; for (int i = 0; i < 512; i++) { for (int j = 0; j < 512; j++) { map_cpy[i * 512 + j] = map[i, j]; } } Array.Sort(map_cpy); double minval = map_cpy[0]; double maxval = map_cpy[512 * 512 - 1]; double range = maxval - minval; double step = range / 12; Graphics g = pictureBox1.CreateGraphics(); for (int i = 0; i < 513; i++) { for (int j = 0; j < 513; j++) { double p = map[i, j]; Color clr = Color.White; if (p < minval + step) { clr = Color.MidnightBlue; } else if (minval + step < p && p < minval + step * 2) { clr = Color.Navy; } else if (minval + step * 2 < p && p < minval + step * 3) { clr = Color.DarkBlue; } else if (minval + step * 3 < p && p < minval + step * 4) { clr = Color.MediumBlue; } else if (minval + step * 4 < p && p < minval + step * 5) { clr = Color.Blue; } else if (minval + step * 5 < p && p < minval + step * 6) { clr = Color.DarkGreen; } else if (minval + step * 6 < p && p < minval + step * 7) { clr = Color.Green; } else if (minval + step * 7 < p && p < minval + step * 8) { clr = Color.ForestGreen; } else if (minval + step * 8 < p && p < minval + step * 9) { clr = Color.OliveDrab; } else if (minval + step * 9 < p && p < minval + step * 10) { clr = Color.DarkKhaki; } else if (minval + step * 10 < p && p < minval + step * 11) { clr = Color.PaleGoldenrod; } else if (minval + step * 11 < p) { clr = Color.LightGoldenrodYellow; } ((Bitmap)pictureBox1.Image).SetPixel(i, j, clr); //pictureBox1.Refresh(); } } pictureBox1.Refresh(); }