Permalink
Browse files

Fixed a bug in TColor.toHex, typo in build script

Because of Javascript's "unusual" number representation and lack of leading zeroes from using toString(16) for hex, some colors were returning incorrect hex, for example:
c = tc.newRGB(0.2, 0.2, 0.3)
> toxi.color.TColor
c.toHex()
> "cccb4" //should be 33334c
  • Loading branch information...
1 parent cf973a1 commit 48d812bdc45291201248aebe654ee0a47dfb35ed Leonard Tirulnikov committed May 21, 2011
Showing with 15 additions and 9 deletions.
  1. +1 −1 build/toxi-color.js
  2. +1 −1 build/toxiclibs.js
  3. +11 −5 src/color/TColor.js
  4. +2 −2 utils/build.py
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -502,11 +502,17 @@ toxi.color.TColor.prototype = {
},
toHex: function() {
- var hex = this.toARGB().toString(16);
- if (hex.length > 6) {
- hex = hex.substring(2);
- }
- return hex;
+ var hexes = "",
+ d;
+ for (var i = 0; i < 3; i++) {
+ d = parseInt(this.rgb[i] * 255).toString(16);
+ if (d.length == 1) {
+ hexes += "0" + d;
+ } else {
+ hexes += d;
+ }
+ }
+ return hexes;
},
toHSVAArray: function(hsva) {
View
@@ -180,7 +180,7 @@ def parse_args():
args = parser.parse_args()
else:
- parser = optparse.OptionParser(description='Build and compress Three.js')
+ parser = optparse.OptionParser(description='Build and compress toxiclibs.js')
parser.add_option('--includes', dest='includes', help='Build includes.js', action='store_true')
parser.add_option('--physics2d', dest='physics2d', help='Build toxi-physics2d.js', action='store_true')
parser.add_option('--core', dest='core', help='Build toxi-core.js', action='store_true')
@@ -207,7 +207,7 @@ def main(argv=None):
config = [
['toxiclibs','common', COMMON_FILES + COLOR_FILES + PHYSICS2D_FILES, args.common],
['toxi-core','core', COMMON_FILES, args.core],
- ['toxi-color','color', COLOR_FILES, args.cologitr],
+ ['toxi-color','color', COLOR_FILES, args.color],
['toxi-physics2d','physics2d', PHYSICS2D_FILES, args.physics2d]
]

0 comments on commit 48d812b

Please sign in to comment.