Hi there
I'm making a project to show how some of algorithms work. Basically i needed to show some drawing pixel by pixel. I made the code
below and tried to run it
<script>
function init() {
var paper = Raphael(10, 50, 800, 600);
var arr = [];
var j = 1;
var i = 1;
for (var x = 10; x < 800; x = x + 10) {
arr[x] = [];
for (var y = 50; y < 600; y = y + 10) {
arr[x][y] = paper.circle(x, y, 5);
}
}
return arr;
}
function setPixel(x, y,arr) {
var x = x * 10;
y = (y + 4)*10;
var arr=init();
arr[x][y].attr("fill", "#f00");
}
function unsetPixel(x, y,arr) {
var x = x * 10;
y = (y + 4)*10;
var arr=init();
arr[x][y].attr("fill", "#fff");
}
function clear(arr) {
for (var i = 1; i < 80; i++) {
for (var j = 1; j < 56; j++) {
unsetPixel(j, i, arr);
}
}
}
var ins = init();
for (var i = 1; i < 10; i++) {
for (var j = 1; j < 10; j++) {
setPixel(j, i, ins);
}
}
</script>
Basically it creates matrix of big 'pixels'
So far so good drawing 4800 empty circles was nearly instant
Problem started when i wanted to test the filling of them . Opera was filling 9x9 box for nearly 10 minutes , FF gave message about script timed out , Chrome didnt gave a fuck and showed me filled circles after about 10s of page loading.
Whats wrong with this script ? I'm pretty new to JS so sorry for propably some lame mistake or approach to this :d