-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
102 lines (77 loc) · 2.58 KB
/
index.html
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DibujarCuadrado, Parámetro rest</title>
</head>
<body>
<canvas width="600" height="400"></canvas>
<script>
function consola(params) {
console.log(params);
}
//function para capturar elemento canvas
function contextCanvas(selectorHtml) {
let pantalla = document.querySelector(selectorHtml);
let pincel = pantalla.getContext("2d");
return pincel;
}
//function para validar color css
function isColor(strColor) {
let isColor;
if (strColor !== "") {
let s = new Option().style;
s.color = strColor;
isColor = s.color == strColor;
} else {
isColor = false;
}
return isColor;
}
//function para dibujarContornos
function dibujarContorno(x, y, ...c) {
if (c.length == 4) {
let pincel = c[3], color = c[0], width = c[1], height = c[2];
//valores por defecto en caso de que no vengan correctamente
if ((isColor(c[0]) != false) || (color = "black"));
if ((c[1] >= 0) || (width = 600));
if ((c[2] >= 0) || (height = 400));
//cuadrado contorno
pincel.strokeStyle = color;
pincel.strokeRect(x, y, width, height);//border cuadrado 1
} else {
console.error("faltan parámetros")
}
}
//function para dibujar Cuadrado
function dibujarCuadrado(x, y, ...c) {
if (c.length == 4) {
let pincel = c[3], color = c[0], width = c[1], height = c[2];
//valores por defecto en caso de que no vengan correctamente
if ((isColor(c[0]) != false) || (color = "green"));
if ((c[1] != 0) || (width = 600));
if ((c[2] != 0) || (height = 400));
//cuadrado
pincel.fillStyle = color;
pincel.fillRect(x, y, width, height);//cuadrado 1
} else {
console.error("faltan parámetros")
}
}
consola("Dibujar Cuadrado v.1.0");
//contexto contexto canvas
let pizarra = contextCanvas("canvas"); //esta function espera un tagHtml, en este caso es el elemento canvas
let x = 0;
while (x < 600) {
dibujarCuadrado(x, 0, "yellow", 50, 50, pizarra);
dibujarContorno(x, 0, "black", 50, 50, pizarra);
dibujarCuadrado(x, 50, "blue", 50, 50, pizarra);
dibujarContorno(x, 50, "black", 50, 50, pizarra);
dibujarCuadrado(x, 100, "red", 50, 50, pizarra);
dibujarContorno(x, 100, "black", 50, 50, pizarra);
x += 50;
}
</script>
</body>
</html>