Sunday, September 6, 2009

Messing with our new logo

I'm trying to create a new background for the header of our blog.
You can see the current result here:


It looks quite nice, like the countour-map of a long pyramid-like structure.

This is how I created this one: (in lack of 1337 photoshop sk1lls:)

I created a 24-bit bmp, with the width of 640 and height of 96. I needed this only to create the 54 byte header of my bmp file, so this actual bmp file was blank white. (This file has been saved as 'start.bmp'.)
In this small piece of java code the header will be copied to 'end.bmp':

Reader r = new FileReader("start640.bmp");
BufferedReader br = new BufferedReader(r);
char[] cbuf = new char[256];
int l = 54;
br.read(cbuf, 0, l);
br.close();
FileWriter fw = new FileWriter("end.bmp");
fw.write(cbuf, 0, l);

(Be aware, that file operations need to be in a try-catch block!)
After this, with my brand new FileWriter, I'll continue to fill up the contents of my bmp file. To do that, we need to know, that each pixel will need 3 bytes there, the so called RGB-code. In our case these 3 bytes will be equal, since we need grey lines.

First we have to put down the bottom line pixels, then the above, and so on, until reaching the top. To create the contour, I used a really simple algorithm: first I compute the distance from the border, and I'll color every seventh line, or 'height'. (Just like in a contour-map.)
This is the code:

int width = 640;
int height = 96;

for(int j = 0; j != height; j++)
{
for(int i = 0; i != width; i++)
{
boolean grey = false;

int diffHeight = Math.min(j, height - j - 1);
int diffWidth = Math.min(i, width - i - 1);

int diffMin = Math.min(diffHeight, diffWidth);

if(diffMin % 7 == 2) grey = true;

char colour = 255;

if(grey)colour = 210;
cbuf[0] = colour; cbuf[1] = colour; cbuf[2] = colour;
fw.write(cbuf, 0, 3);
}
}
fw.close();

Simple, isn't it?

When I'll have the time, I'll try to improve the look of this stuff by using a non-linear function, or by random terrain.

(By the way after setting the code color to blue, I was not able to use the line:
for(int i=0; i {smallerthan} max; i++){} // where {smallerthan} means that sign
cause there were some html errors with the styles. How comes this, google?!
I had to modify the 'less than' sign to 'not equals',
and I'm not able to modify the color of the above line...)

No comments: