actorRunning

12-17-2011, 01:18 AM

Well, I clearly haven't the experience with javascript to understand why I can't do this:

function bubbleSortKernel(a, b) {

if (b < 50) {

swap(a, b);

draw();

setTimeout("bubbleSortKernel(++a, ++b)", 200);

}

}

where

swap(a, b) does just what it says: swaps the two elements in an array, and

draw() looks about like this:

function draw() {

if (ctx != null) {

ctx.clearRect(0, 0, width, height);

for (var i = 0; i < rectangles.length; i++) {

ctx.fillRect(x, rectangles[i][0], rectangles[i][1], rectangles[i][2]);

}

}

}

I'm newer to javascript that other things, and this seems perfectly legal to me. I'm looking for someone who knows more that I and can explain what I'm missing. I'm guessing my timeout doesn't really work like I think it does, but I've gotten so frustrated I can't see the forest for the trees.

Any help or nudge is greatly appreciated. Thanks!

function bubbleSortKernel(a, b) {

if (b < 50) {

swap(a, b);

draw();

setTimeout("bubbleSortKernel(++a, ++b)", 200);

}

}

where

swap(a, b) does just what it says: swaps the two elements in an array, and

draw() looks about like this:

function draw() {

if (ctx != null) {

ctx.clearRect(0, 0, width, height);

for (var i = 0; i < rectangles.length; i++) {

ctx.fillRect(x, rectangles[i][0], rectangles[i][1], rectangles[i][2]);

}

}

}

I'm newer to javascript that other things, and this seems perfectly legal to me. I'm looking for someone who knows more that I and can explain what I'm missing. I'm guessing my timeout doesn't really work like I think it does, but I've gotten so frustrated I can't see the forest for the trees.

Any help or nudge is greatly appreciated. Thanks!