diff --git a/js/main.js b/js/main.js index e91c30e..c5c5f7b 100644 --- a/js/main.js +++ b/js/main.js @@ -22,10 +22,9 @@ class WindSimulation { constructor(width, height, mills) { this.width = width; this.height = height; - this.mills = mills; this.wms = []; - this.init_windmills(); + this.init_windmills(mills); this.wm = null; this.simulation = null; @@ -63,19 +62,16 @@ class WindSimulation { scene.add(this.flag); } - init_windmills() { + init_windmills(mills) { if(!WindMill.isReady()) { - setTimeout(() => { this.init_windmills() }, 100); + setTimeout(() => { this.init_windmills(mills) }, 100); return; } - for(var i = 0; i < this.mills; i++) { - var wm = new WindMill(); - wm.position.set(4 + 0.5, i + 5 - Math.ceil(this.mills / 2) + 0.5, 0); - wm.rotation.z = this.targetRotation; - scene.add(wm); - this.wms.push(wm); - } - this.wm = this.wms[0]; + + for(var i = 0; i < mills; i++) + this.addWindMill(); + + this.wm = null; } move(pos, ended=false, count=2) { @@ -180,7 +176,7 @@ class WindSimulation { this.simulation = null; this.simulationPots = null; this.simulationPot = null; - for(var i = 0; i < this.mills; i++) + for(var i = 0; i < this.wms.length; i++) this.wms[i].lowPower(false); document.getElementById("follower").style.display = "none"; document.getElementById("results").style.display = "none"; @@ -202,28 +198,35 @@ class WindSimulation { this.targetRotation = rotations[dir]; } - addWindMill() { - if(this.mills >= 10) return; - - this.mills++; - this.reset(); + positionValid(pos) { + for(let i = 0; i < this.wms.length; i++) + if(pos.clone().sub(this.wms[i].position).length() < 1) + return false; + return true; } - removeWindMill() { - if(this.mills <= 1) return; - - this.mills--; - this.reset(); + addWindMill() { + if(this.wms.length >= 10) return; + + for(let x = 0; x < 5; x++) + for(let y = 0; y < 10; y++) { + var pos = new THREE.Vector3(4.5 + Math.ceil(x / 2) * (x % 2 ? 1 : -1), 4.5 + Math.ceil(y / 2) * (y % 2 ? 1 : -1), 0); + if(this.positionValid(pos)) { + var wm = new WindMill(); + wm.position.set(pos.x, pos.y, 0); + wm.rotation.z = this.targetRotation; + scene.add(wm); + this.wms.push(wm); + return; + } + } } - reset() { - for(var i = 0; i < this.wms.length; i++) - scene.remove(this.wms[i]); - - this.wms = []; - this.rotation = this.targetRotation; + removeWindMill() { + if(this.wms.length <= 1) return; - this.init_windmills(); + if(this.wms[this.wms.length - 1] == this.wm) this.wm = null; + scene.remove(this.wms.pop()); } simulate() { @@ -310,15 +313,15 @@ class WindSimulation { var results = document.getElementById("results") var innerHTML = '

Resultados de la simulación

' + (pasa ? - '

🥳🥳🥳 ¡Tu simulación está bien! ¿Probaste otros vientos? Si sí agregá más aerogeneradores.

' : - '

⚠️⚠️⚠️ ¡Tu simulación no funciona! Probá otras configuraciones.

') + ''; + '

' + PARTY + PARTY + PARTY + ' ¡Tu simulación está bien con este viento! Clickeá "¡validar!" para evaluar en los demás.

' : + '

' + EXCLAMATION + EXCLAMATION + EXCLAMATION + ' ¡Tu simulación no funciona! Probá otras configuraciones.

') + '
'; for(let i = 0; i < pot.length; i++) { var perc = Math.round(pot[i] / 14.95 * 100); - innerHTML += '' + innerHTML += '' } var perc = Math.round(sum / 14.95 / pot.length * 100); - innerHTML += '
Nº' + (i + 1) + ':' + Math.round(pot[i] * 100) / 100 + ' GWh' + this.divPercentBar(perc, 50) + ' ' + perc + '% ' + (perc < 50 ? '⚠️' : '') + '
Nº' + (i + 1) + ':' + Math.round(pot[i] * 100) / 100 + ' GWh' + this.divPercentBar(perc, 50) + ' ' + perc + '% ' + (perc < 50 ? EXCLAMATION : '') + '
TOTAL:' + Math.round(sum * 100) / 100 + ' GWh' + this.divPercentBar(perc, 80) + ' ' + perc + '% ' + (perc < 80 ? '⚠️' : '') + '
'; + innerHTML += 'TOTAL:' + Math.round(sum * 100) / 100 + ' GWh' + this.divPercentBar(perc, 80) + ' ' + perc + '% ' + (perc < 80 ? EXCLAMATION : '') + ''; results.innerHTML = innerHTML; results.style.display = "block"; @@ -395,16 +398,6 @@ window.light = light; //scene.add( helper); //window.helper = helper; - - - - -window.windmill = WindMill; - - - - - window.ws = ws; window.screen = screen; window.scene = scene; diff --git a/style.css b/style.css index 11df8f3..60e83e4 100644 --- a/style.css +++ b/style.css @@ -36,7 +36,7 @@ h3, h4 { z-index: 1000; max-width: 70vw; max-height: 70vh; - overflow-x: hidden; + overflow-x: auto; overflow-y: auto; width: auto; border: solid #fff .5vh;