Watchmaker Wiki

The ultimate watch maker for Android Wear!

User Tools

Site Tools


tips:dynamiccolor

This is an old revision of the document!


Changing Color Dynamically

Examples

Change Color When Event is Approaching

 {c1bp} <= ({dtp}+(1/24)) and 'ff0000' or 'ffffff'

Transition Color As Battery Drains, From Green to Yellow to Red

 {bl} >= 66 and string.format('%x%s',(100-{bl})*7.5264,'ff00') or {bl} > 15 and string.format('%s%x%s','ff',({bl}-15)*5.12,'00') or 'ff0000'

Introduction

Changing colors dynamically could be useful for making information stand out when it is most important, or to use color in familiar ways to represent information.

When creating code that sets the color of an object, it's important to understand how that code looks and what it means. Color code is a 6 digit hexadecimal number that represents the amount of red, green and blue in that color. The first two digits are the amount of red, the middle two digits are the amount of green and the last two digits are the amount of blue. Each pair of digits has a minimum value of 00 (none of that color at all), and a maximum value of FF. The code '000000' gives you the color black, and 'FFFFFF' gives you the color white.

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, 11 is B, 12 is C, 13 is D, 14 is E, and 15 is F).

We can use LUA code in Watchmaker to create

Change Color When Event is Approaching

 {c1bp} <= ({dtp}+(1/24)) and 'FF0000' or 'FFFFFF'

This code is intended to set the color of an object to red when the next event on the agenda is less than 1 hour away, and it will set the color to white if there is more than an hour to the next event.

{c1bp} is a variable in Watchmaker that gives you the beginning time of the next event on the agenda as a percentage of a 24 hour day. We are testing to see if this number is less than the current time plus one hour ({dtp}+(1/24)). If that comparison is true, the code will return the part after the word “and” ('FF0000'); if the comparison is false, the code will return the part after the word “or” ('FFFFFF'). 'FF0000' gives us a nice bright red, 'FFFFFF' gives us a white.

tips/dynamiccolor.1421874525.txt.gz · Last modified: 2015/01/21 21:08 by rahul_pawa