Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <canvas id="gameCanvas" width="1350" height="640"></canvas>
- <script>
- var second = 0
- var minute = 0
- var hour = 0
- var paused = false
- function countSec() {
- second ++
- }
- function countMin() {
- if(second == 60) {
- second = 0;
- minute ++
- }
- }
- function countHour() {
- if(minute == 60) {
- minute = 0;
- hour ++
- }
- }
- window.onload = function() {
- canvas = document.getElementById('gameCanvas');
- canvasContext = canvas.getContext('2d');
- var framesPerSecond = 1
- setInterval(function() {
- drawCounter();
- if(paused == false) {
- countSec();
- countMin();
- countHour();
- }
- }, 1000/framesPerSecond);
- canvas.addEventListener('mousedown',handleMouseClick);
- }
- function drawCounter() {
- drawRect(0,0, 750,750, 'white');
- canvasContext.font="40px Arial";
- canvasContext.fillStyle = 'blue';
- canvasContext.fillText("Seconds", 50,50);
- canvasContext.fillText(second, 230,50);
- canvasContext.fillText("Minutes", 50,100);
- canvasContext.fillText(minute, 230,100);
- canvasContext.fillText("Hours", 50,150);
- canvasContext.fillText(hour, 230,150);
- canvasContext.fillText(":", 215,50);
- canvasContext.fillText(":", 215,100);
- canvasContext.fillText(":", 215,150);
- }
- function drawRect(leftX, topY, width, height, drawColor) {
- canvasContext.fillStyle = drawColor;
- canvasContext.fillRect(leftX, topY, width, height);
- }
- function handleMouseClick(evt) {
- if(paused == false) {
- paused = true
- } else if(paused) {
- paused = false
- }
- }
- </script>
- <html>
Add Comment
Please, Sign In to add comment