Advertisement
Guest User

laby4

a guest
Mar 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.44 KB | None | 0 0
  1. <html>
  2. <head>
  3.   <meta charset="UTF-8">
  4.   <style>
  5.     #square{
  6.       width: 300px;
  7.       height: 300px;
  8.       background-color: gray;
  9.       border: 1px solid black;
  10.       margin-left: 30px;
  11.       float: left;
  12.     }
  13.     #square2{
  14.       width: 300px;
  15.       height: 300px;
  16.       background-color: gray;
  17.       border: 1px solid black;
  18.       margin-left: 30px;
  19.       float: left;
  20.     }
  21.     #form{
  22.       margin-top: 40px;
  23.     }
  24.     input[type=button]{
  25.       display:block;
  26.       margin-top: 30px;
  27.       margin-left: 30px;
  28.     }
  29.  
  30.   </style>
  31.   <script type="text/javascript">
  32.     var odcienKoloru=50;
  33.     var losowy_kolor = 0;
  34.     var numer_pomiaru = 1;
  35.  
  36.     function ustawKolor()
  37.     {
  38.       kwadrat = document.getElementById("square");
  39.       losowy_kolor = Math.floor(Math.random() * 100);
  40.       wartosc = losowy_kolor;
  41.       kwadrat.style.backgroundColor="rgb("+wartosc+"%,"+wartosc+"%,"+wartosc+"%)";
  42.     }
  43.     function jasnosc(val)
  44.     {
  45.       kwadrat = document.getElementById("square2");
  46.       if(val=="jasniej"){
  47.         odcienKoloru += 5;
  48.         wartosc = odcienKoloru;
  49.         kwadrat.style.backgroundColor="rgb("+wartosc+"%,"+wartosc+"%,"+wartosc+"%)";
  50.       }
  51.       if(val=="ciemniej"){
  52.         odcienKoloru -= 5;
  53.         wartosc = odcienKoloru;
  54.         kwadrat.style.backgroundColor="rgb("+wartosc+"%,"+wartosc+"%,"+wartosc+"%)";
  55.       }
  56.  
  57.     }
  58.  
  59.     function ok() {
  60.         document.getElementById("tabela").innerHTML += "<tr><td>" + numer_pomiaru + "</td><td>" + losowy_kolor +"</td><td>" + odcienKoloru + "</td><td>" + Math.abs(losowy_kolor - odcienKoloru) + "</td></tr>";
  61.         numer_pomiaru++;
  62.     }
  63.  
  64.     function czysc() {
  65.         numer_pomiaru= 1;
  66.         document.getElementById("tabela").innerHTML = "";
  67.     }
  68.   </script>
  69. </head>
  70.  
  71. <body>
  72.   <div id="square"></div>
  73.   <div id="square2"></div>
  74.   <form id="form">
  75.     <input type="button" value="Ustaw Kolor" onclick="ustawKolor()"/>
  76.     <input id="jasniej" type="button" value="Jasniej" onclick="jasnosc(this.id)"/>
  77.     <input id="ciemniej" type="button" value="Ciemniej" onclick="jasnosc(this.id)"/>
  78.     <input type="button" value="OK" onclick="ok()"/>
  79.     <input type="button" value="Czyść" onclick="czysc()"/>
  80.   </form>
  81.   <table border="1">
  82.     <tr>
  83.         <th>Numer pomiaru</th>
  84.         <th>Kolor losowy</th>
  85.         <th>Kolor wybrany</th>
  86.         <th>Różnica</th>
  87.     </tr>
  88.     <tbody id="tabela">
  89.  
  90.     </tbody>
  91.   </table>
  92. </body>
  93. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement