Oct
29
Filed Under (Technology) by Thejesh GN on 29-10-2009

As most of you know, I love JavaScript.  Recently I started exploring Processing.js to create some dynamic graphs and animation. I was bowled over by the power of Processing.js.

“Processing.js is an open programming language for people who want to program images, animation, and interactions for the web without using Flash or Java applets. Processing.js uses JavaScript to draw shapes and manipulate images on the HTML5 Canvas element. The code is light-weight, simple to learn and makes an ideal tool for visualizing data, creating user-interfaces and developing web-based games.”

The Processing language was originally created by Ben Fry and Casey Reas for Java. In 2008, John Resig ported the 2D context of Processing to JavaScript. It needs Canvas. So make sure you are using HTML5 capable browser like Firefox 1.

Setup: Download the processing.js. That is the only file you need.

Initialize processing: We need to initialize the processing engine on a canvas. We will have that in the init.js and will include that.

<html>
<head>
<script src="init.js"></script>
<script src="processing.min.js"></script>
<title>Analog Clock using Processing.js</title>
</head>
<body>
<script type="application/processing" target="clock">
//your processing code
</script><canvas id="clock">You need HTML5 canvas support.
Try latest Firefox</canvas>
</body>
</html>

The above code snippet shows the basic setup to run. We need to add our processing code inside

<script type="application/processing">
//your processing code
</script>

The init.js code actually searches for all the script tag type=”application/processing” and applies processing the code on the target canvas. init.js was borrowed from JResig‘s code examples.

Logic for the clock:
Circle has 2PI radians. So for each second/minute we have to move 2PI/60 radians. Given the center of the circle (a,b), radius r and angle t radians. we can find any point on the circle, using
x = a+r cos(t);
y = b+r sin(t);
or
x = a + r (1-t2)/(1+t2)
y = b + r (2t)/(1+t2)

I have used the first set of formula. Processing.js supports time and trigonometric functions by default.

But the 0 degrees start at horizontally and I wanted 0th hour to start at 90 degrees. And hence the subtraction of quarterCicrle which equals = PI/2.

The two main important methods are
void setup() – called initially when canvas gets loaded.
void draw() – called at the rate of frameRate.
Read the rest of this entry »



Apr
04
Filed Under (Technology) by Thejesh GN on 04-04-2009

Digg recently introduced url shortener. This is not your standard url shortener where the shortener does a 302 forward. Digg shortener displays destination site in a frame. Which means the reader still stays on the Digg.

Most of the modern web analytics software will be able to record this visit, but it will problem in finding out the actual referrer.  Also standard traffic counters like alexa don’t count this visit against your site.
So if you don’t like to that DiggBar to be displayed on your blog.  You can add this one line code to your site. Add it to your webpage’s head section.

<script type="text/javascript">
if (top !== self) top.location.href = self.location.href;
</script>

This code in fact doesn’t allow anybody to display your content in their frame. Here is the demo url http://digg.com/u1BSW to check. It should work on all browsers.
Let me know if you have any other suggestions.



Jan
20
Filed Under (Technology) by Thejesh GN on 20-01-2009

I like to comment when I read a good post. More than 50% of the blogs that I read are on either wordpress.com or hosted . So I created a simple scriptlet to fill the comment form for ease of commenting.Then I thought it could be useful to others too. So I wrote this small script to create a scriptlet for you.
Fill up the name, email and url you use while commenting. You can even have some default comment if you want. Make sure not to use single or double quotes. As of now the JS code breaks. Try to manage with out quotes : )
Once you have entered the details click “Generate Scriptlet”. If everything goes OK then the link below the button becomes “Fill Comment”. Pull it to your links bar. Now that should make your commenting easy on any wordpress blog. Send in your comments.

Your Name:

Your Email:

Your URL:

Default Comment or leave blank:

Not yet



Nov
26
Filed Under (Technology) by Thejesh GN on 26-11-2008

I am attending FOSS.IN/2008 virtually through twitter (unfortunately I could not attend due to work pressure). Here is my contribution to the FOSS world as part of FOSS.IN/2008.

Go to jFotoNotes project page

jFotoNotes is java implementation of famous FotoNotes in php. A variation of FotoNotes is also used by flickr. Fotonotes is a standard, specification, and collection of scripts for annotating images. In jFotoNotes I have used the same JavaScript libraries but I have completely rewritten the server side components in Java.
jFotoNotes



Sep
02
Filed Under (Technology) by Thejesh GN on 02-09-2008

Yet another browser to code for? I guess it will obey ECMA-262 rev3 so don’t worry too much about incompatibilities as of now. Lets see the positive side

  1. Its an open source, you get to participate and allows you to write plug-ins
  2. Each tab is a separate process.so the effect of one tab is not seen in another tab.
  3. Within each tab you have separate thread for JavaScript. So your JavaScript execution will be fast.
  4. JavaScript now runs inside a virtual machine called V8. The JavaScript is compiled to machine code before running. Now that’s an advantage for heavy JavaScript applications like Gmail. Where most of the JS resides on client side and simply gets the JSON from server to show the data. You don’t have to re-interpret the JS every time. Compile once and keep running again and again. Your apps will be super fast now. Now GWT developers don’t have worry about JS performance.
  5. Rendering is by webkit which is again open source.
  6. Looks like they have better garbage collection algorithm for garbage collection. Which will again makes my work simple.
  7. Gears is part of browser now. Your offline apps will have better performance now. Think -> Gears API is loaded as soon as browser is loaded, JavaScript is compiled to m/c code, runs in separate process and thread. What more you want? Your offline application might be as fast as any native application if not faster.

Anything else you want to add.