About Me

My photo
I'm a colonist who has declared war on machines and intend to conquer them some day. You'll often find me deep in the trenches fighting off bugs and ugly defects in code. When I'm not tappity-tapping at my WMD (also, known as keyboard), you'll find me chatting with friends, reading comics or playing a PC game.

Saturday, December 31, 2011

Create a simple vintage photo effect with Gimp

Hey folks!

Sometimes you might want to take a recent photo and make it look like it was taken with a vintage camera. Here's one easy way to do this. Note that the image processing software that I am using here is Gimp 2.6.1. Gimp is free software and can be downloaded from http://www.gimp.org/

Alright, just to give you guys a feel of what we're trying to accomplish, here are before and after shots of a photo that I took when visiting the Chinese Gardens in Singapore.

Before:












After:












Step 1: Open the image of your choice in Gimp.

Step 2: Duplicate the image layer one time. You can duplicate a layer by clicking on the duplicate button at the bottom of the layers panel window or pressing Shift + Ctrl + D (in Windows).

Step 3: With the new layer selected, go to Colors->Desaturate. Pick 'Luminosity' among the options presented and then click OK. Your image should now look Black and White.

Step 4: Change the blend mode of the Black and White Layer to 'Overlay'. The blend mode can be changed from the drop-down menu at the top of the Layers panel.


Step 5: Change the foreground color to the following shade of Yellow: fbf2a3

Step 6: Go to Layer->New Layer (or press Shift + Ctrl + N). Among the Layer Fill type options, select 'Foreground color'. Leave everything else as is and click OK.

Step 7: Change the blend mode of the new layer to 'Multiply' and set its Opacity to 60. Your image should now have a yellowish tinge.

Step 8: Change the foreground color to the following shade of Magenta: e865b3. Once again, add a new layer with Layer Fill type as 'Foreground color'. Change the blend mode of the new layer to 'Screen' and set its Opacity to 20.

Step 9: Change the foreground color to the following shade of Blue: 0949e9. Again, add a new layer with Layer Fill type as 'Foreground color'. Change the blend mode of the new layer to 'Screen' and set its Opacity to 17.

Step 10: That's it! We're done. You may tweak the opacities of the Yellow, Magenta and Blue layers to make your particular image seem more authentic.

Enjoy!

Friday, December 30, 2011

Light Snake for HTML5!


I have had the good fortune to explore a bit of HTML5, an emerging web standard that is poised to take the online world by storm. The technology isn't quite there yet. Current browser vendors offer differing or incomplete implementations of the standard and it's a bit of a pain to ensure that whatever you write works generically. Still, this is one of those lemons that bears watching...

The first thing that crossed my mind was to port LightSnake. Its a simple and fun game of snake and requires very minimal player input. And so, I did manage to port the game from C++ to Javascript and get it running acceptably well on most of the major browsers. One notable exception is that dinosaur of all browsers, the one that exists simply to torment all web-developers. Yes, Internet Explorer!

The project has been hosted on Google App Engine and can be accessed from the following URL: lightsnakegame.appspot.com (I wanted to get the app name 'lightsnake', but someone seems to be squatting on it).

Enjoy!
EDIT: The source of the project can be forked on github at: http://github.com/angelorohit/lightsnake

Wednesday, November 9, 2011

Light Snake

While listening to some really cool music on soundcloud, an image of the old-school Snake game popped up in my head. A game of Snake with neon lights. So, I thought to myself - "Heck, I should make this!" And so I did...


Needless to say, I didn't sleep that night.

Want to play? Get it from:

Thursday, October 27, 2011

How to erase specific elements from an STL container - the C++ way.

STL iterators are tricky little fellows. One moment they act clean and the very next, they throw their hands up and say something cryptic. Consider this snippet that erases all elements whose values are 20 from a vector of integers.

typedef std::vector<int> IntVectorType;
IntVectorType vInt;

for(IntVectorType::const_iterator iter = vInt.begin();
iter != vInt.end(); ++iter)
{
if( *iter == 20 )
{
vInt.erase(iter);
}
}

Lo and behold! The program crashes! This is because when you erase an element from a container all iterators to its position are invalidated. This just happens to be our loop iterator. So, what is an innocent programmer to do?

Well, there are two ways to erase individual elements in an STL container.

Method 1: The crude way ( recommended for cavemen/barbarians/C -programmers ;) )

IntVectorType::iterator iter = vInt.begin();
while(iter != vInt.end())
{
if( *iter == 20 )
{
iter = vInt.erase(iter); // Get iterator to next element.
}
else
{
++iter; // Increment if not erased.
}
}

