You have received a series of answers indicating the right direction to begin processing the spray effect. Based on your answer to my comment, you also need an algorithm for generating random points in a radius.
There are several ways to do this, and probably the most obvious would be to use polar coordinates to select a random point, and then convert the polar coordinate to a Cartesian (x, y) coordinate to render the pixel. Here is a simple example of this approach. To keep things simple, I just drew a simple 1x1 ellipse for each point.
private Random _rnd = new Random(); private void Form1_MouseDown(object sender, MouseEventArgs e) { int radius = 15; using (Graphics g = this.CreateGraphics()) { for (int i = 0; i < 100; ++i) {
Alternatively, you can arbitrarily select the x, y coordinates from the rectangle that corresponds to the spray circle, and using the equation of the circle r ^ 2 = x ^ 2 + y ^ 2 check the point to determine whether it lies inside the circle if you arbitrarily choose another point and check again until you get a point lying inside the circle. Here is a brief example of this approach
private Random _rnd = new Random(); private void Form1_MouseDown(object sender, MouseEventArgs e) { int radius = 15; int radius2 = radius * 2; using (Graphics g = this.CreateGraphics()) { double x; double y; for (int i = 0; i < 100; ++i) { do {
Chris taylor
source share