|
| 1 | +<html> |
| 2 | + <head> |
| 3 | + <meta charset="UTF-8"> |
| 4 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 5 | + <title></title> |
| 6 | + </head> |
| 7 | + |
| 8 | + <body> |
| 9 | + |
| 10 | +<pre id="easycoder-script" style="display:none">! |
| 11 | + |
| 12 | +! Twin dice roller |
| 13 | + |
| 14 | + script DiceRoller |
| 15 | + |
| 16 | + div Screen |
| 17 | + div Dice |
| 18 | + div Dot |
| 19 | + variable NDice |
| 20 | + variable M |
| 21 | + variable N |
| 22 | + variable D |
| 23 | + variable Index |
| 24 | + variable Row |
| 25 | + variable Dots |
| 26 | + variable Patterns |
| 27 | + variable Left |
| 28 | + variable Top |
| 29 | + |
| 30 | + put 2 into NDice |
| 31 | + set style `.ec-dice` to `{width:100px;height:100px;margin:20px;` |
| 32 | + cat `background:yellow;border:1px solid black;display:inline-block;` |
| 33 | + cat `position:relative}` |
| 34 | + set style `.ec-dot` to `{width:20px;height:20;position:absolute;` |
| 35 | + cat `background:black;border-radius:10px}` |
| 36 | + |
| 37 | + set Patterns to |
| 38 | + 40 40 0 0 0 0 0 0 0 0 0 0 |
| 39 | + 10 40 70 40 0 0 0 0 0 0 0 0 |
| 40 | + 10 40 40 40 70 40 0 0 0 0 0 0 |
| 41 | + 10 10 70 10 10 70 70 70 0 0 0 0 |
| 42 | + 10 10 70 10 10 70 70 70 40 40 0 0 |
| 43 | + 10 10 10 70 40 10 40 70 70 10 70 70 |
| 44 | + |
| 45 | + create Screen |
| 46 | + set the style of Screen to `padding:1em` |
| 47 | + set the elements of Dice to NDice |
| 48 | + |
| 49 | +Redraw: |
| 50 | + put 0 into M |
| 51 | + while M is less than 10 |
| 52 | + begin |
| 53 | + put 0 into N |
| 54 | + while N is less than NDice |
| 55 | + begin |
| 56 | + index Dice to N |
| 57 | + remove element Dice |
| 58 | + create Dice in Screen |
| 59 | + set the class of Dice to `ec-dice` |
| 60 | + gosub to RandomiseDots |
| 61 | + add 1 to N |
| 62 | + end |
| 63 | + wait 10 ticks |
| 64 | + add 1 to M |
| 65 | + end |
| 66 | + on click Dice go to Redraw |
| 67 | + stop |
| 68 | + |
| 69 | +RandomiseDots: |
| 70 | + put random 6 into Dots |
| 71 | + multiply Dots by 12 giving Row |
| 72 | + put 0 into D |
| 73 | + while D is less than 12 |
| 74 | + begin |
| 75 | + add D to Row giving Index |
| 76 | + index Patterns to Index |
| 77 | + put Patterns into Top |
| 78 | + add 1 to D |
| 79 | + if Top is not 0 |
| 80 | + begin |
| 81 | + add 1 to Index |
| 82 | + index Patterns to Index |
| 83 | + put Patterns into Left |
| 84 | + create Dot in Dice |
| 85 | + set the class of Dot to `ec-dot` |
| 86 | + set style `top` of Dot to Top |
| 87 | + set style `left` of Dot to Left |
| 88 | + on click Dot go to Redraw |
| 89 | + end |
| 90 | + add 1 to D |
| 91 | + end |
| 92 | + return |
| 93 | +</pre> |
| 94 | + |
| 95 | + <script type='text/javascript' src='https://cdn.jsdelivr.net/gh/easycoder/easycoder.github.io/dist/easycoder.js?v=200413'></script> |
| 96 | + |
| 97 | + </body> |
| 98 | +</html> |
0 commit comments