Skip to main content
gamedev.net
🔒 Locked

rand() pixel drawing

Started by GravtyKlz Feb 27, 2003 at 11:54 PM 2 replies 250+ views
Original Post
GravtyKlz
GravtyKlz
Im drawing pixels to the screen randomly but I want one have of it to be a set of random colors and the other half to use a set of random colors but one side will be darker than the other because of the random colors I let it choose but Im not sure how to make the second half a set of colors with out randomly coloring to the whole screen ill show you some of my code...
int x = rand()%200;
int y = rand()%300;
int x2 = rand()%400;
int y2 = rand()%300;

SetPixel(hdc, x,y, color);
SetPixel(hdc, x2,y2, color2);
 
I hope this all makes sense. Thanks
Ronin Magus
Ronin Magus
To get a random number betwee a minimum value and a maximum value, use this formula:

int myRand = rand()%(max - min) + min


simple enough, eh?

GravtyKlz
GravtyKlz
Seems simple. That math doesnt come out to be the same as 400?
int x2 = rand()%(400-200)+200

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.