Last active
September 30, 2020 17:06
-
-
Save fcrespo82/fd408761ab794432c78bff42b6678418 to your computer and use it in GitHub Desktop.
Dice roller in widget for Scriptable iOS app
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: 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