Generating colourful stars on the fly
I had downloaded NeHe's latest demo, Space and in it, i saw colourful stars! Not the boring shades of grey but various colours. He did his by putting them on a large bitmap and blitting them on the screen, but for a project I'm working on, blitting such large bitmaps is too expensive a task. I would like to generate them on the fly...which leads to my two questions:
1) How do I go about generating these stars, assuming im using Allegro, and its "putpixel" function. Actually, I'd just like to know how he did his colours. Upon inspecting them through Photoshop, he used various colours in the forms of (RGB):
x,x,2x (and all such combinations)
2x,2x,x (ditto)
plus the typical gray shades.
Can anyone tell me how to get as close as possible to the colours NeHe used?
2)In the project I'm working on, the number of stars you'll see depends on your screen resolution. I have a struct called "Star" with two ints (x,y) for the coordinates, and 3 short ints (r,g,b) to hold the star's colour. How do i first declare these stars in an array of indefinite size, and then create the entire array as soon as i can get the screen size/width? (I'm using C, not c++!)
----------------------
Da Masta 0wnZ y3r azz!
Edited by - Da Masta on 7/3/00 9:49:42 AM
----------------------Da Masta 0wnZ y3r azz!
Star* starArray = NULL;// ...// nStars = number of stars you wantstarArray = (Star*) malloc ( nStars * sizeof ( Star ) );// To access star <i>n </i> starArray[n].x = myX;// To delete the arrayfree ( starArray );// To resize the array (nStars = new number of stars)starArray = realloc ( nStars * sizeof ( Star ) );
And that''s the basics of dynamically allocated arrays in C. Though new and delete make it less messy if you can use C++.
-RWarden (roberte@maui.net)
depends how many stars you have but,
putpixel(rand()%x,rand()%y,rand()%color);
should work ok. or if you have a color you want you can range around that color using a sine wave or something.
JoeMont001@aol.com | Polarisoft.n3.net
putpixel(rand()%x,rand()%y,rand()%color);
should work ok. or if you have a color you want you can range around that color using a sine wave or something.
JoeMont001@aol.com | Polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
RWarden: Thank you very much for clarifying that for me. :-)
Julio: This is what I was using to get greyscale stars:
(note: putpixel( int x, int w, int colour) and makecol(short r, short g, short b))
i = rand()%255;
putpixel(rand()%screenx,rand()%screenw,makecol(i,i,i));
This is pretty much what you were explaining with your firstpart, but what did you mean by that sine wave part? I didnt quite catch that.
Julio: This is what I was using to get greyscale stars:
(note: putpixel( int x, int w, int colour) and makecol(short r, short g, short b))
i = rand()%255;
putpixel(rand()%screenx,rand()%screenw,makecol(i,i,i));
This is pretty much what you were explaining with your firstpart, but what did you mean by that sine wave part? I didnt quite catch that.
----------------------Da Masta 0wnZ y3r azz!
well, I''m still not exactly sure of the effect you''re trying to get, but if you''re using 24 bit graphics you could find a color range you like and range around that color. or if you have some pre-definded colors you could create a look up table sort of system and after a random number is chosen it would be compared to the look up table for it''s color. that''s only if you have less than like 20 or so colors.
JoeMont001@aol.com | Polarisoft.n3.net
JoeMont001@aol.com | Polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Julio:
Oh I see what you mean now. The lookup table is a good idea but it wouldnt work for the random look I'm going for. But I asked NeHe himself, and he told me that he did it by blitting 4 colours all over one spot with transparency enabled...so this is the code I came up with:
int i; // random colour value
int rgb[3]; // rgb values
(for each star)
i = rand()%255;
// r,g,b value
rgb[0] = rgb[1] = rgb[2] = i;
// fourth value, giving the distinct colour
rgb[rand()%3] += i;
//draw star
putpixel(rand()%screenx,rand()%screeny,makecol(rgb[0],rgb[1],rgb[2]));
So I think I've solved my problem...thank you all for helping. :-)
----------------------
Da Masta 0wnZ y3r azz!
Edited by - Da Masta on July 5, 2000 5:28:27 PM
Oh I see what you mean now. The lookup table is a good idea but it wouldnt work for the random look I'm going for. But I asked NeHe himself, and he told me that he did it by blitting 4 colours all over one spot with transparency enabled...so this is the code I came up with:
int i; // random colour value
int rgb[3]; // rgb values
(for each star)
i = rand()%255;
// r,g,b value
rgb[0] = rgb[1] = rgb[2] = i;
// fourth value, giving the distinct colour
rgb[rand()%3] += i;
//draw star
putpixel(rand()%screenx,rand()%screeny,makecol(rgb[0],rgb[1],rgb[2]));
So I think I've solved my problem...thank you all for helping. :-)
----------------------
Da Masta 0wnZ y3r azz!
Edited by - Da Masta on July 5, 2000 5:28:27 PM
----------------------Da Masta 0wnZ y3r azz!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement