Created
November 1, 2020 13:05
-
-
Save simonbs/679409464a4b46cd27c72aba9dffce80 to your computer and use it in GitHub Desktop.
Shows an image of an animal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: purple; icon-glyph: paw; | |
let pandaURL = "https://c402277.ssl.cf1.rackcdn.com/photos/7749/images/story_full_width/HI_204718.jpg?1414503137" | |
let slothURL = "https://c402277.ssl.cf1.rackcdn.com/photos/6518/images/story_full_width/iStock_000011145477Large_mini_%281%29.jpg?1394632882" | |
let redPandaURL = "https://c402277.ssl.cf1.rackcdn.com/photos/8036/images/story_full_width/WEB_279173.jpg?1418412345" | |
let pandaImg = await getImage(pandaURL) | |
let slothImg = await getImage(slothURL) | |
let redPandaImg = await getImage(redPandaURL) | |
let g = new LinearGradient() | |
g.locations = [0, 1] | |
g.colors = [ | |
new Color("#1B5E20"), | |
new Color("#2E7D32") | |
] | |
let w = new ListWidget() | |
w.setPadding(10, 10, 10, 10) | |
w.spacing = 4 | |
w.backgroundGradient = g | |
let titleStack = w.addStack() | |
titleStack.cornerRadius = 4 | |
titleStack.setPadding(2, 5, 2, 5) | |
titleStack.backgroundColor = new Color("#000", 0.2) | |
let wtitle = titleStack.addText("Animals of the Day") | |
wtitle.font = Font.semiboldRoundedSystemFont(14) | |
wtitle.textColor = Color.white() | |
w.addSpacer(4) | |
let row = w.addStack() | |
addAnimal( | |
pandaImg, | |
"Panda", | |
"https://www.worldwildlife.org/species/giant-panda", | |
row) | |
row.addSpacer(20) | |
addAnimal( | |
slothImg, | |
"Sloth", | |
"https://www.worldwildlife.org/species/sloth", | |
row) | |
row.addSpacer(20) | |
addAnimal( | |
redPandaImg, | |
"Red Panda", | |
"https://www.worldwildlife.org/species/red-panda", | |
row) | |
w.presentLarge() | |
function addAnimal(img, name, link, r) { | |
let stack = r.addStack() | |
stack.layoutVertically() | |
stack.url = link | |
let wimg = stack.addImage(img) | |
wimg.cornerRadius = 4 | |
stack.addSpacer(4) | |
let wname = stack.addText(name) | |
wname.font = Font.semiboldRoundedSystemFont(14) | |
wname.textColor = Color.white() | |
stack.addSpacer(4) | |
} | |
async function getImage(url) { | |
let req = new Request(url) | |
return await req.loadImage() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment