xxxxxxxxxx
65
var carASpeed=100;
var carBSpeed=2;
var startingDist=37;
var gain=0;
var t=0;
var hrs=0;
var mins=0;
var carA; // Slider for carA Speed
var carAx=5; // Position of CarA
var carB; // Slider for carB Speed
var carBx; // Position of carB;
var d; // Slider for distance between cars
function setup() {
createCanvas(400, 400);
carBx=map(startingDist, 0, 100, 0, width);
carA=createSlider(0,100, 0, 1);
carA.style('transform',"rotate(-90deg)");
carA.position(-45,85);
carA.input(calcTime);
carB=createSlider(0,100, 0, 1);
carB.style('transform',"rotate(-90deg)");
carB.position(100,85);
carB.input(calcTime);
d=createSlider(0,100, 0, 0.5);
d.position(10, 250);
d.size(width-20, 10);
d.input(calcTime);
}
function draw() {
background('skyblue');
textSize(15);
text("CarA Speed: " + carA.value() + " mph", 10,180);
text("CarB Speed: " + carB.value() + " mph", 150,180);
text("Starting Distance: " + d.value()+" miles", 10, 225);
textSize(20);
if((hrs>0) && (hrs<Infinity))
{
text(hrs + " hours and " + mins + " minutes.", 10, 300);
}
// console.log(carA.value());
}
function calcTime()
{
carASpeed=carA.value();
carBSpeed=carB.value();
gain=carASpeed-carBSpeed;
startingDist=d.value();
t=startingDist/gain;
t=t*60;
hrs=floor(t/60);
mins=floor(t-(hrs*60));
//console.log(hrs + " hours and " + mins + " minutes.");
}