I am a 21 22yr old, on a quest to discover self. Student of life. Web Designer, Developer, Photography freak, & an Artist by passion. And a Software Engineer by profession.
This is my online space, which would showcase my thoughts, ideas and works. If you have any questions, comments, feedback or requests feel free to shoot them
November 6th, 2011 | In Processing, Programming | No Comments »
Most games or applications which make use of arrow keys, sometimes require the use of multiple combinations like UP+RIGHT, LEFT+DOWN, etc also. I was trying to do the same for a 3d game I was trying to write in Processing. It might seem like a simple problem, which it is, surprisingly i couldn’t find anything on it. So after playing around with a little bit i figured it out.
Each key when pressed and released individually triggers a separate event, including for combinations of keys. Hence the way to test if both Up+Right keys are pressed, is to store the pressed status of individual keys, and clear their status individually when each key is released.
Here is the processing code. The logic should be applicable for any language and platform.
class KeyStateReader {
//binary sequence for easy state storage
static final int K_UP = 1;
static final int K_RIGHT = 2;
static final int K_DOWN = 4;
static final int K_LEFT = 8;
int keyState;
//combine the key stats into single variable by logical |
public void onKeyPress() {
int kType = getK();
keyState |= kType;
}
//on release clear individual bits
public void onKeyRelease() {
int kType = getK();
keyState = keyState ^ kType;
}
// pass a key combo using logical or '|' ( UP | RIGHT ) to see if it exists.
public boolean isKey(int k) {
return (k & keyState) != 0 ? true : false;
}
// do we have any at all ?
public boolean hasAnyKey() {
return keyState > 0;
}
public int getK() {
switch(keyCode) {
case UP: return K_UP;
case DOWN: return K_DOWN;
case LEFT: return K_LEFT;
case RIGHT: return K_RIGHT;
}
return -1;
}
}
KeyStateReader keyState = new KeyStateReader();
void keyPressed() {
keyState.onKeyPress();
}
void keyReleased() {
keyState.onKeyRelease();
}
To check for key combos you can now do this
void checkKeyCombo() {
// for UP+RIGHT
if( keyState.isKey( KeyStateReader.K_UP | KeyStateReader.K_RIGHT ) ) {
do_something_up_right();
}
// You can even check them individually
if( keyState.isKey( KeyStateReader.K_UP ) ) {
do_something_up();
}
if( keyState.isKey( KeyStateReader.K_RIGHT ) ) {
do_something_right();
}
}
There are definitely other ways to do it too, like maintain an array with all the keyCodes and check if the key being tested is available in the array. That way you will be able to track multiple keys and you wouldn’t have to re-define key codes for each of them.
Tags : code, games, processing, snippet
October 25th, 2011 | In Photography | No Comments »
Am a big fan of Google Reader and have subscribed to hundreds of RSS feeds. I love browsing through Flickr. I am addicted to it, especially to their explore section, where daily they come up with few hundred most interesting photos from flickr for that day.
So I wrote a PHP Script which generates an RSS feed of the 100 most interesting photos on Flickr’s explore, every single day via a cron job which uses Flickr API and a bit of cUrl magic. A 100 photos are published to the RSS Feed, every-single-day. The explore positions vary through out the day, but only those that appear to the script when it runs are considered.
Every single day I go through those photos, I am left inspired and mesmerized. There are so many amazing photographers out there, that simply watching their work is a delight. It just makes my day. Here is the Feed URL for you to subscribe for your photography delight.
Feed URL - http://feeds.feedburner.com/Flickr-Daily-100-Interesting
You can use any Feed Reader you want. If you are not sure I would recommend Google Reader.
Tags : explore, feeds, flickr, reader, rss, script, subscrive
April 9th, 2011 | In Ramblings and Rantings, Thoughts & Thoughts | No Comments »
(Posted for 2nd of April, My Birthday)
Life is like a loop, it goes on, and on, iterating through every passing year. This post, commemorates my 22nd one, which as a customary, I have done in the past too. It helps keep record, of what I wanted to do, what I have done, what I am going to do or atleast that which I thought I should do, leaving behind a trail of how I have changed. So a decade later, when I have the need to slap myself, I can go against my ego and do so, with proof.
Every year It feels I have come to fill the gap, a gap at which I seemed to have sucked at, an year back. I feel good, or almost, because before that happens, an introspective realization hits that its just another improvised gap, like suckiness in recursion, for the coming year. This observation has been quite consistent over the past 5 years. Or so I remember.
Each year that goes past, I consider myself to have become an year younger, a tradition which helps keep the spirit going, for I would have left some baggage behind, to move on, to look forward for things ahead in life. This time its different, I am 1 year older, truly, for the things I have been through, what I have picked up, can never be left behind, can never be forgotten, never be healed. And yet I seem to be looking forward and ahead in life, for the times that are yet to come. The only true way of healing grief is by accepting it and letting it become an integral part of what and who we are. That probably makes me an entirely different person, different to me atleast, different from what I was an year back. I think I have started to accept and embrace so drastic a change, for its the only way to survive life and live it. Its a significant milestone in life, one which I dearly wish I didn’t have to arrive at.
Photography has stuck on with me, for over 2 years, to become a serious hobby, my best friend, helping me, when in need, to come out, cope up, move on & cheer up. It has helped me make memories few of which I would forever cherish, helped make new friends, talk to and interact with other people, with whom I might not have otherwise. Have also picked up something which I thought I lost 10 years back, only to get much better at it – Sketching. That makes it 3 things, check & done.
One of the things worthy of mentioning, that which has gone to change my way of thinking, my opinions, given a chance to make few new ones, to make some very strong & to break a quite a few too, is a book, “Fountainhead by Ayn Rand”. Those who read the book, need no more explanation, those who haven’t, should read without asking for an explanation. It is the one book which made me truly believe that books have power to influence, change and redirect a person by 180 degrees, a change worth skipping all your meals for, in case you thought books aren’t worthy enough. Reading wise, read more than 20 books, which considering that I never took to reading before, is another check.
India won the Cricket World Cup 2011, co-incidentally on the B-day, thats one more thing, no two things, double check.
2 years back I earned myself a DSLR for my B’day, out of the freelancing gigs I did, way back at college. It changed my life. Last year I earned myself my very first job as a backend/web developer. It changed my life. This time, as a life experiment, despite knowing that I love the web, I put myself (or life made me to be exact) in a position which I have no idea how I would possibly handle, and the only way of knowing how I would, is when I am in it and have no choice – a shiny new job, as a C++ dev.
This has given me a new sense of feeling towards life, me the ego, myself as a person and the world around in general, which I shall want to keep to myself. With it, I seem to have gotten a better idea of what I would want to do and importantly what I don’t want to do, which if I have to, I atleast know how I should want to.
The usual ritual is to make huge list of resolutions, as the self-observed pattern says that 60% of them get completed in most cases. This time there are only few, most of which are the ones that overflowed from last year’s list, and few other newer personal ones, which to summarize are – Run, Draw, Shoot, Travel, Read, Meet, Speak, Express.
(Posted for 2nd of April, My Birthday)
January 25th, 2011 | In Thoughts & Thoughts | No Comments »
Knowledge weighs more than anything
And what matters is we strive to push our bounds for more of it…
the first sketch was originally drawn for this post
January 24th, 2011 | In Ramblings and Rantings, Thoughts & Thoughts | No Comments »
Discussions are good. Debates are better. Great when they are impromptu. Awesome, when they are with people who have respectable amount of knowledge gained over many years. Splendid if it is at workplace, for it adds positive energy to the environment, and forms a perfect ground for having an intelligent conversation. The one having naive ideas gets corrected and directed. One with more knowledge knows the other persons perspective. One who has no idea, has an opportunity to learn about both the sides of the argument, that if they were to show atleast a tiny bit of interest, a pretty big IF. Its a perfect win-win-win situation to be in, if take in the right stride.
For if they aren’t, they only add up negative value to the environment, by discouraging the lower peer, passing comments around in numerous ways which certainly aren’t productive for anyone. Such people neither are interested to learn nor they suck it up. There is no excuse to not put on headphones and get cracking with their work, when they are provided with a laptop, with high speed internet, by streaming music or any other form of distractive concentration they may want, rather than whine about how much they are being distracted, without noting the fact that they are actually wasting more time by IM’ing others to pass those comments, some of which go out of the way to provoke by calling mannerless pets who are creatures unconcerned about violating their its-just-another-job bubble, as if it were equivalent to a Hiroshima attack.
One may be good at something, gets things done, and not concerned about anything else, like slaves. But slaves never change anything, not for themselves, not for others. Sure it may get them an increment, better rating, a promotion, but for what? To become a better slave? Such attitude won’t make them any better, unless they strive to learn something, something new and do something differently. A 2 year old who strives to learn is always better than a 10-year-old slave who just wants the day to end. For learners are the ones who will invent, who will change the way things are done, or perhaps even change the world.
There is no boasting or bias on my part. I don’t claim to be any better than anyone. For I know, know it well and accept it all, that I am young and most or all of the billion ideas and opinions that I have are naive. I am just trying to change that. I just want to learn, become less naive, and a better person, consume in every drop of knowledge I can find, drink it like I haven’t had a drop, for there are more things to learn in this world then we have time for, so much so that one lifetime is just not enough. If I can, I would try to help anyone with as much little as I can, the way I am being helped. And I certainly would remember to suck it up when its my turn, which I did when I got few concepts explained by a junior. Being a wannabe-[better]-person is not a bad thing. It’s an awesome thing, when effort is being made. Its not how people look at, make me feel or treat that bothers me, for I don’t give a rats ass. It’s the sometimes lame-attacking and know-it-all attitude that people show towards others in general that worries me.
Not everyone is same, definitely not. But if one is neither trying to be a better person nor letting others, let alone adding positive value, what’s the point?
Tags : attitude, debate, discussing, learning, opinion, work
January 14th, 2011 | In Technology, Thoughts & Thoughts | 3 Comments »
Let me introduce to you the another class of so called humans known as – Attention craving zombies! They belong to an advanced generation of “Empty Vessels” species of viruses, which originally known to have originated in relation to solid empty objects mostly metals for making lot of noise, crept into human bodies. This condition is due to an infection, known as “emptyvesselism”. This like a disease manifests itself inside the entire human body, but in all cases it resides inside the human head. Hosting itself inside the head logically makes sense, as the skull has the most vessel like structure
As technology has evolved to allow the humans via their brains and hands to communicate over the internet, the virus emptyvesselism has evolved to develop a new digital form, more like a sister-virus. It has to be in contact with its parent being at all times to exhibit active intelligence. But it also shows surprising amount of persistence through autonomous existence in form of noise data when it is out of contact with its parent virus, for example when the host is sleeping or dead. And it hasn’t stopped with the human brain and mouth, it has taken over the Internet too. Since actual vocal noise takes up lot of bandwidth it takes the form of textual noise data which takes way way less space, makes sense. Looks like a pretty intelligent virus, doesn’t it?.
[1] This also makes me suspect if the human skull allegedly known to have been made up of bone or more specifically calcium is indeed made up of pure metal, and the brain just another form of emptiness to fill it. This needs further philosophical investigation.
The virus whilst keeping its victim by inducing a trance-like state by making them crave attention like zombies and giving it to them. They loose a sense of the world, reality, and start to embrace it as a part of life, until it becomes their life, a life which seems is only liked by people who are also infected with it. The usual effects of any virus is mostly biological, but emptyvesselism, its psychological (leading to biological), sociological, economical eventually leading to biological side effects. And the technological residue it leaves behind is capable of exiting more viruses to grow in.
Clinical pathology of the virus also reveals that it exhibits a progress structure similar to that of common viruses, like aids, cancer, etc, but in vastly different fashion and pertains to the psyche of the victim. Its quantified via the factor “coefficient of emptyvesselism” or simply zombicity(read: zohhm-bi-ci-ty). Emptyvesselism in its internet form is measured by the term tzombicity (read: zzohhm-bi-ci-ty). The value of the factor as preferred by most humans is a word which a combination of a synonym to word “psyho” and from the Oxford dictionary of Profanity.
Even though there are many methods to cure a person of this disease, the most effective way is through Self-Realization, which is known through observation to happen just before the the active-psyche is annihilated by the infected-psyche. This happens only if the active-psyche earlier had – a self realized purpose, a purpose by defined others, a dream or a goal in life.
The virus can also be neutralized by extreme levels of determination, which in many cases causes agitation amongst other victims and they might try break it. Ones the person has come out of it, they may choose to be entirely disconnected or still stay in contact with the virus yet have no side-effects as they seem to exhibit extreme levels of immunity. But as with any disease, higher the zombicity, more difficult it is to cure.
[2] Presence of this virus is very much apparent in many Internet services, prominent among them is Twitter, where people just try to chatter in bursts adding only noise but no value in the name of making friends with unknown people. What they don’t know is that they are retarded, as their so-called-friend is also infected with emptyvesselism.
Another popular place for these zombies to get together is Facebook where one can create, add and share noise amongst the comfortable bounds of (so-called-)friendships, and it can get more rapidly spread here.
Some purists may classify blogging as form of emptyvesselism too, but rehabilitated veterans claim that in many cases it has always been an informative side-effect. But all good-ish-side-effects are not entirely good. There is noise too, in the form of though usually infrequent but an extended burst of words.
Notes:
[1] Logical inference(s) for the insane.
[2] The naked eye observable conclusion(s) for the sane.
(Credit: Pencil sketch version by me, of a painting by allie push)
Tags : disease, humor, Internet, life, Rambing, technology, thoughts
December 20th, 2010 | In JavaScript, Programming | 1 Comment »
Fractals are fun to understand and also to code. They are also philosophically significant as they offer infinite scope for dissecting an given entity, event in life or for the matter of fact the very human nature, as its never ending, but thats subjective.
L-Systems are generating self similar fractals, in which an initial set of generating rules cumulatively applied on an initial state for given ‘n’ generations produces a growing fractal. The production rules are a variant of formal grammar, very logical and simple to understand and create. Its concisely explained with examples in this wikipedia article on l-systems.
Couple of days back, did an impromptu code sprint and wrote some code for the lsystem-js lib project started by @cmdr2. The Javascript lib can be used to define production or fractal generation rules, handlers for variables and visually draw it on canvas (working on the last part to integrate into the lib itself).
The library is very simple to use, and has helped me to understand few fractal objects as simple as Sierpinski Triangle which for some i have never been able to push into my mind
Here is an lsystem-js lib example to generate a Fractal Plant
Variables :
X, F
Generation rules :
X → F-[[X]+X]+F[+FX]-X
F → FF
Action
F : Move forward
+: Turn 25° right
- : Turn 25° left
[ : preserve current state
] : retrieve state
X : do nothing
Number of generations
5
Code fragment to generate the fractal
// New lSystem - fractal/tree
frac = new lSystem.LSystem ( 'X', {'X' : 'F-[[X]+X]+F[+FX]-X', 'F' : 'FF'} );
// Generate (generation count=5)
frac.generate(5);
// get context
ctx = document.getElementById('canvas').getContext('2d');
/**
* Fractal RunHandler([init defaults])
* Run handler lets one define event handlers for variables
* Here we initialize the variables required by run handler
*/
hfrac = new lSystem.LRunHandler({
a:40, // angle
x:10, // x
y:10, // y
r:5, // radius
raMap:{}, // radius-angle map/cache
stack:[] // stack for tree
});
/**
* Specify conditions. State functions
*/
hfrac.on( 'F', function() {
ctx.beginPath();
ctx.moveTo( this.x, this.y );
// cache angle values
// If the angles are repeated(highly likely),
// it will reuse existing calculations
// to preserve the decimal approximation.
hash = this.r + '#' + this.a;
if( typeof this.raMap[hash] == 'undefined' ) {
this.raMap[hash] = {
x : Math.round( this.r * Math.cos( this.a * Math.PI/180 ) ),
y : Math.round( this.r * Math.sin( this.a * Math.PI/180 ) )
};
}
this.x += this.raMap[hash].x;
this.y += this.raMap[hash].y;
ctx.lineTo( this.x, this.y );
ctx.stroke();
});
// Turn right 25°
hfrac.on( '+', function() { this.a += 25; });
// turn left 25°
hfrac.on( '-', function() { this.a -= 25; });
// push the state into a stack
hfrac.on( '[', function() { this.stack.push({ x:this.x, y:this.y, a:this.a }); });
// pop the state from the stack
hfrac.on( ']', function() {
var ls = this.stack.pop();
this.x = ls.x;
this.y = ls.y;
this.a = ls.a;
});
/**
* frac.run(arg) -> arg is a function(token) or
* -> arg is an LRunHandler() Instance
*/
frac.run(hfrac);
Simple? More to come
Tags : canvas, fractals, JavaScript, library