### Archive

Archive for the ‘Graphics’ Category

## Fireworks (Processing)

A little something I knocked together in Processing language (source code here). I used a bit of calculus to determine the trajectories of the sparks — nothing too tricky, just a bit of integration.

I have an idea for an animation (or maybe a game?) which would involve finding the roots of a 4th degree polynomial to determine where a trajectory (two quadratics) will intersect with a circle. I’ll be using NumPy to do this, as once you’ve defined the polynomial NumPy can find the roots automatically.

I’ll also investigate NumPy alternatives for Java so that I can use Numerical programming with Processing.

Categories: Graphics, Maths, Processing

## Making a rogue-like game with libtcod

Well I haven’t yet made a roguelike game, but I have completed a short tutorial on using the libtcod library.

Trapped in a lonely dungeon. Wait... who's that?!

Libtcod is a library with wrappers available for numerous programming languages which aids in the creation of roguelike games. I happen to be using the Python wrapper.

It provides a special true-colour console with plenty of neat tricks like customizable fonts, blitting of images and off screen drawing areas. These provide the potential for some stunning visuals that still have a blocky, old-school, feel.

While I’m sure these facts alone would make it useful for a great many styles of game, libtcod also provides numerous helpful toolkits which, for the most part, are aimed at roguelike developers.

Basically all of the standard routines that you would otherwise need to figure out for yourself before you can start designing your unique game. These include:

• Field of view toolkit. What can you see in the dungeon… where does your torchlight fall?
• Path finding toolkit. Compute the path from A to Z in your dungeon.
• Keyboard and mouse support
• BSP dungeon generation toolkit. Tweak the parameters for dungeons, towns, forests or whatever.

Plus a few more neat features you may not have ever imagined you would need for a roguelike:

• BMP and PNG support
• Heightmap toolkit 😯
• Perlin noise support. Hmmm… ocean anyone?
• Random number and compression toolkits

It’s probably important to note that you can use any or all of the toolkits that you choose… If you would prefer to implement your own dungeon generator for example, that’s fine too. In fact there is still plenty of work still to be done as a game developer. For instance, libtcod won’t implement the monster AI or combat for you (yet).

Lately I’ve been focusing on learning C++, and if I’m to learn one new language a year (which seems a reasonable goal) then this is certainly the year of C++. However, I would also like to have fun with a language that I already know well (ie. Python), and this is where I see libtcod fitting in. My verdict so far is that I like this library and I think I could have a lot of fun tinkering with it.

I’ll post my game here when it’s awesome 😀

Crikey, I nearly forgot! The tutorial that I was blathering on about at the top of this post is here. At the time of writing this only the first part has been written, but that is enough to create the explorable dungeon level seen in the screenshot above. Here’s hoping that the authors finish the remainder of the tutorial sometime soon.

Categories: Games, Graphics, Plans, Python

## It’s Compilin’ Time!

Further to my last post, I actually have coded a very simply Mandelbrot set renderer in C++.

I’m quite familiar with the basic syntax of C++, so at the outset I though the main challenges would be:

1. dealing with complex numbers
2. saving the results as an image file

After some mild Googling both of these challenges were surmountable.

C++ has a standard library header “complex,” which implements complex as a template class. Whatever that means. Anyway, import “complex” and you now have complex number support. See the code below for a demonstration.

For PNG support I used PNGwriter (also available in the Ubuntu repos). PNGwriter’s project site has plenty of example code, and the usage seems very straight forward. The only stumbling block (for me at least) was getting the compiling options right to “link” the PNGwriter library. As it turns out, some or all of the following command is required to compile this code:

g++ main.cpp -o my_program `freetype-config –cflags` -I/usr/local/include -L/usr/local/lib -lpng -lpngwriter -lfreetype

Aside from that bit of unpleasantness, it was really no harder to write this in C++ than in Python. Here it the finished code:

```#include <iostream>
#include <complex>
#include <pngwriter.h>

using namespace std;

int main()
{
int bailout = 256;
int size = 800;
pngwriter png1(size,size,0,"mandel2.png");

for(int x=0;x<size;x++)
{
for(int y=0;y<size;y++)
{
int i = 0; //iterations
complex<double> c(x/(size/4.)-2, y/(size/4.)-2);
complex<double> z(0, 0);

while(abs(z)<2 and i<bailout)
{
// iterate through mandelbrot dynamic
z = pow(z, 2) + c;
i++;
}

if(i<bailout)
{
// c is outside the mandelbrot set
float value = (float) i / bailout;
png1.plot(x, y, value, value, value);
}

} // for y
} //for x

png1.close();

cout << "done!" << endl;

return 0;
}
```

Remember, if you want to try running this code you will need the PNGwriter library.

The output is of course no different from the Python version that I posted previously, but here it is for the sake of completeness:

The Mandelbrot Set

Categories: C++, Fractals, Graphics

## See Plus Plus

These Buddhabrot scripts can sure be processor intensive. I would be better off programming them in C or C++, much as I do love Python. They are rather trivial, so it shouldn’t be too difficult.

One purpose of this blog is to openly record my musings of the various things that I think I ought to do—in the hope that I may remember to actually do them. This is but one such open musing.

Categories: C++, Fractals, Graphics, Plans, Python

## Deeper into the Buddhabrot

My previous Buddhabrot images were built up from many thousands of ‘z‘ orbits. Over time the trails left by these orbits average out into nice soft symmetrical clouds. Most of what you can see are the trails left by the orbits that survive for relatively few iterations before escaping to infinity (there are so many more of this kind of orbit).

If you filter out these “shallow” iteration orbits and instead render only orbits with deep iterations something very interesting happens. The paths of the individual orbits become discernable. They almost look like temporary strange attractors, spinning and swirling before finally blowing away on the winds of chaos.

Take a look at these fantastic patterns (click to enlarge):

Deeply iterated Buddhabrot

This image consists only of orbits with between 20,000 and 30,000 iterations.

As with my strange attractor images, due to a few very bright pixels, it was necessary to render in 16-bit greyscale and then equalize the images to bring out the details which would otherwise be too dark to see. Normalize or auto-levels won’t do the trick. I used ImageJ for the equalize function.

If more orbits were calculated, over time a regular and symmetrical pattern should arise.

Here is the same image as above allowed to accumulate roughly 3x the orbits:

Some interesting discussion of deeply iterated Buddhabrots can be found here.

Categories: Fractals, Graphics