![]() |
| | #1 |
| Registered User Join Date: May 2008
Posts: 1
| insert Code:
System.Drawing.Color[] colorList = new System.Drawing.Color[3];
colorList[0] = Color.Orange;
colorList[1] = Color.Green;
colorList[2] = Color.Red;
DateTime currentDateTime = DateTime.Now;
Random colorRandom = new Random(currentDateTime.Millisecond);
Color snowPen;
snowPen = colorList[];
DateTime currentDateTime2 = DateTime.Now;
Random snowRandom = new Random(currentDateTime.Millisecond);
int xIntegerSnow = Convert.ToInt32(this.Width / 2),
yIntegerSnow = Convert.ToInt32(this.Height / 2);
Pen whitePen = new Pen(snowPen, 2);
// Make it snow in random locations.
for (int indexInteger = 1; indexInteger < 40000; indexInteger++)
{
int xInteger = snowRandom.Next(1, this.Width);
int yInteger = snowRandom.Next(1, this.Height);
e.Graphics.DrawLine(whitePen, xInteger, yInteger,
xInteger + 1, yInteger + 1);
}
}
|
| AlmightyDerek is offline | |
| | #2 |
| the hat of redundancy hat Join Date: Aug 2001 Location: Hannover, Germany
Posts: 2,754
| snowPen = colorList[]; In that line, pick one color ar random: snowPen = colorList[snowRandom.Next(0,2)]; Now it will pick one color at random and create the pen. You probably want to have each line in a different color, so move the color selection and pen creation into the loop. For performance reasons you should create an array of pens with each pen the color of one of your arrays of colors. Then in your loop select one pen randomly just like you did with the colors before.
__________________ hth -nv She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate." When in doubt, read the FAQ. Then ask a smart question. |
| nvoigt is offline | |
![]() |
| Tags |
| array, color, random |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with Searching Array for Longest Sequence of an Element | w2look | C Programming | 7 | 11-25-2008 01:50 AM |
| 1-D array | jack999 | C++ Programming | 24 | 05-12-2006 07:01 PM |
| Template Array Class | hpy_gilmore8 | C++ Programming | 15 | 04-11-2004 11:15 PM |
| sorting a randomly generated dynamic array | Led Zeppelin | C Programming | 4 | 05-03-2002 09:10 AM |
| Hi, could someone help me with arrays? | goodn | C Programming | 20 | 10-18-2001 09:48 AM |