Managed to cook up this for the Timer for HTML5 (below). Any chance to reset at 60:00?
var that = this;
this.initialMinutes = 46.4;// minutes here
this.totalTime = 0;
this.currentTime = 0;
this.interval = 0;
this.start = function()
{
that.startTimer(that.updateCallBack, that.endCallback);
};
this.updateCallBack = function()
{
that.setText();
};
this.startTimer = function(updateCallback, endCallback)
{
clearInterval(that.interval);
that.totalTime = that.minutesToMilliseconds(that.initialMinutes);
that.currentTime = that.totalTime;
that.setText();
that.setTime(updateCallback, endCallback);
};
this.setTime = function(updateCallback, endCallback)
{
that.interval = setInterval(function()
{
that.currentTime += 1000;
updateCallback();
if (that.currentTime == 60)
{
clearInterval(that.interval);
endCallback();
}
}, 100);//speed here
};
this.setText = function()
{
var time = that.timeCode(that.currentTime);
that.timeText.text = time.minutes + ":" + time.seconds;
};
this.minutesToMilliseconds = function(minutes)
{
return 1000 * 60 * minutes;
};
this.timeCode = function(milliseconds)
{
var seconds = Math.floor((milliseconds / 1000) % 60);
var strSeconds = (seconds < 10) ? ("0" + String(seconds)) : String(seconds);
var minutes = Math.round(Math.floor((milliseconds / 1000) / 60));
var strMinutes = (minutes < 10) ? ("0" + String(minutes)) : String(minutes);
return {seconds: strSeconds, minutes: strMinutes};
};
this.start();
The following codes are husky I'm sure, but they're currently working for HTML. All are based on the same fundamental code.
Code for Incremental Time starting whenever User chooses (Time):
var that = this;
this.initialMinutes = 46.4; // display here
this.totalTime = 0;
this.currentTime = 0;
this.interval = 0;
this.start = function()
{
that.startTimer(that.updateCallBack, that.endCallback);
};
this.updateCallBack = function()
{
that.setText();
};
this.startTimer = function(updateCallback, endCallback)
{
clearInterval(that.interval);
that.totalTime = that.minutesToMilliseconds(that.initialMinutes);
that.currentTime = that.totalTime;
that.setText();
that.setTime(updateCallback, endCallback);
};
this.setTime = function(updateCallback, endCallback)
{
that.interval = setInterval(function()
{
that.currentTime += 1000;
updateCallback();
if (that.currentTime == 60)
{
clearInterval(that.interval);
endCallback();
}
}, 1000); // rate of refresh here
};
this.setText = function()
{
var time = that.timeCode(that.currentTime);
that.timeText.text = time.minutes + ":" + time.seconds;
};
this.minutesToMilliseconds = function(minutes)
{
return 1000 * 60 * minutes;
};
this.timeCode = function(milliseconds)
{
var seconds = Math.floor((milliseconds / 1000) % 60);
var strSeconds = (seconds < 10) ? ("0" + String(seconds)) : String(seconds);
var minutes = Math.round(Math.floor((milliseconds / 1000) / 60));
var strMinutes = (minutes < 10) ? ("0" + String(minutes)) : String(minutes);
return {seconds: strSeconds, minutes: strMinutes};
};
this.start();
Code for Random Number (Heartrate):
var that = this;
this.initialMinutes = 10410; // display here
this.totalTime = 0;
this.currentTime = 0;
this.interval = 0;
this.start = function()
{
that.startTimer(that.updateCallBack, that.endCallback);
};
this.updateCallBack = function()
{
that.setText();
};
this.startTimer = function(updateCallback, endCallback)
{
clearInterval(that.interval);
that.totalTime = that.minutesToMilliseconds(that.initialMinutes);
that.currentTime = that.totalTime;
that.setText();
that.setTime(updateCallback, endCallback);
};
this.setTime = function(updateCallback, endCallback)
{
that.interval = setInterval(function()
{
that.currentTime += 1000;
updateCallback();
}, 5535); // rate of refresh here
};
this.setText = function()
{
var time = that.timeCode(that.currentTime);
that.timeText.text = time.minutes;
};
this.minutesToMilliseconds = function(minutes)
{
return 100 * 60 * minutes;
};
this.timeCode = function(milliseconds)
{
var seconds = Math.ceil(Math.random() * 5 + 130);
var minutes = Math.ceil(Math.random() * 5 + 130);
return {seconds, minutes};
};
this.start();
Code for Incremental Numbers (Calories):
var that = this;
this.initialMinutes = 10410; // display here
this.totalTime = 0;
this.currentTime = 0;
this.interval = 0;
this.start = function()
{
that.startTimer(that.updateCallBack, that.endCallback);
};
this.updateCallBack = function()
{
that.setText();
};
this.startTimer = function(updateCallback, endCallback)
{
clearInterval(that.interval);
that.totalTime = that.minutesToMilliseconds(that.initialMinutes);
that.currentTime = that.totalTime;
that.setText();
that.setTime(updateCallback, endCallback);
};
this.setTime = function(updateCallback, endCallback)
{
that.interval = setInterval(function()
{
that.currentTime += 1000;
updateCallback();
if (that.currentTime == 60)
{
clearInterval(that.interval);
endCallback();
}
}, 100); // rate of refresh here
};
this.setText = function()
{
var time = that.timeCode(that.currentTime);
that.timeText.text = time.minutes;
};
this.minutesToMilliseconds = function(minutes)
{
return 100 * 60 * minutes;
};
this.timeCode = function(milliseconds)
{
var seconds = Math.floor((milliseconds / 1000) % 60);
var strSeconds = (seconds < 10) ? ("0" + String(seconds)) : String(seconds);
var minutes = Math.round(Math.floor((milliseconds / 1000) / 60));
var strMinutes = (minutes < 10) ? ("0" + String(minutes)) : String(minutes);
return {seconds: strSeconds, minutes: strMinutes};
};
this.start();
Code for Incremental Numbers with Decimal (Miles):
var that = this;
this.initialMinutes = 61.3; // display here
this.totalTime = 0;
this.currentTime = 0;
this.interval = 0;
this.start = function()
{
that.startTimer(that.updateCallBack, that.endCallback);
};
this.updateCallBack = function()
{
that.setText();
};
this.startTimer = function(updateCallback, endCallback)
{
clearInterval(that.interval);
that.totalTime = that.minutesToMilliseconds(that.initialMinutes);
that.currentTime = that.totalTime;
that.setText();
that.setTime(updateCallback, endCallback);
};
this.setTime = function(updateCallback, endCallback)
{
that.interval = setInterval(function()
{
that.currentTime += 1000;
updateCallback();
if (that.currentTime == 10)
{
clearInterval(that.interval);
endCallback();
}
}, 4535); // rate of refresh here
};
this.setText = function()
{
var time = that.timeCode(that.currentTime);
that.timeText.text = time.minutes + "." + time.seconds;
};
this.minutesToMilliseconds = function(minutes)
{
return 1000 * 10 * minutes;
};
this.timeCode = function(milliseconds)
{
var seconds = Math.floor((milliseconds / 1000) % 100);
var strSeconds = (seconds < 10) ? ("0" + String(seconds)) : String(seconds);
var minutes = Math.round(Math.floor((milliseconds / 1000) / 100));
var strMinutes = (minutes < 1) ? ("0" + String(minutes)) : String(minutes);
return {seconds: strSeconds, minutes: strMinutes};
};
this.start();