Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

hex addition factored out

  • Loading branch information...
commit 8cb323440607071bac1293f26c0f89479707d05b 1 parent 5aa87ed
@cpdean authored
Showing with 15 additions and 11 deletions.
  1. +15 −11 background/index.html
View
26 background/index.html
@@ -62,21 +62,25 @@
return vector;
}
+ var addHex = function(a,b){
+ //assumes hexes are 2 digits in length
+ var first = parseInt(a,16);
+ var second = parseInt(b,16);
+ var newhex = first+second;
+ newhex = newhex.toString(16)
+ if(newhex.length < 2){
+ newhex = "0" + newhex;
+ }
+ return newhex;
+ }
+
var applyVector = function(color,vector){
var baseChannels = channels(color);
+
for(var i in baseChannels){
- var base = parseInt(baseChannels[i],16);
- var v = vector[i];
- v = parseInt(v,16);
- var newbase = base + v; // calculate rebound
- newbase = newbase.toString(16);
- baseChannels[i] = newbase;
- }
- for(var i in baseChannels){
- if(baseChannels[i].length < 2){
- baseChannels[i] = "0"+baseChannels[i];
- }
+ baseChannels[i] = addHex(baseChannels[i],vector[i]);
}
+
return baseChannels.join("");
}
Please sign in to comment.
Something went wrong with that request. Please try again.