ok mate, basically you need to get rid of all the un needed timing stuff.
first of all, a brief explanation:
setTimeout (func, x)
will execute function func after x milliseconds.
setInterval (func, x)
will execute function func Each x milliseconds.
so you only need to set interval one time, and let it work. i have corrected your code:
var period = 600;
function Boom() {
if (period != 300) {
period = 300;
} else {
period = 600;
}
}
function Shake() {
this.draw = function () {
var time = new Date().getTime();
var shakeX = (Math.sin(time * 2.0 * Math.PI / period) + 0);
this.x = shakeX;
var shakeY = (Math.sin(time * 2.0 * Math.PI / period) + 0);
this.y = shakeY;
this.context.drawImage(image, 0, 0);
this.context.translate(this.x, this.y);
setInterval(Boom, 5000)
};
}