The method vector::erase() returns an iterator to the element that subsequently follows the last element that was erased. So, we just use that iterator to continue looping. Good! Problem solved! Is there a better way?

Method 2: The modern C++ way (recommended for rockstars/you/me)

struct EraseFromVector
{
// Functor
bool operator ()(const int value) const
{
return (value == 20);
}
};

vInt.erase(std::remove_if(vInt.begin(), vInt.end(), EraseFromVector()), vInt.end());


Looks like g(r)eek, you say? Alright then, let me explain. Basically, std::remove_if() is a magical chap. He takes two iterators as a range within which to work. For each element within that range, he then checks the unary predicate(our third argument) to see whether the element should be removed or not. If the predicate returns true, the element is removed.

I did say "removed" but in actuality, remove_if() sends the doomed elements to the back of the container. He doesn't actually remove them. How could he? He doesn't know what kind of container he's working with. Only the container can remove elements.

The nice thing about remove_if() is that he is guaranteed by the standard to preserve the order of the elements that were not removed. So, if our vector contained the elements 10, 20, 30, 20, 40 in that order, it will now contain the elements 10, 30, 40, 20, 20.

Finally, remove_if() returns an iterator to the start of the sequence containing all those miserable elements just sitting there at the back waiting for the axe to fall. We pass this iterator as the first argument to vector::erase() and an iterator to the end of the vector as the second argument. In one full swoop, all elements in the range are erased.

Now, doesn't this seem a lot more fun than a boring old while loop? :)

Saturday, October 8, 2011

R.I.P Steve Jobs

At first, the world saw him as nothing more than a nerd, a high school drop out, a rebellious kid. Then the world saw him as a geek, a competitor, an irrational human. Being fired from Apple was the best thing that could have happened because that's what made him a real entrepreneur.

A man who looked at the potential in smaller companies and brought out the best in them. He believed in beauty and elegance in computers unlike the rest of the world. The world resisted his ideology but never killed it.

He returned and changed the music industry for the better. He went through a near-death experience. He beat it, came back and changed the entire way we perceived a digital world with the release of the iPhone. Now, the world sees him in a different light - Visionary, Creator, Future Technologist.

Requiem De Pace - Steve Jobs. You will sorely be missed.

Thursday, September 8, 2011

ACSVParser: A simple CSV parser written in standard C++.

Hey folks,
Its been a while since I posted back here... ok, its been a looong while. A lot has been going on. I've pushed forth my career in gaming all the way to Singapore! Yes, that's one of the four asian tigers and it sure is one of the best places to be working as a game developer. That, of course, does not mean I will let this blog lie fallow. So here goes...

One of the most interesting (vexing?) things about programming is that some of the simplest things turn out to be not so simple at all! Consider a CSV reader. We've probably used one (if not written one of our own) and yet we all know that it could do with a whole lot of customization. Some of the general peeves, I've heard are:
"I don't want to use commas, I like using the caret symbol!"
"Why can't I have new lines in my CSV content?"
"I want to have embedded spaces in my CSV data!"
"I want to sneeze with my eyes open, darn it!"

All of these (except the last one), led me to stop kicking the can down the road and come up with my own parser. I called it ACSVParser(after yours truly :))

The project is hosted on github at https://github.com/angelorohit/ACSVParser
Do check it out and let me know what you think (feedback, suggestions, issues).

Cheers!

Friday, May 20, 2011

Poem - The Warning

While going through an old diary of mine, I happened to stumble upon a poem I'd written in high school. It made me remember that I did want to be a writer before I became a programmer. Perhaps someday, I'll be able to do both.


The Warning

Spare me your protests for peace and love,
You do nothing but put on a lively show…
For then you disbelieve the one above,
And meekly forsake the man next door.

If autumn leaves were to fall in spring time,
Or Snowy flakes were to cover a summer street,
You would still call this poem a crime,
You would still throw tantrums and stamp your feet.

Your hunger-strikes won’t get what you want,
This isn’t the way the battle should be won,
I see starved looks on faces gaunt,
But is what you demand inevitably done?

The bomb blasts you decry aren’t one of a kind,
Hold on a bit and press rewind,
This happened before but you didn’t mind,
Now why would you get that petition signed?

Please don’t belittle this poem of mine,
I’d really appreciate it if you spent the time,
To work through each and every line,
You’ll see there’s always a reason and rhyme.