-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunciones.js
More file actions
51 lines (41 loc) · 1.31 KB
/
Copy pathfunciones.js
File metadata and controls
51 lines (41 loc) · 1.31 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
import { ajustes } from "./ajustes.js";
export function numberoAleatorioEntre(min, max) {
const minCeiled = Math.ceil(min);
const maxFloored = Math.floor(max);
return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled);
}
export function letraAleatoria(desplazamiento) {
return String.fromCharCode(desplazamiento + Math.floor(Math.random() * 26));
}
export function generarNombre() {
const primeraLetra = letraAleatoria(65);
const segundaLetra = letraAleatoria(97);
const terceraLetra = letraAleatoria(97);
return primeraLetra + segundaLetra + terceraLetra;
}
export function calcularDistancia(lugarA, lugarB) {
const dx = lugarB.x - lugarA.x;
const dy = lugarB.y - lugarA.y;
return Math.sqrt(dx * dx + dy * dy);
}
export function obtenerLugar(x, y, lugares) {
for (const lugar of lugares) {
const distancia = Math.sqrt(
Math.pow(x - lugar.x, 2) + Math.pow(y - lugar.y, 2)
);
if (distancia <= ajustes.tamanoDibujo) {
return lugar;
}
}
return null;
}
export function indiceAleatorio(coleccion) {
return Math.floor(Math.random() * coleccion.length);
}
export function elementoAleatorio(coleccion) {
return coleccion[indiceAleatorio(coleccion)];
}
export function umbral(porcentaje) {
return Math.random() < porcentaje;
}
export const log = console.log;