private void btnDraw_Click(object sender, EventArgs e) { Painter = null; int color = sliderColor.Value; int randomness = sliderRandomness.Value; int width = (int)nudWidth.Value; int height = (int)nudHeight.Value; if (width == 0 || height == 0) { MessageBox.Show( "Invalid width or height, both must be greater than 0", "Invalid Parameters", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var input = new Inputs { Color = color, Randomness = randomness }; Painter.Do(input); pbResult.Image = Painter.BitMap; pbResult.SizeMode = PictureBoxSizeMode.StretchImage; }
public void Do(Inputs input) { int pix; var ran = new Random(); int red, green, blue; // Range of possible hues, from 0 to 255 int maxHueRange = (int)(((float)input.Color / 100) * 255); // 0 - 255 int michal = (int)((float)input.Randomness * 2.55); // Start at a random position int x = ran.Next(_bitmap.Width); int y = ran.Next(_bitmap.Height); int dirX = ran.Next(3) - 1; int dirY = ran.Next(3) - 1; int last = ran.Next(256); int startX = x; int startY = y; for (int i = 0; i < _bitmap.Width * _bitmap.Height * .10;) { if (ran.Next(100) <= input.Randomness) { dirX = ran.Next(3) - 1; dirY = ran.Next(3) - 1; } red = ran.Next(last, last + maxHueRange) % 256; green = (ran.Next(red, red + maxHueRange)) % 256; blue = (ran.Next(red, red + maxHueRange)) % 256; x += dirX; y += dirY; if (x < 0 || y < 0 || x >= _bitmap.Width || y >= _bitmap.Height) { x = ran.Next(_bitmap.Width); y = ran.Next(_bitmap.Height); dirX = ran.Next(3) - 1; dirY = ran.Next(3) - 1; continue; } pix = (255 << 24) | (red << 16) | (green << 8) | (blue); _bitmap.SetPixel(x, y, Color.FromArgb(pix)); ++i; } }