Procedural Generation: The First Step
I am by no means an expert in procedural generation techniques, however, from my experience there seems to be a distinct lack of information on the subject that is suitable for beginners, so I thought I'd try to cover the basic principles.
What is Procedural Generation?
As the name suggests, procedural generation is when an entity (map, object, texture, string, etc.) is created via procedures executed within the program, as opposed to being generated from static data. A procedural image could be as simple as one solitary dot, all that's required is that at least one property of the dot (x/y co-ordinates, colour) be determined procedurally. So here is your first procedurally generated image:
What Procedural Generation is Not!
Contrary to what the above code suggests, and what many people mistakenly believe, procedural generation is
not random; true, random numbers are often used, but randomization is merely a method of producing arbitrary variation. If we seed the random number generator with a static value we will produce the exact same dot each time we run the code:
randomize 8
dot rnd(200), 10
The ability to reproduce the same entities consistently is vital when the data being generated is too large to be stored in memory; this is what allows players in Elite to return to planets they've previously visited.
Know the Rules
Procedural generation relies heavily on rules, these rules are what give structure and form to the entities created. Our “procedural dot” has three rules associated with it:
1. Its colour must be the previously set ink colour.
2. Its Y co-ordinate must be 10.
3. Its X co-ordinate must be between 0 and 200.
The first two rules are static in this case so they might appear unimportant, yet they greatly restrict the type of dots we can produce with this code -- it should be apparent that infinitely iterating this code would produce a horizontal line of uniform colour. If we randomize the colour and Y axis we get greater variation but as a consequence we also lose structure:
From herein I'm going to use for-loops to display all the possible x/y co-ordinates without having to rely on the random number generator.
for y = 0 to 255
for x = 0 to 255
ink rgb(rnd(255),rnd(255),rnd(255)),0
dot x,y
next x
next y
Building Structure
Creating complex entities requires more than randomization, we must add complexity to our structure to allow for variation that follows a desirable pattern. One way to increase structural complexity is to make different parts of the process affect each other. This is like drawing two balls from a bag: the second ball cannot be the same as the first, this is an “emergent rule”; creating associations allows for rules to emerge procedurally without having been explicitly defined by the programmer.
If we take our previous snippet and associate the colour with the X and Y co-ordinates we get something a little more aesthetically pleasing:
for y = 0 to 255
for x = 0 to 255
ink rgb(x,y,y),0
dot x,y
next x
next y
It's a nice smooth gradient but we can make it more interesting by forming additional associations between the co-ordinates:
for y = 0 to 255
for x = 0 to 255
ink rgb(x,y,x+y),0
dot x,y
next x
next y
or even:
for y = 0 to 255
for x = 0 to 255
ink rgb(x-y,y,x+y),0
dot x,y
next x
next y
What do you think will happen if we change “x-y” to “x+y” or change “y” to “x-y”? We actually remove colour or complexity from the image because we're reducing the number of unique terms; we must take care to
add complexity not remove it. So maybe instead we try multiplication:
for y = 0 to 255
for x = 0 to 255
ink rgb(x-y,x*y,x+y),0
dot x,y
next x
next y
wait key
But is this procedural generation? Yes, and this demonstrates that randomization is not fundamental to the concept: we've specified the values 0 and 255 but everything in-between is generated by the program – so technically you could argue that the four corner pixels are not procedurally generated, but the rest of the image certainly is. I will repeat what I stated before: randomization is merely a method of introducing arbitrary variation.
Here is an image of all the outputs for the code examples above:
______________________
If you would like me to continue this series please leave a comment and your suggestions for future topics (relating to procedural generation).
Cheers,
OB
If you would like to send me a donation of any amount for writing this tutorial, and to encourage me to write more, then click this button:

I would really appreciate it but I don't demand it.

Formerly OBese87.