Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var liczby = [];
  2.  
  3. var c = document.getElementById("canvas");
  4. var ctx = c.getContext("2d");
  5.  
  6. ctx.lineWidth = 2;
  7. ctx.strokeStyle = '#000';
  8.  
  9. function Rysuj (liczby)
  10. {
  11.     ctx.clearRect(0, 0, canvas.width, canvas.height);
  12.     for (var i = 0; i < liczby.length; i++)
  13.     {
  14.         ctx.beginPath();
  15.         ctx.moveTo(2 * i + 1, 500);
  16.         ctx.lineTo(2 * i + 1, 500 - (liczby[i]));
  17.         ctx.stroke();
  18.     }
  19. }
  20.  
  21. function Losuj()
  22. {
  23.     liczby = [];
  24.  
  25.     for (var i = 0; i < 250; i++)
  26.     {
  27.         liczby.push(Math.floor(Math.random() * 500) + 1);
  28.     }
  29.     Rysuj(liczby);
  30. }
  31.  
  32. function Sortuj()
  33. {
  34.     var j = 1;
  35.     function pj ()
  36.     {
  37.         if (j < liczby.length)
  38.         {
  39.             i = 0;
  40.             function pi ()
  41.             {
  42.                 if (i < liczby.length)
  43.                 {
  44.                     if (liczby[i] > liczby[i + 1])
  45.                     {
  46.                         var ltym = liczby[i];
  47.                         liczby[i] = liczby[i + 1];
  48.                         liczby[i + 1] = ltym;
  49.                     }
  50.                     Rysuj(liczby);
  51.                     i++;
  52.  
  53.                     setTimeout(pi, 1);
  54.                 }
  55.                 else
  56.                 {
  57.                     j++;
  58.                     return;
  59.                 }
  60.             }
  61.             pi();
  62.  
  63.             setTimeout(pj, 1);
  64.         }
  65.         else
  66.         {
  67.             //console.log(liczby);
  68.             //return liczby;
  69.             return;
  70.         }
  71.     }
  72.     pj();
  73. }
  74.  
  75. Losuj();
  76. //Sortuj();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement