xxxxxxxxxx
112
/*
Prachi Sadhwani
TTC Subway Delay Data
Using the slider will allow you see how the number of delays at each station changes with time.
The button toggles between displaying a visualization for Line 1 and Line 2
*/
let table, table2, total; //table variables for data
let slider, button; //variable for input objects
let factor = 3; //multiplier for sizing
let sound; // veriable for audio
//initializing p5.scribble by Janneck Wullschleger for circle drawings and animation
var scribble = new Scribble();
//loading the tables and sounds, all tables/csv files can be found in "data" folder
function preload() {
table = loadTable("/data/YU-delays-time.csv", "csv", "header");
table2 = loadTable("/data/BD-delays-time.csv", "csv", "header");
total = loadTable("/data/totalDelays.csv", "csv", "header");
soundFormats("mp3", "wav");
sound = loadSound("ttc.wav");
}
function setup() {
createCanvas(1000, 650);
textFont("Londrina Sketch"); //setting font to something sketchy
//looping and playing sound
sound.play();
sound.loop();
//button initialization
button = createButton("Line 2", "Line 1");
button.position(600, 550);
button.size(350, 50);
button.class("btn");
//slider initialization
slider = createSlider(1, 24, 0, 1);
slider.position(540, 100);
slider.class("time");
slider.size(450);
//changing value+text of buttons when it is pressed
button.mousePressed(() => {
if (button.value() == "Line 1") {
button.value("Line 2");
button.html("Line 1");
} else if (button.value() == "Line 2") {
button.value("Line 1");
button.html("Line 2");
}
});
//slowing down frame rate for better animation
frameRate(10);
}
function draw() {
background(234, 226, 214);
//getting total delay info for each line
let yuDelays = total.getColumn("YU");
let bdDelays = total.getColumn("BD");
let delayDisp;
//depending on the button's value, changing the data visualization display + text
if (button.value() == "Line 1") {
dataLine1(); //in Line-1.js
delayDisp = yuDelays;
} else if (button.value() == "Line 2") {
dataLine2(); //in Line-2.js
delayDisp = bdDelays;
}
//finding and displaying the time with the slider value
let curTime = slider.value() - 1;
if (curTime < 12) {
if (curTime == 0) {
curTime = "Midnight";
} else {
curTime = curTime + " am";
}
}
if (curTime > 12) {
curTime = curTime - 12;
curTime = curTime + " pm";
}
//adding other text
textSize(32);
textAlign(CENTER);
fill(0);
text("TTC Subway Delays", 775, 50);
text("Time of Day: " + curTime, 775, 175);
text("Total Delays: " + delayDisp[slider.value() - 1], 775, 250);
}
/*
Credits
sound - https://freesound.org/people/chungus43A/sounds/580790/
p5.scribble - Copyright (c) [2017] Janneck Wullschleger (portation of processing lib)
*/