cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div id='mainWrap' class='clearfix'>
  <h1 class='title'>Pomodoro Clock</h1>
  <div id='canvasWrap' class='clearfix'><canvas id='canvas1' width='200px' height='200px'></canvas><canvas id='canvas2' width='200px' height='200px'></canvas></div>
<div id='btnsWrapper' class='clearfix'>
  <div class='dimToggle'><div id='breakBtns'><span class='lengthTxt'>Break Length</span>
 <button type='button' name='breakVal' value='-' class='minus'>-</button><div id='breakVal'></div>
  
  <button type='button' name='breakVal' value='+' class='plus'>+</button>
  </div>

  <div id='sessionBtns'><span class='lengthTxt'>Session Length</span>
 <button type='button' name='minutes' value='-' class='minus'>-</button> <div id='minutesVal'></div>

    <button type='button' name='minutes' value='+' class='plus'>+</button></div></div><!-- end dimToggle1 -->
<div id='controlBtns'>
  <div class='dimToggle'><button type='button' id='start'>Start</button></div>
  <div class='dimToggle dim'><button type='button' id='pause'>Pause</button>
    <button type='button' id='reset'>Stop/Reset</button></div>
  </div><!-- end controlBtns -->
</div> <!-- end btnsWrapper -->
</div><!-- end mainWrap -->
<audio>
			<source src="http://octanewebgroup.com/wp-content/uploads/2016/06/Store_Door_Chime-Mike_Koenig-570742973.ogg" type="audio/ogg" />
			<source src="http://octanewebgroup.com/wp-content/uploads/2016/06/Store_Door_Chime-Mike_Koenig-570742973.mp3" type="audio/mp3" />
			Your browser does not support the audio element.
		</audio>

            
          
!
            
              
* {
  box-sizing: border-box;
  color: black;
}
#canvas1, #canvas2 {
  position: absolute;
  top: 0;
  left: 0;
}
#canvas1 {
  z-index: 2;
}
#canvas2 {
  z-index: 1;
}
#mainWrap {
  margin: 1em auto;
  max-width: 650px;
  height: 600px;
  border: 6px solid silver;
  border-radius: 10%;
  background: lightgrey;
  
}
#canvasWrap {
  width: 70%;
float: left;
  position: relative;
}
#btnsWrapper {
  width: 20%;
  float: right;
  background: grey;
  padding: 1%;
}
button {
  width: 100%;
  padding: 5%;
  margin: 5% auto;
  background-color: white;
  box-shadow: 1px 1px 1px black;
  border: 1px solid silver;
  border-radius: 10%;
}
#breakBtns, #sessionBtns {
  margin: 10% auto;
  text-align: center;
}
.lengthTxt {
  display: block;
  margin: 5%;
}
#breakVal, #minutesVal {
 display: inline-block;
 width: 40%;
}

#controlBtns {
  width: 100%;
}
#start, #pause, #reset {  
}
.plus, .minus {
 width: 20%;
}
.dimToggle button {
  color: green;
}
.dim button {
  color: grey;
}
.title {
  text-align: center;
  color: darkgrey;
}
.clearfix:after {
	visibility: hidden;
	display: block;
	font-size: 0;
	content: " ";
	clear: both;
	height: 0;
	}
            
          
!
            
              var options = {
  seconds: 0,
  minutes: 25,
  breakVal: 5
};
var audio = document.getElementsByTagName("audio")[0];
var canvas = document.querySelector('#canvas1');
var ctx = canvas.getContext('2d');
var canvas2 = document.querySelector('#canvas2');
var ctx2 = canvas2.getContext('2d');
var canvasWidth, canvasHeight, canvasMidX, canvasMidY;
var dimToggle = document.querySelectorAll('.dimToggle'),
  i;
var RUNNING = false,
  s, m, timer, milli, newS, newM, mTotal, mDeg, breakTime = false,
  pause = false;
