Fun trick: Box that flashes

Quick trick to make a flashing rectangle:

withName(
  if(Now().Second().IsEven(), "#FFFFFF", "#000000"),
  _color,
  Rectangle(10, 10, _color)
)
4 Likes

Just noticed this “fun trick” posting. I think using now() as proposed in this trick goes against a high cost in overhead.

Hi Joost, thanks for the feedback. What are the performance implications of using now() in this way?

I can’t quantify it, but it has been mentioned by Codans to be careful using now() in places where it stays active, like putting now() on the canvas to use it as clock. I assume using it for a flashing box, the function will stay ''on" and use resources in a similar fashion as what has been mentioned in the past.

Can’t find a reference to the remarks now, but if I do I will post it here.

1 Like

The thing with Now() is that it will be recalculated every seconds (as it’s its default precision) :blush: … So it can get heavy in terms of performances, as @joost_mineur said …

Blinking

Still a cool trick though :blush:

1 Like

@joost_mineur are any of these :point_down: the posts you were remembering?
(2020-02-10) https://community.coda.io/t/psa-replace-now-with-a-lower-resolution-real-time-clock-for-heavy-formulas/13759
(2020-12-11) https://community.coda.io/t/how-to-avoid-using-now-to-reduce-the-calculation-time-of-a-doc-to-check-the-hour/19998/4
(2021-08-17) https://community.coda.io/t/launched-new-features-to-manage-your-structured-data-with-precision-and-ease/24929/15

1 Like

Well, the point of the blinking box is to blink every second :slight_smile: so I guess it has to depend on Now() with second precision. 1 ms recalculation now and then won’t make much difference. But yeah, as the doc becomes more complicated, the blinking may become slower.

Personally, if I needed a blinking image in a dense doc I would rather make and upload a gif :slight_smile:

2 Likes

Thanks, a gif seems like a great solution for a dense doc, and it’s great to know about the new Now syntax that allows for less frequent calculation:
now("hour") etc.

1 Like

Yes - that’s exactly what I had in the back of my mind. Thanks for looking them up.

1 Like