Skip to content

Instantly share code, notes, and snippets.

@fcrespo82
Last active September 30, 2020 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcrespo82/fd408761ab794432c78bff42b6678418 to your computer and use it in GitHub Desktop.
Save fcrespo82/fd408761ab794432c78bff42b6678418 to your computer and use it in GitHub Desktop.
Dice roller in widget for Scriptable iOS app
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-green; icon-glyph: dice;
let widget = new ListWidget()
widget.backgroundColor = Color.white()
let padding = 10
widget.setPadding(padding,padding,padding,padding)
let dot = "⚫️"
let n1 = "000,010,000"
let n2 = "001,000,100"
let n3 = "001,010,100"
let n4 = "101,000,101"
let n5 = "101,010,101"
let n6 = "101,101,101"
let numbers = [n1, n2, n3, n4, n5, n6]
function drawDice(input) {
let number = input.split(",").map(function(i){return i.split("")})
for (i in number) {
let stack = widget.addStack()
stack.layoutHorizontally()
for (j in number[i]) {
if (number[i][j] == "0") {
stack.addSpacer()
} else {
let text = stack.addText(dot)
text.font = Font.largeTitle()
}
}
if (i < number.length - 1) {
widget.addSpacer()
}
}
}
drawDice(numbers[Math.floor(Math.random() * 6)])
widget.presentSmall()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment