Changes

Jump to: navigation, search

User:Dhhodgin

1,648 bytes added, 23:09, 28 October 2009
code blocks
==== unhex() ====
Specification for shortenunhex() in processing [http://processing.org/reference/unhex_.html here].<br />
unhex takes a string representing a 8 digit hex code as its only argument and returns an int representation of the string. JavaScript supports 64 bit floats as var's so it took a little number crunching to make it output an exact replication of the Java implementation with signed int's.
Example of this function and test is [http://matrix.senecac.on.ca/~dhhodgin/dps909/unhex_test.htm here].<br />
'''Known issues:''' None.
 
==== nfs() ====
Specification for nfs() in processing [http://processing.org/reference/nef_.html here].<br />
nfs() is a function used to format numbers as strings with padding of 0's on either the left or right of the decimal place. It accepts int, int[], float, and float[] types and returns either a single string or array of strings depending on the input.
 
p.nfs = function( num, left, right){
var str;
// array handling
if (typeof num == "object"){
str = new Array();
for(var i=0; i < num.length; i++){
str[i] = p.nfs(num[i], left, right);
}
}
else if (arguments.length == 3){
var negative = false;
if (num < 0)
negative = true;
str = "" + Math.abs(num);
var digits = ("" + Math.floor(Math.abs(num))).length;
var count = left - digits;
while (count > 0){
str = "0" + str;
count--;
}
// get the number of decimal places, if none will be -1
var decimals = ("" + Math.abs(num)).length - digits - 1;
if (decimals == -1 && right > 0)
str = str + ".";
if (decimals != -1)
count = right - decimals;
else if (decimals == -1 && right > 0){
count = right;
}
else
count = 0;
while (count > 0){
str = str + "0";
count--;
}
str = (negative ? "-" : " ") + str;
}
else if (arguments.length == 2){
str = p.nfs(num, left, 0);
}
return str;
}
 
Example of this function and test is [http://matrix.senecac.on.ca/~dhhodgin/dps909/nfs_test.htm here].<br />
'''Known issues:''' None.
== Week 1 stuff ==
1
edit

Navigation menu