TNM084 2019 Lab 1:
procedural images in general programming languages

The aim of this lab exercise is to demonstrate that there is no need for a special programming language or special programming tools to create procedural images. Almost any programing language will do. Java is a perfectly useful alternative, even if Java doesn't execute quite as fast as C or C++. Matlab is also a useful tool, for several reasons: you already have experience with it, it's a very good prototyping environment, and it contains predefined functions to create, process and display images.

Apart from the general operations and elementary functions you can find in most programming languages, it's useful to have Perlin noise and Cellular noise, or similar functions, simply because that kind of semi-regular patterns are so central to the subject.

As stated above, any programming langauge is useful for this kind of programming, but the recommended choices are Java, C/C++ or Matlab, and these are the languages for which I provide a framework and some noise functions to get you started. Similar functions exist for many other languages, and are even built into some visual programming frameworks like Processing, but if you want to use such alternatives you need to set things up yourself.

Callular noise was implemented in C from the start, and the Java port was done by me, in a somewhat ugly and inefficient but working manner. Ken Perlin wrote his modern variants of Perlin noise and Perlin simplex noise in Java, although I extended his code and speeded it up rather substantially, while also translating it to C. The C versions of Perlin, simplex and cellular noise are packaged in MEX files for use by Matlab. The MEX files in the archive below are compiled for 64-bit Windows. If you run any other platform, you need to compile them yourself from Matlab using the command "mex", but if you are running Linux or MacOS, that is a very simple process. Only in Windows is this a hassle due to the lack of a built-in compiler - hence the pre-compiled files.

The program skeletons in Java and C paint a simple animated noise image. The Java files require nothing more than a reasonably modern Java SDK and the files included in the archive below. The C program depends on the library GLFW 3 (www.glfw.org), which is included for the Windows platform in the archive (the file glfw3.a). In all computer labs at ITN, you will find the simple but useful development environment Dev-C++. The C code example contains a project file for that IDE (the .dev file). Should you prefer using Code::Blocks, Visual Studio, Eclipse or anything else, you will need to create a project with the correct settings to find the relevant header files, include files and libraries. I suggest you simply use Dev-C++ to avoid hassle.

In Matlab, you need to do the work yourself if you want to watch animated images - I gave up my attempts to get a flicker-free animation. I'm sure it can be done, I just don't have the time to fiddle with it. Even if you don't make an animated pattern in Matlab, at least consider how your pattern could be made to change over time. The relative ease with which you can make animated patterns is one of the main advantages of procedural images.

Your own computer, and/or not-Windows?

It's fine if you want to do the lab work on your own computer. (In fact, the large number of participants may require at least a few people to do so, or we won't have enough workstations in the lab.) The packages above should work on most modern computers. Unfortunately, I don't have the time to prepare files for operating systems other than Windows. The Java and the Matlab files are of course compatible between platforms, but you need to spend some extra work to get the C program to compile in MacOS or Linux. What you need to do is install the library GLFW 3 and set up a project file for your choice of development environment. I have pretty solid experience with MacOS X and Linux myself, but I simply don't have enough time to prepare this for you. MacOS X as well as Linux change enough between versions and from one year to the next for some minor details in the build process to break, and I really can't keep up. (I'm sad to say I'm not running MacOS X or Linux on a daily basis.)

Lab assignment

Your task for this exercise is to write a program that generates a reasonably interesting and relatively complex pattern, preferably in color, and where the time variable (unless you are using Matlab) is used in a manner which creates some kind of motion in the picture. Make waves, growing cells, something that looks somewhat like fire, smoke or clouds, or some slithering, shimmering, flowing or otherwise moving pattern, where you are using several different functions to create and mix procedural elements to make the image. Exactly what you do is not all that important. The most important thing is that you make something based on your own ideas, that you write the code yourself, and that the result looks more or less like you intended, or at least that you know why it looks the way it does. It's not absolutely necessary that you use a noise function in your code, but that is probably the best way to create a reasonably interesting image with a reasonable amount of work.

Please note that you are not supposed to "draw" stuff in your image in the traditional manner. The structure of your program should be a loop where every pixel is painted with the same code, a "shader" that takes as its only input the position of the pixel and the current time. In Matlab you can straighten your loops by performing arithmetic operations on all pixels in the entire image at once instead of one pixel at a time, but that's not a requirement. Just make sure you are executing the same code for all pixels.

There will be lab assistants in the room to answer questions and to help you if you get stuck, but, first and foremost, your work should be based on your own ideas, your own curiosity and your own inventiveness. Play around. Test things out. Confuse yourself. Ask questions. Learn.

The requirement for passing the assignment is to show a non-trivial, preferably moving pattern computed by your own code, and that you understand and can explain what you did. Oral examination during the lab session proper is preferred. If you don't finish in time, please finish up on your own and show the result on the next scheduled session.

Good luck, and have fun!