- Official Sites

- Learn

- Platforms

- Share

- Official Sites

- Learn

- Platforms

- Share

tips:flashingtext

**This is an old revision of the document!**

Ever want to display flashing text? How about a battery indicator that flashes when the battery drops below 20%? Or, maybe you'd like to show weather and date in the same space? Here's how. All example formulas are designed for the **opacity** field.

{drss}%6<3 and 100 or 0

{bl}>=20 and 100 or {drss}%6<3 and 100 or 0

Object 1: {ds}%6<3 and 100 or 0 Object 2: {ds}%6<3 and 0 or 100

The first thing you have to figure out is how quickly you want to flash. Keep in mind that WatchMaker runs calculations at 50fps, so your flash speed must be greater than 1/50 of a second (which wouldn't really appear to be flashing anyway), and watch timeouts will ruin the effect if you get much over 3 seconds. The number you choose will depend mainly on what you're trying to do. Are you wanting attention-grabbing text, or are you trying to display two pieces of information in the same space? I'd recommend 1/2 second flashing for the former, and about 3 seconds for the latter.

We're going to use a handy mathematical tool here called Modulo, which in LUA is represented by the percent sign (%). Modulo gives you only the remainder for any division problem. For example, 6/3=2 with no remainder, so Modulo would return 0. 5/3=1 with 2 remainder, so Modulo returns 2.

One second on a clock is 6 degrees of rotation (360 degrees / 60 seconds = 6 degrees/sec.). Thus, {drss} will increase by 6 each second, but it's updated 50 times per second, so for the other 49/50 of a second, there will be a remainder if we divide by 6. We don't really care what the remainder is but we know it will steadily climb from 0 to something in the 5.9 range. Using modulo, we can test for half-seconds by simply stating “{drss}%6<3”, which will result true for the first half of every second, and false for the 2nd half. After that, we simply set opacity to 100 or 0, depending on which half second it is. So, **{drss}%6<3 and 100 or 0** basically says to show for the first half of every second, and don't show for the second half.

You can add conditions to this, such as having the text flash when battery level is below 20%. In the example, the battery level display is steady until battery level falls below 20%, where it will start flashing. This could be set the opposite way (Like a “Charge Battery Now!” sign) by simply changing that first 100 to 0.

Alternating text is basically this, twice. You could choose to alternate colors, which means you probably still want to flash quickly, or you could use it to alternate displays, such as have date and weather alternate, so that both show in the same exact space. In this case, you'd want to slow things down a bit. Whereas {drss} takes 1 second to become divisible by 6, {ds} takes 6 seconds to get there. So, simply changing {drss} to {ds} in that same formula will slow things down to a 3-second flash, rather than 1/2 second. You alternate simply by reversing the opacity values on the objects, so that when one is 100 the other is 0 and vice versa. In this case, weather and date (or whatever) can each show for 3 seconds before switching to the other display.

tips/flashingtext.1422473954.txt.gz · Last modified: 2015/01/28 20:39 by jt3

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International