Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var liczby = [];
- var c = document.getElementById("canvas");
- var ctx = c.getContext("2d");
- ctx.lineWidth = 2;
- ctx.strokeStyle = '#000';
- function Rysuj (liczby)
- {
- ctx.clearRect(0, 0, canvas.width, canvas.height);
- for (var i = 0; i < liczby.length; i++)
- {
- ctx.beginPath();
- ctx.moveTo(2 * i + 1, 500);
- ctx.lineTo(2 * i + 1, 500 - (liczby[i]));
- ctx.stroke();
- }
- }
- function Losuj()
- {
- liczby = [];
- for (var i = 0; i < 250; i++)
- {
- liczby.push(Math.floor(Math.random() * 500) + 1);
- }
- Rysuj(liczby);
- }
- function Sortuj()
- {
- var j = 1;
- function pj ()
- {
- if (j < liczby.length)
- {
- i = 0;
- function pi ()
- {
- if (i < liczby.length)
- {
- if (liczby[i] > liczby[i + 1])
- {
- var ltym = liczby[i];
- liczby[i] = liczby[i + 1];
- liczby[i + 1] = ltym;
- }
- Rysuj(liczby);
- i++;
- setTimeout(pi, 1);
- }
- else
- {
- j++;
- return;
- }
- }
- pi();
- setTimeout(pj, 1);
- }
- else
- {
- //console.log(liczby);
- //return liczby;
- return;
- }
- }
- pj();
- }
- Losuj();
- //Sortuj();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement