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 :)

Friday, July 23, 2010

On average..

"Announcing that on average, people have an average intelligence is kind of boring. What's interesting about intelligence and what is interesting about things like personality is the variation around the mean and the explanation about that variation. And that's what we need to start talking about now.

Oh, btw. well, it is, of course, by definition the case, that on average, people have average intelligence, they don't believe it. If you ask people "Do you think that you are more intelligent, less intelligent or about of average intelligence compared to the rest of the population, you'll get some distribution around that, too. But you'll find that the average perception of intelligence is that we're all above average.

This goes for a variety of other questions like "How good looking are you? Above average, below average or average?". Well, we're all little above average there, too. It turns out, that there is one group that gets the answer correct. And if you ask this group of people on average "Are you brighter or dumber than average, they'll come out in the middle. Asked "Are you cuter or uglier than average?", they'll come out, you know, average. Anybody knows who that group is? ….. Yes, it's the depressed. Depressed people have an accurate assessment of their own intelligence and good looks. In fact, it has been seriously argued, that part of what keeps us undepressed is an unrealistic assessment of the world. Right? We're smart, we're good looking … if we knew the truth, we all will be depressed. But that's a topic for another date. …."

Extracted from the Jeremy Wolfe's lecture "Intelligence: How do we know you are smart?"

Sunday, July 18, 2010

from A to B losing time T

Traveling from point A to point B means losing time t. Say, knowing the distance and your speed, you can proudly calculate the time you gonna lose. :) This, however doesn't solve your problem.

Happily, we live in a wonderful world (what have our poor parents done without the magic devices we own?!? ) and now we are able to graduate MIT without leaving our dens. :) Check what I found here. Amazing, wonderful, funny, especially this lecture dedicated to the subject of "behavioral psychology" is the perfect stuff to entertain you on your way to work or university or in the train/plane/car/whatever. Why we stop inserting a coin in the cola vending machine when it stops giving us cola but we don't if we gamble? How can you implant and modify false memories in somebody's mind. Or how every cell of our brain is mapped to a small areas of our bodies.. Really interesting stuff. :)

Oh, and last week we won the "KIT Company of the year award", part of the simulation we did during the previous semester in the "Business Leadership" course. The prize itself is not important, but the fact, that we almost believed ourselves in having the future in our hands and knowing what we want and wanting all that so much… :) (btw, we stands for 3D Innovations: Diana, Christian, me and Martin)

What else… what else.. Tomorrow I have to get the chips from the custom office. I also have to fight again with the bureaucracy in Deutsche Bank to get my bank statement letter translated in English. Firefox has a new version 4. The rechargeable battery of my macbook was almost up to explode. "But the wind still blows over Savannah and in the Spring the turkey buzzard struts and flounces before his hens." ;)