Generate Color Ramp in Javascript

Leave a comment

  var theColorBegin = 0x632593;
  var theColorEnd = 0xFF7766;
  var theNumSteps = 5;

  theR0 = (theColorBegin & 0xff0000) >> 16;

  theG0 = (theColorBegin & 0x00ff00) >> 8;

  theB0 = (theColorBegin & 0x0000ff) >> 0;

  theR1 = (theColorEnd & 0xff0000) >> 16;

  theG1 = (theColorEnd & 0x00ff00) >> 8;

  theB1 = (theColorEnd & 0x0000ff) >> 0;

  // return the interpolated value between pBegin and pEnd

  function interpolate(pBegin, pEnd, pStep, pMax) {

    if (pBegin < pEnd) {

      return ((pEnd - pBegin) * (pStep / pMax)) + pBegin;

    } else {

      return ((pBegin - pEnd) * (1 - (pStep / pMax))) + pEnd;



  function generateColor(){
    for (i = 0; i <= theNumSteps; i++) {

      theR = interpolate(theR0, theR1, i, theNumSteps);

      theG = interpolate(theG0, theG1, i, theNumSteps);

      theB = interpolate(theB0, theB1, i, theNumSteps);

      theVal = ((( theR << 8 ) |  theG ) << 8 ) | theB;

The result will display as below:


Prototypal Inheritance in JavaScript

Leave a comment

For this part, I would like to show you about how to make inheritance in JavaScript.
For Java, you can inherit from one object to one more object by using the key word “extends” to inherit all the properties of the parent object.

For JavaScript, we can make inheritance that is similar to the static language like Java also.
Now I would like to choose one trick to show here is about “prototypical inheritance”.

Here try it out with fire bug:

function Person(name, age) { 
	    if (Boolean(name))  = name; 
	    if (Boolean(age)) 
	        this.age = age; 

// Getters 
Person.prototype.getName = function () { 
Person.prototype.getAge = function () { 
         return this.age; 
// Setters 
Person.prototype.setName = function (name) { 
 = name; 
Person.prototype.setAge = function (age) { 
           this.age = age; 
// A default name for Person objects that don't have a name = "John Doe"; 

var jane = new Person("Jane Smith", 35); 

var noName = new Person(); 

Instant Messaging for Khmer Unicode

Leave a comment

Nowadays Cambodia Society has been transformed from the ancient style in exchange message from writing the message on the paper to email, because of this factor makes my friends and I want to share some contribution to the Cambodian people with the Khmer Unicode by sharing the knowledge in IT to develop one instant messaging for Khmer Unicode as soon as possible.My friend and I hope that this project will be supported by Cambodian people and the people who has ability to use Khmer Unicode.

KU-Chat will be coming soon.

Please comment us for help.

Encode URL

Leave a comment

encodeURI, escape, encodeURIComponent, or you can click below link.

Example of arguments in javascript

Leave a comment

you can run this code in firebug .

var myfunction = function(){
    alert("Arg1 = " + arguments[0] + ", Arg2 = " + arguments[1]);

Prototype example in Javascript

Leave a comment

• A prototype is a property of every JavaScript object
• Functions and properties can be associated with a
constructor’s property
• When a function is invoked with new keyword, all
properties and methods of the prototype for the
function are attached to the resulting object

var MyObj = function(name, size){ = name;
    this.size = size;

MyObj.prototype.tellSize = function(){
    alert("size of " + + "is" + this.size);

var myObject = new MyObj("Sang", "30 Inches");

Event in JavaScript

Leave a comment

onkeypress – A keyboard key is pressed or held down
onkeyup – A keyboard key is released
onload – A page or an image is finished loading
onmousedown – A mouse button is pressed
onmousemove – The mouse is moved
onmouseout – The mouse is moved off an element
onmouseover – The mouse is moved over an element
onmouseup – A mouse button is released
onreset – The reset button is clicked
onresize – A window or frame is resized
onselect – Text is selected
onsubmit – The submit button is clicked
onunload – The user exits the page