Colors, exclude origin when choosing destination

This commit is contained in:
Tyler Hallada 2018-04-09 23:56:04 -04:00
parent 35e3f8f3a3
commit e686a854d8
3 changed files with 10 additions and 4 deletions

View File

@ -40,7 +40,7 @@ export default class Station {
stationCount += 1;
this.id = stationCount;
this.label = new PIXI.Text(`${this.id}`, {
fill: 'orange',
fill: '#FFA500',
fontFamily: 'monospace',
fontSize: '12px',
});

View File

@ -23,7 +23,7 @@ export default class Train {
trainCount += 1;
this.id = trainCount;
this.label = new PIXI.Text(`${this.id}`, {
fill: 'white',
fill: '#AEAEAE',
fontFamily: 'monospace',
fontSize: '12px',
});

View File

@ -70,7 +70,9 @@ const moveTrains = (trains: Train[], stations: Station[]) => {
for (const train of trains) {
// choose a destination randomly with a bias towards larger stations
if (train.destination === undefined) {
const closeStations = Station.stationsWithinRadius(stations, train.location, MAX_JOURNEY);
const otherStations = stations.filter(station => station !== train.origin);
const closeStations = Station.stationsWithinRadius(otherStations, train.location,
MAX_JOURNEY);
const closeStationWeights = closeStations.map(station => station.population);
train.destination = weightedRandom(closeStations, closeStationWeights);
}
@ -140,10 +142,14 @@ const run = () => {
graphics.clear();
fpsText.text = `${Math.round(ticker.FPS)}`;
graphics.lineStyle(1, 0xaeaeae, 1);
graphics.lineStyle(1, 0xFFA500, 1);
drawStations(stations, graphics);
graphics.lineStyle(1, 0xAEAEAE, 1);
drawTrains(trains, graphics);
// TODO: ?
// drawLine(line, graphics);
});
ticker.start();