function keyPressed() {
  // Spacebar pressed
  if (keyCode === 32) {
    // Updates configuration
    Object.keys(INPUTS).map(function(key, i) {
      CONFIG[key] = Number(INPUTS[key].value());
    });
    
    createMovers();
  }
  
  // 'P' key pressed
  if (keyCode === 80) {
    let mass = random(CONFIG.planetMinMass, CONFIG.planetMaxMass);
    let p = new Mover(mouseX, mouseY, mass, mass * 20);
    movers.push(p);
  }
  
  // 'R' key pressed
  if (keyCode === 82) {
    for (var i = 0; i < movers.length; i++) {
      movers[i].velocity.mult(0);
    }
  }
  
  // 'S' key pressed
  if (keyCode === 83) {
    let mass = random(CONFIG.starMinMass, CONFIG.starMaxMass);
    let s = new Mover(mouseX, mouseY, mass, mass * 2);
    movers.push(s);
  }
  
  // 'V' key pressed
  if (keyCode === 86) {
    visible = !visible;
    
    if (visible === true) {
      Object.keys(INPUTS).map(function(key, i) {
        INPUTS[key].show();
      })
      Object.keys(TEXT).map(function(key, i) {
        TEXT[key].show();
      })
    } else {
      Object.keys(INPUTS).map(function(key, i) {
        INPUTS[key].hide();
      })
      Object.keys(TEXT).map(function(key, i) {
        TEXT[key].hide();
      })
    }
  }
  
  // 'X' key pressed
  if (keyCode === 88) {
    // Updates configuration
    Object.keys(INPUTS).map(function(key, i) {
      CONFIG[key] = Number(INPUTS[key].value());
    });
  }
}
// Press the 'X' key to update configuration
Press the 'X' key to update configuration
Press the ' X ' key to update configuration
function keyPressed() {
  if (keyCode === 32) {
    Object.keys(INPUTS).map(function(key, i) {
      CONFIG[key] = Number(INPUTS[key].value());
    });
    createMovers();
  }
  if (keyCode === 80) {
    let mass = random(CONFIG.planetMinMass, CONFIG.planetMaxMass);
    let p = new Mover(mouseX, mouseY, mass, mass * 20);
    movers.push(p);
  }
  if (keyCode === 82) {
    for (var i = 0; i < movers.length; i++) {
      movers[i].velocity.mult(0);
    }
  }
  if (keyCode === 83) {
    let mass = random(CONFIG.starMinMass, CONFIG.starMaxMass);
    let s = new Mover(mouseX, mouseY, mass, mass * 2);
    movers.push(s);
  }
  if (keyCode === 86) {
    visible = !visible;
    if (visible === true) {
      Object.keys(INPUTS).map(function(key, i) {
        INPUTS[key].show();
      })
      Object.keys(TEXT).map(function(key, i) {
        TEXT[key].show();
      })
    } else {
      Object.keys(INPUTS).map(function(key, i) {
        INPUTS[key].hide();
      })
      Object.keys(TEXT).map(function(key, i) {
        TEXT[key].hide();
      })
    }
  }
  if (keyCode === 88) {
    Object.keys(INPUTS).map(function(key, i) {
      CONFIG[key] = Number(INPUTS[key].value());
    });
  }
}
function keyPressed ( ) { if ( keyCode === 32 ) { Object . keys ( INPUTS ) . map ( function ( key , i ) { CONFIG [ key ] = Number ( INPUTS [ key ] . value ( ) ) ; } ) ; createMovers ( ) ; } if ( keyCode === 80 ) { let mass = random ( CONFIG . planetMinMass , CONFIG . planetMaxMass ) ; let p = new Mover ( mouseX , mouseY , mass , mass * 20 ) ; movers . push ( p ) ; } if ( keyCode === 82 ) { for ( var i = 0 ; i < movers . length ; i ++ ) { movers [ i ] . velocity . mult ( 0 ) ; } } if ( keyCode === 83 ) { let mass = random ( CONFIG . starMinMass , CONFIG . starMaxMass ) ; let s = new Mover ( mouseX , mouseY , mass , mass * 2 ) ; movers . push ( s ) ; } if ( keyCode === 86 ) { visible = ! visible ; if ( visible === true ) { Object . keys ( INPUTS ) . map ( function ( key , i ) { INPUTS [ key ] . show ( ) ; } ) Object . keys ( TEXT ) . map ( function ( key , i ) { TEXT [ key ] . show ( ) ; } ) } else { Object . keys ( INPUTS ) . map ( function ( key , i ) { INPUTS [ key ] . hide ( ) ; } ) Object . keys ( TEXT ) . map ( function ( key , i ) { TEXT [ key ] . hide ( ) ; } ) } } if ( keyCode === 88 ) { Object . keys ( INPUTS ) . map ( function ( key , i ) { CONFIG [ key ] = Number ( INPUTS [ key ] . value ( ) ) ; } ) ; } }
Press the 'X' key to update configuration
Press the ' X ' key to update configuration
// Spacebar pressed // Updates configuration // 'P' key pressed // 'R' key pressed // 'S' key pressed // 'V' key pressed // 'X' key pressed // Updates configuration