Skip to content

Instantly share code, notes, and snippets.

@perseoq
Created March 9, 2023 21:17
Show Gist options
  • Save perseoq/69fd7c87253005c111e962a044ed9382 to your computer and use it in GitHub Desktop.
Save perseoq/69fd7c87253005c111e962a044ed9382 to your computer and use it in GitHub Desktop.
Cambia de tamaño una linea con Javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<canvas id="myCanvas"></canvas>
<input type="number" id="lineLength" min="0" max="50000" value="1">
<script>
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
function drawLine(length) {
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(length, 0);
ctx.stroke();
}
const lineLengthInput = document.getElementById('lineLength');
lineLengthInput.addEventListener('input', () => {
const length = lineLengthInput.value;
drawLine(length);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment