asternauta

[Piękny] Czas [przeszły] do końca lekcji

Jan 3rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.65 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title></title>    
  5.         <meta charset="UTF-8"/>
  6.     </head>
  7.     <body>
  8.         <!--
  9.         <canvas id="rys1" width="500" height="500" style="border: 1px solid"></canvas>
  10.         -->
  11.         <canvas id="rys2" width="500" height="50" style="border: 1px solid"></canvas>
  12.         <script>
  13.             //TUDU: zrobić należycie to rysowanie prostukonta i wymyśleć rozwiązanie z kołem
  14.  
  15.             var konce_lekcji = [
  16.                 [7, 0],
  17.                 [7, 50],
  18.                 [8, 40],
  19.                 [9, 30],
  20.                 [10, 15],
  21.                 [11, 15],
  22.                 [12, 5],
  23.                 [12, 55],
  24.                 [13, 45],
  25.                 [14, 35],
  26.                 [15, 25]
  27.             ];
  28.            
  29.             const czas_lekcji = 45;
  30.             var nr_kon_lekc = -1;  
  31.             /*
  32.             function DodajZeroWiodace(l)
  33.             {
  34.                 var w = l;
  35.                
  36.                 if(l < 10)
  37.                     w = "0" + l;
  38.                
  39.                 return w;
  40.             }
  41.             */
  42.             function ZnajdzNrTKoncaLekcji()
  43.             {
  44.                 var d = new Date();
  45.                 var i = 0;
  46.                 var n = -1;
  47.                 while (n == -1 && i < konce_lekcji.length)
  48.                 {
  49.                     if (d.getHours() <= konce_lekcji[i][0])
  50.                     {
  51.                         if (d.getMinutes() <= konce_lekcji[i][1])
  52.                         {
  53.                             n = i;
  54.                         }
  55.                     }
  56.                     ++i;
  57.                 }
  58.                
  59.                 return n;
  60.             }
  61.            
  62.             function ObliczCzasDoKoncaLekcji(d, n)
  63.             {
  64.                 var d2 = new Date();
  65.                 d2.setHours(konce_lekcji[nr_kon_lekc][0]);
  66.                 d2.setMinutes(konce_lekcji[nr_kon_lekc][1]);
  67.                 d2.setSeconds(d.getSeconds());
  68.                
  69.                 var diff = d2 - d;
  70.                 var minuty = Math.round(diff / 60000);     
  71.                
  72.                 return minuty;
  73.             }
  74.            
  75.             var rys1 = document.getElementById("rys1");
  76.             var rys2 = document.getElementById("rys2");
  77.            
  78.             function RysujKolo(ctx, x, y, r, wypelnienie, wsp_pi = 2)
  79.             {
  80.                 ctx.beginPath();
  81.                 ctx.arc(x,y,r,0,wsp_pi*Math.PI);
  82.                
  83.                 if (typeof(wypelnienie) != "undefined")
  84.                 {
  85.                     ctx.fillStyle = wypelnienie;
  86.                     ctx.fill();
  87.                 }
  88.                 else
  89.                     ctx.stroke();
  90.             }
  91.            
  92.             /*
  93.             const kolo_tlo = "red";
  94.             const kolo_tlo_czas = "green";
  95.             */
  96.             const prost_tlo = "green";
  97.             const prost_tlo_czas = "#d1c134";
  98.             const tekst_kolor = "black";
  99.             const tekst_czcionka = "20px Verdana";     
  100.            
  101.             function Rysuj()
  102.             {
  103.                 //var ctx1 = rys1.getContext("2d");
  104.                 var ctx2 = rys2.getContext("2d");
  105.                
  106.                 /*
  107.                 var rys1_sz = rys1.width;
  108.                 var rys1_wys = rys1.height;
  109.                 */
  110.                
  111.                 var rys2_sz = rys2.width;
  112.                 var rys2_wys = rys2.height;
  113.                
  114.                 var d = new Date();
  115.                 var minuty = ObliczCzasDoKoncaLekcji(d, nr_kon_lekc);
  116.                
  117.                 var ul = minuty / czas_lekcji;
  118.                 var prost_szer_czas = rys2_sz * ul;
  119.                
  120.                 /*
  121.                 var kolo_x, kolo_y, kolo_r;
  122.                
  123.                 if (c_sz <= c_wys)                 
  124.                     kolo_r = c_sz / 2;                 
  125.                 else
  126.                     kolo_r = c_wys / 2;                
  127.                
  128.                 kolo_r--;
  129.                
  130.                 kolo_x = c_sz / 2;
  131.                 kolo_y = c_wys / 2;
  132.                
  133.                 RysujKolo(ctx1, kolo_x, kolo_y, kolo_r, kolo_tlo);
  134.                 */
  135.                
  136.                 ctx2.fillStyle = prost_tlo;
  137.                 ctx2.fillRect(0, 0, rys2_sz, rys2_wys);
  138.                
  139.                 ctx2.fillStyle = prost_tlo_czas;               
  140.                 ctx2.fillRect(0, 0, prost_szer_czas, rys2_wys);
  141.                
  142.                 ctx2.fillStyle = tekst_kolor
  143.                 ctx2.font = tekst_czcionka;
  144.                 ctx2.fillText("0", 0, rys2_wys - 1);
  145.                
  146.                 var nap_czas_do_kon_lek = minuty + "";
  147.                 var nap_czas_do_kon_lek_szer = ctx2.measureText(nap_czas_do_kon_lek).width;
  148.                
  149.                 ctx2.fillText(nap_czas_do_kon_lek, prost_szer_czas, rys2_wys - 1);
  150.                
  151.                 var nap_czas_lek_szer = ctx2.measureText("45").width;
  152.                 var nap_czas_lek_x = rys2_sz - nap_czas_lek_szer;
  153.                 ctx2.fillText("45", nap_czas_lek_x, rys2_wys - 1);
  154.                
  155.                 /*
  156.                 var wsp_pi = ul * 2;               
  157.                 RysujKolo(ctx, kolo_x, kolo_y, kolo_r, kolo_czas_tlo, wsp_pi);
  158.                 */
  159.                
  160.             }
  161.            
  162.             nr_kon_lekc = ZnajdzNrTKoncaLekcji();
  163.             Rysuj();
  164.             setInterval(Rysuj,1000);
  165.         </script>
  166.     </body>
  167. </html>
Advertisement
Add Comment
Please, Sign In to add comment