-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
71 lines (60 loc) · 1.98 KB
/
index.html
File metadata and controls
71 lines (60 loc) · 1.98 KB
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
<html>
<head>
<title>Ringa Tech - Red neuronal</title>
<style type="text/css">
#sitio {
padding: 5rem;
font-size: 5rem;
margin-left: 15rem;
}
</style>
</head>
<body>
<input data-jscolor="{value:'#CC66FF'}", onInput="update(this.jscolor)">
<div id="sitio">
Mi sitio web
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jscolor/2.4.5/jscolor.min.js"></script>
<script src="https://unpkg.com/brain.js"></script>
<script type="text/javascript">
//Inicio red neuronal
var network = new brain.NeuralNetwork();
//Entrenarla, darle ejemplos de cuando poner el tipo de texto blanco, o texto negro segun el fondo requerido
network.train([
//Fondo negro (entrada en 0s) = texto blanco (salida = 1)
{input: {rojo: 0, verde: 0, azul: 0}, output: {color: 1}},
//Fondo blanco (entrada en 1s) = texto negro (salida = 0)
{input: {rojo: 1, verde: 1, azul: 1}, output: {color: 0}},
//Fondo verde, texto negro
{input: {rojo: 0, verde: 1, azul: 0}, output: {color: 0}},
//Fondo azul, texto blanco
{input: {rojo: 0, verde: .43, azul: 1}, output: {color: 1}},
//Fondo rojo, texto blanco
{input: {rojo: 1, verde: 0, azul: 0}, output: {color: 1}},
]);
function update(color) {
//Hacemos el objeto "rgb"
var rgb = [color.channels.r, color.channels.g, color.channels.b];
//console.log(rgb);
var div = document.getElementById("sitio");
div.style.background = color.toHEXString();
//Tomar el fondo actual elegido por el usuario,
//para usarlo de entrada para que la red nos de su prediccion del mejor color de texto a utilizar
var entrada = {
rojo: rgb[0]/255,
verde: rgb[1]/255,
azul: rgb[2]/255,
};
//Obtener la prediccion de la red
var resultado = network.run(entrada);
//console.log(resultado);
//Si resultado > .5, se considera color de texto blanco
if (resultado.color > .5) {
div.style.color = "white";
} else {
div.style.color = "black";
}
}
</script>
</body>
</html>