Monday, August 16, 2010

ascii pictures

Yesterday, I wanted to experiment a little bit with ascii art and was searching for a nice simple piece of software that converts image in ascii art console output. After a while I decided to write some simple java class that do the job (not because there were no such nice programs, but I was tired of searching). It works simple, outputs the image in the console and in a txt file, takes as input argument an image file, but it is not (still) suitable for large images (> 50px each side). Works good with pictograms. And it is not quite ascii, just sign art :) If I find some free hours in the next week, I'm gonna improve it to do more and better job, but for now that's not the case. And here it is:



import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.imageio.ImageIO;


public class Visualizer {


public Visualizer(File file)
{
try
{
// the line that reads the image file
BufferedImage image = ImageIO.read(file);

int height = image.getHeight();
int width = image.getWidth();

System.out.println("Picture width: "+width);
System.out.println("Picture height: "+height);

int i, j;
String output = "";
for (i=0; i < height; i++)
{
for (j=0; j < width; j++)
{
int pixel = image.getRGB(j, i);
int grayscale = convertToGrayscale(pixel);
//writes the string for the txt file
output = output+" "+getASCIIforGrayscale(grayscale);
//prints the image in the console
System.out.print(" "+getASCIIforGrayscale(grayscale));

}
output = output+"\n";
System.out.print("\n");
}

writeToFile(output);
}
catch (IOException e)
{
// log the exception
// re-throw if desired
}
}

public int convertToGrayscale(int pixel)
{
//int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;
int grayValue = (red + green + blue) / 3;

return grayValue;
}


public String getASCIIforGrayscale(int grayValue){
String ascii = ".";
ascii = lookupTableGray(grayValue);
return ascii;
}

public void printPixelARGB(int pixel) {
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;
System.out.println("argb: " + alpha + ", " + red + ", " + green + ", " + blue);
}

public String lookupTableGray(int gray){

if (-1 < gray && gray < 40)
{
return "@";
}
else if (40 < gray && gray < 60)
{
return "#";
}
else if (60 < gray && gray < 80)
{
return "%";
}
else if (80 < gray && gray < 100)
{
return "0";
}
else if (100 < gray && gray < 160)
{
return "*";
}
else if (160 < gray && gray < 210)
{
return "o";
}
else if (210 < gray && gray < 256)
{
return ".";
}else
{
return ".";
}

}

public String lookupTableBinary(int gray){

if (-1 < gray && gray < 170)
{
return "@";
}
else if (170 < gray && gray < 256)
{
return ".";
}
else
{
return "_";
}
}

public void writeToFile(String output) throws IOException
{
BufferedWriter out = new BufferedWriter(new FileWriter("asciitest.txt"));
out.write(output);
out.close();
}



public static void main(String[] args) {

File file = new File(args[0]);
new Visualizer(file);
}

}

Wednesday, August 11, 2010

ConQuest 2010

Back from ConQuest... That was my first LARP, but definitely not the last one.
Here's the story, in pictures and words, although these two are far more insufficient to describe what happened:

Day 1:
After 9 hour train trip, we finally got there and my first impression was: Oh, God! No internet, no electricity and cow shits everywhere. I have to survive somehow until Sunday..


Der Sieger baut ab :)


The town

Day 2:
As in all stories, the world is inhabited with good and evil. At the beginning, there was only good - the pure elements: earth (avatar: Terra), water (avatar: Aqua), air (avatar: Aeris), fire (avatar: Ignis) and magic (avatar: Magica).

But then, of course, in order to preserve the balance, the evil was created. And that's us - the banished, the evil children of the second creation: Schwarzes Eis, Untotes Fleisch, Leere, Pestilenz and Technische Ratio.


Schwarzes Eis


Untotes Fleisch


Leere


The Technische Ratio is part of the story, but there are no players indeed, because it is too powerful and therefore buried.

Doerchgardt is the fortress of the Untotes Fleisch and our mission is to defend it from the attacks of the elements.


Fortress Doerchgardt


An'nai Herr von Doerchgardt


The throne of the Knochen-Königin

2 years ago, we buried the avatar of Terra under a pyramid in Doerchgardt and now, the elements want to set her free. To do that, they first have to conquer our fortress.

In this first day of the play, our swarm (Schwarm 7) of Schwarzes Eis had duty from 21 p.m to 4 a.m. We had to defend the fortress, but there wasn't much to defend at all, because the players had party and didn't care much of attacking at this time. They also didn't have the necessary equipment to damage the walls of our fortress. Therefore we succeeded in stealing a big army gun from the Neutral camp.









Day 3

Day 3 was really hard, since we had duty till 4 a.m. previous night. After long hours of defending, at the end the players invaded Doerchgardt. Which was actually good, because otherwise we had to stay till 4 a.m. again. I was very sad, but our Sharun - Andy told me that it is not a big deal and we will get our fortress right on next day. So it was…

Day 4

Early in the morning we organized a little invasion in the Air Camp, just to wake up the players and prepare them for the fight. After lunch, we all marched in Doerchgardt and in approximately 20 min the fortress was ours again. However, it wasn't for a long, because in the late afternoon the players got together and Doerchgardt fell gain. And again, it was good, because they freed us of duty during the night.
Although the fortress was theirs, they couldn't set Terra free, because the players didn't succeeded in fulfilling their plots. Moreover, the group responsible for the instructions how to free Terra was dead.

Day 5

The players seem to learn very slow, since they left not more than 20 people to defend Doerchgradt again. And again, early on Saturday, 2 swarms marched in the fortress and in 10 min it was ours. At this point, the story was black for the elements, but the rest of the day everything changed.

We attacked the Magic and Fire Camps, because we received the mission instructions to bring back 7 prisoners. A hard fight under the midday sun, but we succeeded. Moreover, we captured another Avatar (but I'm not sure which one). We were already very very tired and it was pretty clear, that we cannot keep the fortress till the end of the day… And the end of the day was also the end of the play.


On the right side - me, dead





We lost the final fight, indeed. 3 holes in the fortress wall and a burning tower. Aching muscles everywhere, sun burn and unconquerable sleep drive.. We've lost the fortress.. They freed Terra.. it's part of the game.. but in practice, when you give 100% of you, nobody can call you a loser :)