Pen Settings

HTML

CSS

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.

+ add another resource

JavaScript

Babel includes JSX processing.

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.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
    <div class="row text-center">
        <!-- Break Length -->
        <div class="col-xs-2">
            <div id="break-length">
                <p id="break-text">Break</p>
                <span id="break-length-minus">-</span>
                <span id="break-length-int">5</span>
                <span id="break-length-plus">+</span>
            </div>
        </div>
        <!-- Pomodoro canvas -->
        <div class="col-xs-8">
            <canvas id="canvas" width="400" height="400">Your browser does not support the canvas tag.</canvas>
        </div>
        <!-- Session Length -->
        <div class="col-xs-2">
            <div id="session-length">
                <p id="session-text">Session</p>
                <span id="session-length-minus">-</span>
                <span id="session-length-int">25</span>
                <span id="session-length-plus">+</span>
            </div>
        </div>
    </div>
    <!-- end row -->
</div>
<!-- end container-fluid -->
              
            
!

CSS

              
                * {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

html, body {
    height: 100%;
    color: #FFF;
    background-color: #1D1F20;
    font-family: "Roboto";
    font-weight: 300;
}

#header {
  font-size: 32px;
}

#canvas {
  cursor: pointer;    
}

#break-length {
  background-color: #2A2A2A;
  font-family: 'Inconsolata', monospace;
  font-size: 20px;
  border-radius: 4px;
  width: 80px;
}

#break-length-minus {
  cursor: pointer;
}

#break-length-plus {
  cursor: pointer;
}

#break-text {
    background-color: #0033FF;
    color: #FFFFFF;
    border-radius: 4px 4px 0 0;
}

#session-length {
  background-color: #2A2A2A;
  font-family: 'Inconsolata', monospace;    
  font-size: 20px;
  border-radius: 4px;
  width: 80px;
}

#session-length-minus {
  cursor: pointer;
}

#session-length-plus {
  cursor: pointer;
}

#session-text {
    background-color: #009900;
    color: #FFFFFF;
    border-radius: 4px 4px 0 0;
}

.container {
  width: 640px;
  height: 100%;
  display: flex;
  align-items: center;
}

/* Mobile */
@media (max-width: 480px) {
    canvas {
        width: 200px;
        height: 200px;
    }
    
    #break-length {
        font-size: 8px;
        width: 35px;
    }
    
    #session-length {    
        font-size: 8px;
        width: 35px;
    }    
    
    .container {
        width: 480px;
    }
}

              
            
!

