Advertisement
Guest User

Pebble Code

a guest
Aug 1st, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var rocky = require('rocky');
  2.  
  3. // Number of hours in the day
  4. var nHours = 10;
  5.  
  6. rocky.on('secondchange', function(event) {
  7.   rocky.requestDraw();
  8. });
  9.  
  10. rocky.on('draw', function(event) {
  11.   var ctx = event.context;
  12.   ctx.clearRect(0, 0, ctx.canvas.clientWidth, ctx.canvas.clientHeight);
  13.  
  14.   ctx.fillStyle = 'turquoise';
  15.   ctx.textAlign = 'center';
  16.     ctx.font = '30px bolder Bitham';
  17.    
  18.   var w = ctx.canvas.unobstructedWidth;
  19.   var h = ctx.canvas.unobstructedHeight;
  20.    
  21.     // Calculate the Time
  22.     var date = new Date();
  23.     var secs = date.getSeconds();
  24.     var mins = date.getMinutes();
  25.     var hour = date.getHours();
  26.    
  27.     var pourcent = (secs + mins*60 + hour*3600)/86400;
  28.    
  29.     // pourcent = (Dsecs + Dmins*100 + Dhour*10000)/100000
  30.    
  31.     var totalDsecs = pourcent*10000*nHours;
  32.    
  33.     var Dhour = Math.floor(totalDsecs/10000);
  34.     totalDsecs -= Dhour * 10000;
  35.    
  36.     var Dmins = Math.floor(totalDsecs/100);
  37.     var Dsecs = Math.floor(totalDsecs - Dmins*100);
  38.  
  39.     if (Dsecs < 10) {
  40.         Dsecs = "0" + Dsecs;
  41.     }
  42.    
  43.     if (Dmins < 10) {
  44.         Dmins = "0" + Dmins;
  45.     }
  46.    
  47.     if (secs < 10) {
  48.         secs = "0" + secs;
  49.     }
  50.    
  51.     if (mins < 10) {
  52.         mins = "0" + mins;
  53.     }
  54.    
  55.     var dec_time = Dhour + ":" + Dmins + ":" + Dsecs;
  56.   ctx.fillText(dec_time, w / 2, h / 2 - 40);
  57.    
  58.     ctx.font = '24px bold Gothic';
  59.     ctx.fillStyle = 'white';
  60.    
  61.     var time = "\n\n24h: " + hour + ":" + mins + ":" + secs;
  62.    
  63.     ctx.fillText(time, w / 2, h / 2 - 40);
  64.    
  65.     ctx.font = '18px Gothic';
  66.    
  67.     var currDate = "\n\n\n\n" + date.toISOString().split('T')[0].replace(/-/g,"/");
  68.     ctx.fillText(currDate, w / 2, h / 2 - 40);
  69. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement