-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
54 lines (45 loc) · 1.47 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Obtener el canvas y su contexto
const canvas = document.getElementById("artCanvas");
const ctx = canvas.getContext("2d");
// Configurar el tamaño del canvas
canvas.width = window.innerWidth * 0.9;
canvas.height = window.innerHeight * 0.8;
// Funcion para generar un color aleatorio
function getRandomColor() {
const r = Math.floor(Math.random() * 256);
const g = Math.floor(Math.random() * 256);
const b = Math.floor(Math.random() * 256);
return `rgb(${r}, ${g}, ${b})`;
}
// Funcion para dibujar un circulo
function drawCircle(x, y) {
const radius = Math.random() * 50 + 10; // Radio entre 10 y 60
const color = getRandomColor();
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();
ctx.strokeStyle = "#fff";
ctx.stroke();
}
// Funcion para dibujar una linea
function drawLine(x1, y1, x2, y2) {
const color = getRandomColor();
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.strokeStyle = color;
ctx.lineWidth = Math.random() * 5 + 1; // Grosor entre 1 y 10
ctx.stroke();
}
// Evento para dibujar al mover el mouse
canvas.addEventListener("click", (e) => {
const x = e.offsetX;
const y = e.offsetY;
// Dibujar un circulo mas grande al hacer clic
drawCircle(x, y);
});
// Limpiar el canvas cada 5 segundos
setInterval(() => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}, 5000);