Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html><head><base href="https://diceroller.fun/" />
- <title>DiceRoller.fun - ASCII Dice Simulator</title>
- <style>
- body {
- font-family: 'Roboto', sans-serif;
- background-color: #f0f0f0;
- margin: 0;
- padding: 0;
- display: flex;
- justify-content: center;
- align-items: center;
- min-height: 100vh;
- }
- .container {
- background-color: #ffffff;
- border-radius: 10px;
- box-shadow: 0 0 20px rgba(0,0,0,0.1);
- padding: 30px;
- text-align: center;
- max-width: 400px;
- width: 100%;
- }
- h1 {
- color: #4a4a4a;
- margin-bottom: 20px;
- }
- .controls {
- display: flex;
- justify-content: center;
- gap: 10px;
- margin-bottom: 20px;
- }
- button {
- background-color: #4CAF50;
- border: none;
- color: white;
- padding: 10px 20px;
- text-align: center;
- text-decoration: none;
- display: inline-block;
- font-size: 16px;
- margin: 4px 2px;
- cursor: pointer;
- border-radius: 5px;
- transition: background-color 0.3s;
- }
- button:hover {
- background-color: #45a049;
- }
- select {
- padding: 10px;
- font-size: 16px;
- border-radius: 5px;
- border: 1px solid #ddd;
- }
- .result {
- font-size: 24px;
- font-weight: bold;
- color: #4a4a4a;
- margin-top: 20px;
- }
- .dice-ascii {
- font-family: monospace;
- font-size: 14px;
- white-space: pre;
- line-height: 1;
- margin-top: 20px;
- text-align: center;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>DiceRoller.fun</h1>
- <div class="controls">
- <select id="dice-type">
- <option value="d4">D4</option>
- <option value="d6" selected>D6</option>
- <option value="d8">D8</option>
- <option value="d10">D10</option>
- <option value="d12">D12</option>
- <option value="d20">D20</option>
- </select>
- <button id="roll-button">Roll Dice</button>
- </div>
- <div class="result" id="result"></div>
- <div class="dice-ascii" id="dice-ascii"></div>
- </div>
- <script>
- const diceTypeSelect = document.getElementById('dice-type');
- const rollButton = document.getElementById('roll-button');
- const resultElement = document.getElementById('result');
- const diceAsciiElement = document.getElementById('dice-ascii');
- const diceTypes = {
- d4: { sides: 4 },
- d6: { sides: 6 },
- d8: { sides: 8 },
- d10: { sides: 10 },
- d12: { sides: 12 },
- d20: { sides: 20 }
- };
- const diceAscii = {
- 1: `
- +-------+
- | |
- | • |
- | |
- +-------+`,
- 2: `
- +-------+
- | • |
- | |
- | • |
- +-------+`,
- 3: `
- +-------+
- | • |
- | • |
- | • |
- +-------+`,
- 4: `
- +-------+
- | • • |
- | |
- | • • |
- +-------+`,
- 5: `
- +-------+
- | • • |
- | • |
- | • • |
- +-------+`,
- 6: `
- +-------+
- | • • |
- | • • |
- | • • |
- +-------+`,
- 7: `
- +-------+
- | • • • |
- | • • |
- | • • • |
- +-------+`,
- 8: `
- +-------+
- | • • • |
- | • • • |
- | • • • |
- +-------+`,
- 9: `
- +-------+
- | • • • |
- | • • • |
- | • • • |
- | • • |
- +-------+`,
- 10: `
- +-------+
- | • • • |
- | • • • |
- | • • • |
- | • • • |
- +-------+`,
- };
- function getAsciiNumber(num) {
- if (num <= 10) {
- return diceAscii[num];
- } else {
- return `
- +-------+
- | ${num.toString().padStart(2, ' ')} |
- | |
- | |
- +-------+`;
- }
- }
- function rollDice() {
- const selectedDice = diceTypeSelect.value;
- const { sides } = diceTypes[selectedDice];
- const result = Math.floor(Math.random() * sides) + 1;
- resultElement.textContent = `You rolled a ${selectedDice} and got:`;
- diceAsciiElement.textContent = getAsciiNumber(result);
- }
- rollButton.addEventListener('click', rollDice);
- // Initial roll
- rollDice();
- </script>
- </body></html>
Advertisement
Add Comment
Please, Sign In to add comment