var breakVal = document.querySelector('#breakVal');
var minutesVal = document.querySelector('#minutesVal');
var breakBtns = document.querySelector('#breakBtns');
var sessionBtns = document.querySelector('#sessionBtns');
var startBtn = document.querySelector('#start');
var pauseBtn = document.querySelector('#pause');
var resetBtn = document.querySelector('#reset');
breakBtns.addEventListener('click', breakValue, false);
sessionBtns.addEventListener('click', sessionValue, false);
startBtn.addEventListener('click', startT, false);
pauseBtn.addEventListener('click', pauseT, false);
resetBtn.addEventListener('click', reset, false);

pauseBtn.disabled = true;
minutesVal.innerHTML = tweak(options.minutes);
breakVal.innerHTML = tweak(options.breakVal);

ctx.lineCap = 'round';
var lineW;
var dimToggleL = dimToggle.length;
window.addEventListener('resize', resizeCanvas, false);
window.addEventListener('orientationchange', resizeCanvas, false);

// resize canvas if window is resized
function resizeCanvas() {
  ctx.clearRect(0, 0, canvasWidth, canvasHeight);
  ctx2.clearRect(0, 0, canvasWidth, canvasHeight);
  // Set up temporary canvas
  var tempCanvas = document.createElement('canvas');
  tempCanvas.width = canvas.width;
  tempCanvas.height = canvas.height;
  var tempCtx = tempCanvas.getContext('2d');
  // Set up temporary canvas2
  var tempCanvas2 = document.createElement('canvas');
  tempCanvas2.width = canvas.width;
  tempCanvas2.height = canvas.height;
  var tempCtx2 = tempCanvas2.getContext('2d');

  // Copy to temporary canvas
  tempCtx.drawImage(canvas, 0, 0);
  tempCtx2.drawImage(canvas2, 0, 0);
  canvasWidth = document.querySelector('#canvasWrap').offsetWidth;
  canvasHeight = canvasWidth;

  // Resize original canvas
  canvas.width = canvasWidth;
  canvas.height = canvasHeight;
  canvas2.width = canvasWidth;
  canvas2.height = canvasHeight;
  // Copy back to resized canvas
  ctx = canvas.getContext('2d');
  ctx.drawImage(tempCanvas, 0, 0, tempCanvas.width, tempCanvas.height, 0, 0, canvas.width, canvas.height);
  ctx2 = canvas2.getContext('2d');
  ctx2.drawImage(tempCanvas2, 0, 0, tempCanvas2.width, tempCanvas2.height, 0, 0, canvas2.width, canvas2.height);
  canvasMidX = canvasWidth / 2;
  canvasMidY = canvasHeight / 2;
  lineW = canvasWidth / 10;
  drawInit();
  if (pause) {
    draw();
  }
}

// degree to radian
function rad(deg) {
  return ((Math.PI / 180) * deg);
}

function tweak(n) {
  return (n < 10) ? '0' + n : n;
}

function drawInit() {
  ctx.clearRect(0, 0, canvasWidth, canvasHeight);
  ctx2.clearRect(0, 0, canvasWidth, canvasHeight);
  outerCircle();
  center();
  ctx.font = "40px Arial";
  minutes(options.minutes);
  seconds(options.seconds);

}

function draw() {
  ctx.clearRect(0, 0, canvasWidth, canvasHeight);
  center();
  pinkArc();
  blueArc();
  minutes(m);
  seconds(s);
} // end draw

function outerCircle() {
  ctx2.beginPath();
  ctx2.arc(canvasMidX, canvasMidY, canvasWidth / 2 - lineW, 0, 2 * Math.PI, false);
  ctx2.lineWidth = lineW;
  ctx2.shadowBlur = 10;
  ctx2.shadowColor = 'black';
  ctx2.strokeStyle = 'rgb(97, 94, 95)';
  ctx2.stroke();
  ctx2.closePath();
}

