@ -22,10 +22,9 @@ class WindSimulation {
constructor ( width , height , mills ) {
constructor ( width , height , mills ) {
this . width = width ;
this . width = width ;
this . height = height ;
this . height = height ;
this . mills = mills ;
this . wms = [ ] ;
this . wms = [ ] ;
this . init _windmills ( ) ;
this . init _windmills ( mills ) ;
this . wm = null ;
this . wm = null ;
this . simulation = null ;
this . simulation = null ;
@ -63,19 +62,16 @@ class WindSimulation {
scene . add ( this . flag ) ;
scene . add ( this . flag ) ;
}
}
init _windmills ( ) {
init _windmills ( mills ) {
if ( ! WindMill . isReady ( ) ) {
if ( ! WindMill . isReady ( ) ) {
setTimeout ( ( ) => { this . init _windmills ( ) } , 100 ) ;
setTimeout ( ( ) => { this . init _windmills ( mills ) } , 100 ) ;
return ;
return ;
}
}
for ( var i = 0 ; i < this . mills ; i ++ ) {
var wm = new WindMill ( ) ;
for ( var i = 0 ; i < mills ; i ++ )
wm . position . set ( 4 + 0.5 , i + 5 - Math . ceil ( this . mills / 2 ) + 0.5 , 0 ) ;
this . addWindMill ( ) ;
wm . rotation . z = this . targetRotation ;
scene . add ( wm ) ;
this . wm = null ;
this . wms . push ( wm ) ;
}
this . wm = this . wms [ 0 ] ;
}
}
move ( pos , ended = false , count = 2 ) {
move ( pos , ended = false , count = 2 ) {
@ -180,7 +176,7 @@ class WindSimulation {
this . simulation = null ;
this . simulation = null ;
this . simulationPots = null ;
this . simulationPots = null ;
this . simulationPot = 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 ) ;
this . wms [ i ] . lowPower ( false ) ;
document . getElementById ( "follower" ) . style . display = "none" ;
document . getElementById ( "follower" ) . style . display = "none" ;
document . getElementById ( "results" ) . style . display = "none" ;
document . getElementById ( "results" ) . style . display = "none" ;
@ -202,28 +198,35 @@ class WindSimulation {
this . targetRotation = rotations [ dir ] ;
this . targetRotation = rotations [ dir ] ;
}
}
addWindMill( ) {
positionValid( pos ) {
if( this . mills >= 10 ) return ;
for( let i = 0 ; i < this . wms . length ; i ++ )
if ( pos . clone ( ) . sub ( this . wms [ i ] . position ) . length ( ) < 1 )
this . mills ++ ;
return false ;
this. reset ( ) ;
return true ;
}
}
removeWindMill ( ) {
addWindMill ( ) {
if ( this . mills <= 1 ) return ;
if ( this . wms . length >= 10 ) return ;
this . mills -- ;
for ( let x = 0 ; x < 5 ; x ++ )
this . reset ( ) ;
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 ( ) {
removeWindMill ( ) {
for ( var i = 0 ; i < this . wms . length ; i ++ )
if ( this . wms . length <= 1 ) return ;
scene . remove ( this . wms [ i ] ) ;
this . wms = [ ] ;
this . rotation = this . targetRotation ;
this . init _windmills ( ) ;
if ( this . wms [ this . wms . length - 1 ] == this . wm ) this . wm = null ;
scene . remove ( this . wms . pop ( ) ) ;
}
}
simulate ( ) {
simulate ( ) {
@ -310,15 +313,15 @@ class WindSimulation {
var results = document . getElementById ( "results" )
var results = document . getElementById ( "results" )
var innerHTML = '<h3>Resultados de la simulación</h3>' + ( pasa ?
var innerHTML = '<h3>Resultados de la simulación</h3>' + ( pasa ?
'<p style="max-width: 16em"> 🥳🥳🥳 ¡Tu simulación <b>está bien</b>! ¿Probaste otros vientos? Si sí agregá más aerogeneradore s.</p>' :
'<p style="max-width: 16em"> ' + PARTY + PARTY + PARTY + ' ¡Tu simulación <b>está bien</b> con este viento! Clickeá "¡validar!" para evaluar en los demá s.</p>' :
'<p style="max-width: 16em"> ⚠️⚠️⚠️ ¡Tu simulación <b>no</b> funciona! Probá otras configuraciones.</p>') + '<table>' ;
'<p style="max-width: 16em"> ' + EXCLAMATION + EXCLAMATION + EXCLAMATION + ' ¡Tu simulación <b>no</b> funciona! Probá otras configuraciones.</p>') + '<table>' ;
for ( let i = 0 ; i < pot . length ; i ++ ) {
for ( let i = 0 ; i < pot . length ; i ++ ) {
var perc = Math . round ( pot [ i ] / 14.95 * 100 ) ;
var perc = Math . round ( pot [ i ] / 14.95 * 100 ) ;
innerHTML += '<tr><td><b>Nº' + ( i + 1 ) + ':</b></td><td>' + Math . round ( pot [ i ] * 100 ) / 100 + ' GWh</td><td>' + this . divPercentBar ( perc , 50 ) + ' ' + perc + '% ' + ( perc < 50 ? '⚠️' : '' ) + '</td></tr>'
innerHTML += '<tr><td><b>Nº' + ( i + 1 ) + ':</b></td><td>' + Math . round ( pot [ i ] * 100 ) / 100 + ' GWh</td><td>' + this . divPercentBar ( perc , 50 ) + ' ' + perc + '% ' + ( perc < 50 ? EXCLAMATION : '' ) + '</td></tr>'
}
}
var perc = Math . round ( sum / 14.95 / pot . length * 100 ) ;
var perc = Math . round ( sum / 14.95 / pot . length * 100 ) ;
innerHTML += '<tr class="last"><td>TOTAL:</td><td>' + Math . round ( sum * 100 ) / 100 + ' GWh</td><td>' + this . divPercentBar ( perc , 80 ) + ' ' + perc + '% ' + ( perc < 80 ? '⚠️' : '' ) + '</td></tr></table>' ;
innerHTML += '<tr class="last"><td>TOTAL:</td><td>' + Math . round ( sum * 100 ) / 100 + ' GWh</td><td>' + this . divPercentBar ( perc , 80 ) + ' ' + perc + '% ' + ( perc < 80 ? EXCLAMATION : '' ) + '</td></tr></table>' ;
results . innerHTML = innerHTML ;
results . innerHTML = innerHTML ;
results . style . display = "block" ;
results . style . display = "block" ;
@ -395,16 +398,6 @@ window.light = light;
//scene.add( helper);
//scene.add( helper);
//window.helper = helper;
//window.helper = helper;
window . windmill = WindMill ;
window . ws = ws ;
window . ws = ws ;
window . screen = screen ;
window . screen = screen ;
window . scene = scene ;
window . scene = scene ;