Share
Explore

Cat Photo Slideshow

A new random cat photo every few seconds.
Show me a new cat photo every
00
15
seconds.

Sure! A new cat photo is coming your way in
7
seconds


All photos provided by:
Loading…

Copy this doc
to modify it!


How it works
The wonderful folks at Cat as a service (
) provide a simple API for requesting a random cat photo:
https://cataas.com/cat
. Coda (trying to be helpful) caches images it fetches, so that if you try to add multiple images with that same URL you’ll only get a random cat the first time you add it to the doc, and a copy of it every other time. To get around this we need to do some cache busting. This is the process of adding a value to each URL that will make it unique, therefore causing Coda to fetch a new copy, and get a new cat.

An easy way to get a unique string is to utilize the current date and time, since it will never repeat. However I don’t want the cats to fly by every millisecond, so we’ll need to do some rounding so that the time is only unique every few seconds. Using some of the Date formulas we can do just that!

Time Rounded to Minute:
Rounding the time down to the nearest minute, since we’ll be handling the seconds separately.
Now(”minute”)
=>
8/19/2021 5:10 PM
Rounded Seconds:
Using the value of the slider at the top of the doc, round the seconds to the nearest interval.
Floor(Now("seconds").Second() / [Seconds Per Cat]) * [Seconds Per Cat]
=>
45
Rounded Time:
Combine the two values above to compute the rounded time.
[Time Rounded to Minute] + Seconds([Rounded Seconds])
=>
8/19/2021 5:10:45 PM
Rounded Time as Number:
Convert the time to a number, since that’s easier to plug into a URL (no spaces).
[Rounded Time].ToNumber()
=>
44427.71579861111
Cat Image URL:
Put the time at the end of the URL in a fake parameter called
now
that
just ignores.
Format("https://cataas.com/cat?now={1}", [Rounded Time as Number])
=>
https://cataas.com/cat?now=44427.71579861111
Cat Image:
The last step is to use that URL to embed an image, which is what you see above.
[Cat Image URL].Image(height:400)
=>

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.