Created
November 20, 2020 20:43
-
-
Save tmsanchez/06c36b6c6c5139236da580642876d24d to your computer and use it in GitHub Desktop.
Draw a text in random coordinates on a Canvas
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script> | |
function drawWords() { | |
const ctx = document.getElementById('drawArea').getContext('2d'); | |
ctx.font = '12px serif'; | |
const x = Math.floor(Math.random() * 300); | |
const y = Math.floor(Math.random() * 300); | |
ctx.fillText('Some Text', x, y); | |
} | |
</script> | |
</head> | |
<body> | |
<h2>Drawing words in a canvas</h2> | |
<p id="demo">Presss button to draw a text.</p> | |
<button type="button" onclick="drawWords()">Dibuja</button> | |
<canvas id="drawArea" width="300" height="300"> | |
</canvas> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment