Difference between revisions of "Talk:Print"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
imported>Heeheehee
Line 5: Line 5:
  
 
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.--[[User:StDoodle|StDoodle]] 13:26, 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.--[[User:StDoodle|StDoodle]] 13:26, 10 March 2010 (UTC)
 +
 +
 +
 +
Okay. I think I've fully worked out the logic for the numbers.<br />
 +
1: Remove all zeroes in the front of the string (e.g. "#00 00 F0 00 00" becomes "F0 00 00").<br />
 +
2: If length > 7, replace the whole thing with "#00 00 00" (i.e. black).<br />
 +
3: If length = 7, remove the first character (e.g. the red displayed from "#ff0 00 00" is actually "#f0 00 00").<br />
 +
4: 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 />
 +
5: Pass the resultant value as your color.
 +
 +
This ASH function might help with understanding:
 +
  string color (string 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?)
 +
--[[User:Heeheehee|Heeheehee]] 02:44, 14 March 2010 (UTC)

Revision as of 02:44, 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: Remove all zeroes in the front of the string (e.g. "#00 00 F0 00 00" becomes "F0 00 00").
2: If length > 7, replace the whole thing with "#00 00 00" (i.e. black).
3: If length = 7, remove the first character (e.g. the red displayed from "#ff0 00 00" is actually "#f0 00 00").
4: 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).
5: Pass the resultant value as your color.

This ASH function might help with understanding:

 string color (string 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)