Difference between revisions of "Talk:Print"

From Kolmafia
Jump to navigation Jump to search
imported>Heeheehee
m (Using wiki format!)
imported>Heeheehee
m (And last edit to save some time.)
Line 8: Line 8:
  
  
Okay. I think I've fully worked out the logic for the numbers.<br />
+
Okay. I think I've fully worked out the logic for the numbers.
# If there's a # in front, take the first 6 digits that follow.<br />
+
# If there's a # in front, take the first 6 digits that follow.
# Remove all zeroes in the front of the string (e.g. "#00 00 F0 00 00" becomes "F0 00 00").<br />
+
# If length = 6, skip to the last step.
# If length > 7, replace the whole thing with "#00 00 00" (i.e. black).<br />
+
# Remove all zeroes in the front of the string (e.g. "#00 00 F0 00 00" becomes "F0 00 00").
# If length = 7, remove the first character (e.g. the red displayed from "#ff0 00 00" is actually "#f0 00 00").<br />
+
# If length > 7, replace the whole thing with "#00 00 00" (i.e. black).
# If length < 6, add zeroes to the front until length = 6 (e.g. "#42" becomes "#00 00 42", which looks pretty close to black --  hence my earlier misunderstanding).<br />
+
# If length = 7, remove the first character (e.g. the red displayed from "#ff0 00 00" is actually "#f0 00 00").
 +
# If length < 6, add zeroes to the front until length = 6 (e.g. "#42" becomes "#00 00 42", which looks pretty close to black --  hence my earlier misunderstanding).
 
# Pass the resultant value as your color.
 
# Pass the resultant value as your color.
  

Revision as of 18:04, 14 March 2010

Re: "How does color selection work when the specified color name / entity is invalid?"
It returns with the default, black. That is, unless '> ash print("Hello world!","apple-orange");' returns a color that looks really close to black. (No, I'm not color-blind. It returns black. Even for faulty entities, like "42".)
Edit: Apparently it doesn't recognize somewhat uncommon colors, like "lavender". --Heeheehee 06:47, 10 March 2010 (UTC)

That's true for named colors, but for numbers it appears to interpret some part of the number and chop the rest off; it was just a bit more than I wanted to look up in the moment. For instance, if you supply "#ff00000" (which is red with an extra 0), it used red; the "#" appears to make it choose the first 6 digits. However, you can leave off the "#" and it still works as expected with a 6-digit or 3-digit number; but anything else seems to be a weird substring match for which I can't find the logic.--StDoodle 13:26, 10 March 2010 (UTC)


Okay. I think I've fully worked out the logic for the numbers.

  1. If there's a # in front, take the first 6 digits that follow.
  2. If length = 6, skip to the last step.
  3. Remove all zeroes in the front of the string (e.g. "#00 00 F0 00 00" becomes "F0 00 00").
  4. If length > 7, replace the whole thing with "#00 00 00" (i.e. black).
  5. If length = 7, remove the first character (e.g. the red displayed from "#ff0 00 00" is actually "#f0 00 00").
  6. If length < 6, add zeroes to the front until length = 6 (e.g. "#42" becomes "#00 00 42", which looks pretty close to black -- hence my earlier misunderstanding).
  7. Pass the resultant value as your color.

This ASH function might help with understanding:

 string color (string input) {
    if(index_of(input, "#" && length(input)>6) == 0) return substring(input, 0, 6);
    if(length(input) == 6) return input;
    while(index_of(input, "0") == 0) input = substring(input, 1);
    if(length(input)>7) return "000000";
    if(length(input)==7) return substring(input, 1);
    while(length<6) input = "0" + input;
    return input;
 }

(is that too much string manipulation?) --Heeheehee 02:44, 14 March 2010 (UTC)