Colors, exclude origin when choosing destination
This commit is contained in:
parent
35e3f8f3a3
commit
e686a854d8
@ -40,7 +40,7 @@ export default class Station {
|
|||||||
stationCount += 1;
|
stationCount += 1;
|
||||||
this.id = stationCount;
|
this.id = stationCount;
|
||||||
this.label = new PIXI.Text(`${this.id}`, {
|
this.label = new PIXI.Text(`${this.id}`, {
|
||||||
fill: 'orange',
|
fill: '#FFA500',
|
||||||
fontFamily: 'monospace',
|
fontFamily: 'monospace',
|
||||||
fontSize: '12px',
|
fontSize: '12px',
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,7 @@ export default class Train {
|
|||||||
trainCount += 1;
|
trainCount += 1;
|
||||||
this.id = trainCount;
|
this.id = trainCount;
|
||||||
this.label = new PIXI.Text(`${this.id}`, {
|
this.label = new PIXI.Text(`${this.id}`, {
|
||||||
fill: 'white',
|
fill: '#AEAEAE',
|
||||||
fontFamily: 'monospace',
|
fontFamily: 'monospace',
|
||||||
fontSize: '12px',
|
fontSize: '12px',
|
||||||
});
|
});
|
||||||
|
@ -70,7 +70,9 @@ const moveTrains = (trains: Train[], stations: Station[]) => {
|
|||||||
for (const train of trains) {
|
for (const train of trains) {
|
||||||
// choose a destination randomly with a bias towards larger stations
|
// choose a destination randomly with a bias towards larger stations
|
||||||
if (train.destination === undefined) {
|
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);
|
const closeStationWeights = closeStations.map(station => station.population);
|
||||||
train.destination = weightedRandom(closeStations, closeStationWeights);
|
train.destination = weightedRandom(closeStations, closeStationWeights);
|
||||||
}
|
}
|
||||||
@ -140,10 +142,14 @@ const run = () => {
|
|||||||
|
|
||||||
graphics.clear();
|
graphics.clear();
|
||||||
fpsText.text = `${Math.round(ticker.FPS)}`;
|
fpsText.text = `${Math.round(ticker.FPS)}`;
|
||||||
graphics.lineStyle(1, 0xaeaeae, 1);
|
|
||||||
|
|
||||||
|
graphics.lineStyle(1, 0xFFA500, 1);
|
||||||
drawStations(stations, graphics);
|
drawStations(stations, graphics);
|
||||||
|
|
||||||
|
graphics.lineStyle(1, 0xAEAEAE, 1);
|
||||||
drawTrains(trains, graphics);
|
drawTrains(trains, graphics);
|
||||||
|
|
||||||
|
// TODO: ?
|
||||||
// drawLine(line, graphics);
|
// drawLine(line, graphics);
|
||||||
});
|
});
|
||||||
ticker.start();
|
ticker.start();
|
||||||
|
Loading…
Reference in New Issue
Block a user