tips:dynamiccolor
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tips:dynamiccolor [2015/01/22 02:41] – [Introduction] rahul_pawa | tips:dynamiccolor [2016/07/05 19:32] (current) – Correcting this entry to match below (which is correct) wmissimer | ||
---|---|---|---|
Line 19: | Line 19: | ||
- | {bl} > 66 and string.format(' | + | {bl} > 66 and string.format(' |
Line 30: | Line 30: | ||
Hexadecimal is a number system that uses base 16, instead of the base 10 that our decimal number system uses. This means the numbers 0-15 can be represented by a single digit, to represent those numbers past 9, alphabet characters are used (i.e. 10 in decimal is A in hexadecimal, | Hexadecimal is a number system that uses base 16, instead of the base 10 that our decimal number system uses. This means the numbers 0-15 can be represented by a single digit, to represent those numbers past 9, alphabet characters are used (i.e. 10 in decimal is A in hexadecimal, | ||
- | In Watchmaker, you can insert code into the color field by selecting the color field of an object, then tapping the 6 digit color code to the right of the color selector. This will open up the standard variable list you see when editing other fields. From here you can use any variable you want to create conditions that will result in different colors, or even create a color that depends on a variable. | + | In Watchmaker, you can insert code into the color field by selecting the color field of an object, then tapping the 6 digit color code directly under the check mark. This will open up the standard variable list you see when editing other fields. From here you can use any variable you want to create conditions that will result in different colors, or even create a color that depends on a variable. |
Line 50: | Line 50: | ||
- | ==== Transition Color As Battery Drains, From Green to Yellow to Red ==== | + | ==== Gradually |
- | {bl} > 66 and string.format(' | + | {bl} > 66 and string.format(' |
- | Here again we are using a condition to set the color value of an object, this time the condition is {bl} > 66, and the value we get is a function of the battery level: string.format(' | + | Here again we are using a condition to set the color value of an object, this time the condition is {bl} > 66, and the value we get is a function of the battery level: string.format(' |
- | The string.format function is how you build a string in LUA. The part in the parenthesis after string.format are its arguments, each argument is separated by a comma. So the first argument is '%x%s', second is (100-{bl})*255/ | + | The string.format function is how you build a string in LUA. I am using it here to convert the decimal number generated by the formula (100-{bl})*255/ |
- | Let's talk about that first argument, you always need something like this when you use string.format. It always needs the single quotes ('' | + | Let's talk about that first argument, you always need something like this when you use string.format. It always needs the single quotes (' '), and in those quotes is a code that tells LUA what our string will look like. In this case, %.2x tells it the first thing in our string will be a 2 digit hexadecimal number, and %s tells us it will be followed by a string (some letters or numbers). The formatting here is also important, note that there is no space between %.2x and %s, this tells LUA that there shouldn' |
- | The second argument is a bit of code that uses the battery level, it correlates to the %x in the first argument. The code itself is: (100-{bl})*255/ | + | The second argument is a linear formula |
The third argument is a string that is simply the rest of the color code, in this case I want maximum green and no blue. | The third argument is a string that is simply the rest of the color code, in this case I want maximum green and no blue. | ||
Line 67: | Line 67: | ||
The result is that the color changes from bright green to bright yellow with each battery decrease. | The result is that the color changes from bright green to bright yellow with each battery decrease. | ||
- | There is similar code in the second condition to transition from yellow to red when the battery level is between 16 and 66. | + | There is similar code in the second condition to transition from yellow to red when the battery level is between 16 and 66: |
- | {bl} > 16 and string.format(' | + | {bl} > 16 and string.format(' |
+ | |||
+ | In the above you should note there are now four arguments in the string.format function. The three codes each correspond to arguments 2-4 in order. The formula has changed a little because I am using a bigger range, I've decided that I want the gradual transition from yellow to red to start at battery level = 66, and end at battery level = 16. | ||
+ | |||
+ | And finally, if the battery is below 16 the color will be bright red: | ||
+ | |||
+ | or ' | ||
- | And finally, if the battery is below 16 the color will be bright red. | ||
I put this code into a circle that is shaded using the segment shader option, with the code {bl}*3.6 for " | I put this code into a circle that is shaded using the segment shader option, with the code {bl}*3.6 for " |
tips/dynamiccolor.1421894501.txt.gz · Last modified: 2015/01/22 02:41 by rahul_pawa