//center
function center() {
  ctx.beginPath();
  ctx.arc(canvasMidX, canvasMidY, canvasWidth / 4, 0, 2 * Math.PI, false);
  ctx.lineWidth = lineW;
    ctx.shadowOffsetX = 0;
  ctx.shadowOffsetY = 0;
  ctx.shadowBlur = 0;
  ctx.shadowBlur = 0;
  ctx.fillStyle = 'rgb(191,199, 214)';
  ctx.strokeStyle = 'grey';
  ctx.fill();
  ctx.stroke();
}
// pink seconds arc
function pinkArc() {
  ctx.shadowOffsetX = 1;
  ctx.shadowOffsetY = 1;
  ctx.shadowBlur = 15;
  ctx.beginPath();
  ctx.arc(canvasMidX, canvasMidY, canvasWidth / 4, (Math.PI / 180) * 270, rad(((newS * 6) - 90)), false);
  ctx.strokeStyle = 'rgb(247, 202, 201)';
  ctx.shadowColor = 'rgb(247, 202, 201)';
  ctx.lineWidth = lineW;
  ctx.stroke();
}
// blue minutes arc
function blueArc() {
  ctx.beginPath();
  ctx.arc(canvasMidX, canvasMidY, canvasWidth / 2 - lineW, (Math.PI / 180) * 270, rad(((newM * mDeg) - 90)), false);
  ctx.shadowColor = 'rgb(146, 168, 209)';
  ctx.strokeStyle = 'rgb(146, 168, 209)';
  ctx.lineWidth = lineW;
  ctx.stroke();
}
// minutes text
function minutes(source) {
  ctx.shadowOffsetX = 2;
  ctx.shadowOffsetY = 2;
  ctx.shadowBlur = 5;
  ctx.shadowColor = 'grey';
  ctx.fillStyle = "black";
  ctx.fillText(tweak(source), canvasMidX - 50, canvasMidY);
  ctx.fillText(':', canvasMidX, canvasMidY - 2);
}
// seconds text
function seconds(source) {
  ctx.fillStyle = "black";
  ctx.fillText(tweak(source), canvasMidX + 15, canvasMidY);
}

function countdown() {
  milli -= 40;
  ms = ((1000 - milli) / 1000);

  newS = (60 - s) + ms;
  newM = ((mTotal - m) - 1) + (newS / 60);

  if (milli <= 0) {
    s = s - 1;
    milli = 1000;
  }
  if (m > 0 && s <= 0) {
    m--;
    s = 59;

  } else if (s < 0) {
    window.clearInterval(timer);
    breakTime = (breakTime === false) ? true : false;
    audio.play();
    RUNNING = false;
    startT();
    return;
  }
  draw();
} // end countdown

function btnToggle() {
  for (var i = 0; i < dimToggleL; ++i) {
    dimToggle[i].classList.toggle('dim');
  }
}

function startT() {
  if (RUNNING) {
    return;
  }
  btnToggle();

  timer = 0;
  milli = 0;
  if (breakTime) {
    s = options.seconds;
    m = options.breakVal;
  } else {
    s = options.seconds;
    m = options.minutes;
  }
  mTotal = m;
  mDeg = 360 / mTotal;
  pauseBtn.disabled = false;
  RUNNING = true;
  timer = window.setInterval(countdown, 40);
}

function pauseT() {
  if (!pause) {
    // pause
    window.clearInterval(timer);
    pauseBtn.innerHTML = 'Resume';
    pause = true;
  } else {
    // resume
    timer = window.setInterval(countdown, 40);
    pauseBtn.innerHTML = 'Pause';
    pause = false;
  }
}

function reset() {
  if (RUNNING === false) {
    return;
  }
  window.clearInterval(timer);
  btnToggle();
  pauseBtn.innerHTML = 'Pause';
  pause = false;
  pauseBtn.disabled = true;
  breakTime = false;
  RUNNING = false;
  drawInit();
}

function updateDisplay(target, value) {
  if (RUNNING || value === undefined) {
    return;
  }
  var temp = options[target];
  temp = (value === '+') ? temp + 1 : temp - 1;
  if (temp < 1) {
    return;
  }
  options[target] = temp;
  if (target === 'minutes') {
    minutesVal.innerHTML = tweak(temp);
    drawInit();
  } else {
    breakVal.innerHTML = tweak(temp);
  }
}

function breakValue(e) {
  if (e.target !== e.currentTarget) {
     updateDisplay(e.target.name, e.target.value);
  }
}

function sessionValue(e) {
  if (e.target !== e.currentTarget) {
    updateDisplay(e.target.name, e.target.value);
  }
}
resizeCanvas();
            
          
!
999px
Loading ..................

Console