Sign in to follow this  
flyjason

OpenGL Generate random patterns

Recommended Posts

Hi, I would like to know how to create patterns randomly in OpenGL. What I mean is that let say I use a square and a triangle, and then mix them up so that it creates a kind of pattern. The pattern generated should be unique. That is, next time a pattern is generated, it should be different from the previous one. Perhaps OpenGL has some specific functions for performing these??... I need to know also how to save each newly generated pattern as a picture file (JPEG, GIF, etc). Thanks for helping.

Share this post


Link to post
Share on other sites
I still don't understand what you are trying to do. You mean randomly lay out polygons on a plane and get a random sort of design? Create a random sequence of shapes in a row?

Share this post


Link to post
Share on other sites
I want to get a random sort of design yeah.

Laying out some polygons (possibly squares) and then create the design. The design should then be saved in JPEG/GIF format (3x3 inches).

When the program is executed again...a new design is created but should be unique in the sense that the previously created design should be different from the newly created ones. In other words, this imply that all design should be unique.

Any idea?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What kind of design?


seriously, this is still too vague.

Show us a hand drawn example of what you'd make for the design.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The Patterns in the link. Appeart to be designed as part of a Machine Vision project -sounds like Barcodes to me.

Do Your patterns need the same requirements like they specify?
Or are you just trying to say... 'grid of black and white pixels that look interesting'?

I'm guessing that Rand() on a grid of square tiles doesnt do it for you?

Share this post


Link to post
Share on other sites
Quote:
Original post by flyjason
I would like to know how to create patterns randomly in OpenGL. What I mean is that let say I use a square and a triangle, and then mix them up so that it creates a kind of pattern. The pattern generated should be unique. That is, next time a pattern is generated, it should be different from the previous one.
...
I need to know also how to save each newly generated pattern as a picture file (JPEG, GIF, etc).

This is more of a question about generating unique random patterns than a question about OpenGL.

You need to write an algorithm that uses a random number generator (such as rand) to generate a random image, then write code to create the image in memory or use OpenGL to draw the image in memory, then use an image library (such as DevIL) to write the image to a file.

As another alternative, you could use OpenGL to draw the image on the screen and then use screen capture to save it to a file.

Share this post


Link to post
Share on other sites
Yeah I was thinking about using rand()...I know it generates random numbers.

How can it be of help to produce random images?

Any pseudocode?

Share this post


Link to post
Share on other sites
Just call rand() for each pixel in the image, would be a simple answer.
Pseudocode:

foreach (column c in image){
foreach (pixel p in c){
p.red = rand()%256;
p.green = rand()%256;
p.blue = rand()%256;
}
}




If you need anything more constructive or detailed, you have to provide some more information. What are you trying to achieve (at a higher level, that is. What do you need the generated shapes for, what are they meant to represent)

Knowing that is pretty important in order to be able to suggest ways to generate them.

Share this post


Link to post
Share on other sites
Or because those patterns were just black and white squares.


for(each pixel)
{
bool bWhite=rand()%2;
r=g=b=bWhite*255;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this