Changes

Jump to: navigation, search

User:Dhhodgin

1,681 bytes added, 18:59, 5 February 2010
Code Blocks
== Code Blocks ==
Here is a list of code blocks I have written for the processing.js project<br />
=== decimalToHex() ===A helper function used with hex to convert a number passed in to hex and add any specified padding  var decimalToHex = function decimalToHex(d, padding) { //if there is no padding value added, default padding to 8 else go into while statement. padding = typeof(padding) === "undefined" || padding === null ? padding = 8 : padding; if (d < 0) { d = 0xFFFFFFFF + d + 1; } var hex = Number(d).toString(16).toUpperCase(); while (hex.length < padding) { hex = "0" + hex; } if (hex.3 length >= padding){ hex = hex.substring(hex.length - wippadding, hex.length); } return hex; }; === hex() ===hex(x, y) function for processing. x is a byte, char, int, or color. y is the length of the string to return.commit [http: blendColor//github.com/dhodgin/processing-js/commit/d51adccc9acfeb4fa286366c98e06a33ad296524 hex()commit]  // note: since we cannot keep track of byte, char, blendand int types by default the returned string is 8 chars long // if no 2nd argument is passed. closest compromise we can use to match java implementation Feb 5 2010 // also the char parser has issues with chars that are not digits or letters IE: !@#$%^&* p.hex = function hex(value, len) { var hexstring = ""; var patternRGBa = /^rgba?\((\d{1,3}),(\d{1,3}),(\d{1,3})(,\d?\.?\d*)?\)$/i; //match rgba(20,20,20,0)or rgba(20, copy20,20) if (arguments.length === 1) { hexstring = hex(value, 8); } else { if (patternRGBa.test(value)) { // its a color hexstring = decimalToHex(p.rgbaToInt(value),len); } else { // its a byte, char, or int hexstring = decimalToHex(value, len); } } return hexstring; }; 
=== copy() ===
p.copy = function copy(src, sx, sy, sw, sh, dx, dy, dw, dh) {
1
edit

Navigation menu