JS

              
                $(document).ready(function() {

    function Timer() {
        var self = this;
        var running = false;
        var sessionLength = 25;
        var breakLength = 5;
        var counter = sessionLength * 60;
        var type = "session";
        var minutes;
        var seconds;
        var interval;
        var fgRed = "#CC0000";
        var bgRed = "#660000";
        var fgGreen = "#009900";
        var bgGreen = "#005500";           
        var fgBlue = "#0033FF";
        var bgBlue = "#000066";
        var icon = "\uf04b";
        var sound = new Audio("http://aaroncallahan.com/sounds/notify.mp3");

        // Canvas
        var c = document.getElementById('canvas');
        var cWidth = canvas.width;
        var cHeight = canvas.height;
        var ctx = c.getContext('2d');
        var drawCounter = 0;
        var drawStep = 2 / counter;

        this.initCanvas = function(mins) {
            // Foreground arc
            ctx.beginPath();
            ctx.arc(cWidth / 2, cHeight / 2, 150, 0 * Math.PI, 2 * Math.PI, true);
            ctx.lineWidth = 40;
            ctx.strokeStyle = type === "session" ? fgGreen : fgBlue;
            ctx.stroke();
            ctx.closePath();
            // Text
            ctx.fillStyle = type === "session" ? fgGreen : fgBlue;
            ctx.font = "300 40px Roboto";
            ctx.textBaseline = "middle";
            ctx.textAlign = "center";
            ctx.fillText(type.toUpperCase(), cWidth / 2, cHeight / 2 - 70);
            ctx.fillStyle = "#EEE";
            ctx.font = "400 90px Roboto";
            ctx.fillText(mins + ":00", cWidth / 2, cHeight / 2);
            // Icon
            ctx.fillStyle = type === "session" ? fgGreen : fgBlue;
            ctx.font = "50px FontAwesome";
            ctx.fillText(icon, cWidth / 2, cHeight / 2 + 80);             
        }

        this.isRunning = function() {
            return running;
        }

        this.getSeconds = function() {
            return seconds;
        }

        this.getMinutes = function() {
            return minutes;
        }

        this.getBreakLength = function() {
            return breakLength;
        }

        this.setBreakLength = function(length) {
            breakLength = length;
        }

        this.getSessionLength = function() {
            return sessionLength;
        }

        this.setSessionLength = function(length) {
            sessionLength = length;
        }

        this.getCounter = function() {
            return counter;
        }

        this.setCounter = function(length) {
            counter = length * 60;
            clearInterval(interval);
        }

        this.getDrawCounter = function() {
            return drawCounter;
        }

        this.setDrawCounter = function(length) {
            drawCounter = length;
        }

        this.getDrawStep = function() {
            return drawStep;
        }

        this.setDrawStep = function(length) {
            var counter = length * 60;
            drawStep = 2 / counter;
        }

        this.getType = function() {
            return type;
        }

        this.run = function() {
            running = true;
            icon = "\uf04c";
            interval = setInterval(function() {

                self.updateTime();

                if (counter >= 0) {
                    self.clearCanvas();
                    self.updateCanvas();
                } else if (counter < 0) {
                    switch (type) {
                        case "session":
                            type = "break";
                            counter = breakLength * 60;
                            self.updateTime();
                            self.updateDrawTime();
                            self.clearCanvas();
                            self.updateCanvas();
                            sound.play();
                            break;
                        case "break":
                            type = "session";
                            counter = sessionLength * 60;
                            self.updateTime();
                            self.updateDrawTime();
                            self.clearCanvas();
                            self.updateCanvas();
                            sound.play();
                            break;
                    }
                }

                counter--;
            }, 1000);
        }

        this.clearCanvas = function() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
        }

        this.updateCanvas = function() {
            var fgColor = type === "session" ? fgGreen : fgBlue;
            var bgColor = type === "session" ? bgGreen : bgBlue;
            var offset = Math.PI/2; // Used to shift from 3 to 12 o'clock position

            // Background arc
            ctx.beginPath();
            ctx.arc(cWidth / 2, cHeight / 2, 150, 0 * Math.PI, 2 * Math.PI, true);
            ctx.lineWidth = 30;
            ctx.strokeStyle = bgColor;
            ctx.stroke();
            ctx.closePath();

            // Foreground arc
            ctx.beginPath();
            ctx.arc(cWidth / 2, cHeight / 2, 150, (2 * Math.PI) - offset, (drawCounter * Math.PI) - offset, true);
            ctx.lineWidth = 40;
            ctx.strokeStyle = fgColor;
            ctx.stroke();
            ctx.closePath();
            
            // Text
            ctx.fillStyle = fgColor;
            ctx.font = "300 40px Roboto";
            ctx.textBaseline = "middle";
            ctx.textAlign = "center";
            if (type === "session") {
                ctx.fillText(type.toUpperCase(), cWidth / 2, cHeight / 2 - 70);
            } else {
                ctx.fillText(type.toUpperCase(), cWidth / 2, cHeight / 2 - 70);
            }

            if (minutes !== undefined) {
                ctx.fillStyle = "#EEE";
                ctx.font = "400 90px Roboto";
                ctx.fillText(minutes + ":" + seconds, cWidth / 2, cHeight / 2);
            }
            
            this.updateCanvasIcon();

            drawCounter += drawStep;
        }
        
        this.updateCanvasIcon = function() {
            // Icon
            ctx.clearRect(cWidth/2-25, cHeight/2+55, 50, 50);
            ctx.fillStyle = type === "session" ? fgGreen : fgBlue;
            ctx.font = "50px FontAwesome";
            ctx.fillText(icon, cWidth / 2, cHeight / 2 + 80);               
        }

        this.updateTime = function() {
            minutes = Math.floor(counter / 60);
            seconds = Math.floor(counter % 60);
            seconds = seconds < 10 ? '0' + seconds : seconds;
        }

        this.updateDrawTime = function() {
            drawCounter = 0;
            drawStep = 2 / counter;
        }

        this.pause = function() {
            running = false;
            icon = "\uf04b";
            this.updateCanvasIcon();
            clearInterval(interval);
        }

        this.reset = function() {
            running = false;
            sessionLength = 25;
            breakLength = 5;
            counter = length * 60;
            clearInterval(interval);
        }

    }; // end Timer()

    // Build a new timer with default session length
    var timer = new Timer();

    // Load Google Fonts into Canvas
    WebFontConfig = {
        google: {
            families: ['Roboto', 'Inconsolata']
        },
        custom: {
            families: ['FontAwesome'],
            testStrings: {
                'fontawesome': '\uf04c\uf04b'
            }
        },
        active: function() {
            sessionStorage.fonts = true;
            timer.initCanvas(timer.getSessionLength());
        },
    };

    (function() {
        var wf = document.createElement("script");
        wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
        wf.async = 'true';
        document.head.appendChild(wf);
    })();

    // Add click event listeners to all +/- elements
    $('#break-length-minus').click(function() {
        var breakLength = timer.getBreakLength();
        if (breakLength > 1 && !timer.isRunning()) {
            breakLength--;
            timer.setBreakLength(breakLength);
            if (timer.getType() === "break") {
                timer.setCounter(breakLength);
                timer.setDrawStep(breakLength);
                timer.setDrawCounter(0);
                timer.clearCanvas();
                timer.initCanvas(breakLength);
            }
            $('#break-length-int').text(breakLength);
            //$('#timer').text(breakLength + ":00");
        }
    });

    $('#break-length-plus').click(function() {
        var breakLength = timer.getBreakLength();
        if (breakLength < 60 && !timer.isRunning()) {
            breakLength++;
            timer.setBreakLength(breakLength);
            if (timer.getType() === "break") {
                timer.setCounter(breakLength);
                timer.setDrawStep(breakLength);
                timer.setDrawCounter(0);
                timer.clearCanvas();
                timer.initCanvas(breakLength);
            }
            $('#break-length-int').text(breakLength);
        }
    });

    $('#session-length-minus').click(function() {
        var sessionLength = timer.getSessionLength();
        if (sessionLength > 1 && !timer.isRunning()) {
            sessionLength--;
            timer.setSessionLength(sessionLength);
            if (timer.getType() === "session") {
                timer.setCounter(sessionLength);
                timer.setDrawStep(sessionLength);
                timer.setDrawCounter(0);
                timer.clearCanvas();
                timer.initCanvas(sessionLength);
            }
            $('#session-length-int').text(sessionLength);
        }
    });

    $('#session-length-plus').click(function() {
        var sessionLength = timer.getSessionLength();
        if (sessionLength < 60 && !timer.isRunning()) {
            sessionLength++;
            timer.setSessionLength(sessionLength);
            if (timer.getType() === "session") {
                timer.setCounter(sessionLength);
                timer.setDrawStep(sessionLength);
                timer.setDrawCounter(0);
                timer.clearCanvas();
                timer.initCanvas(sessionLength);
            }
            $('#session-length-int').text(sessionLength);
        }
    });

    // Set run/pause click listener on Canvas
    $('#canvas').click(function() {
        if (timer.isRunning()) {
            timer.pause();
        } else {
            timer.run();
        }
    });

});
              
            
!
999px

Console