/    Sign up×
Community /Pin to ProfileBookmark

Speed-up Airport-like big board?

Hi everybody,

is there a way to make chars to change more quickly?
Here is the script:

<pre>
<script type=”text/javascript”>

var numRows = 40;
var numCols = 80;
var numChars = numRows*numCols;

var linearOrder = new Array;
var randomOrder = new Array;
var whichChar = 0;

for (i=1;i<=numRows;i++) {
document.write(‘<div id=”r’+i+'”>’);
for (j=1;j<=numCols;j++) {
document.write(‘<span id=”r’+i+’s’+j+'”>’+String.fromCharCode(65 + Math.round(Math.random() * 25))+'</span>’);
whichChar++;
linearOrder[whichChar] = i+”-“+j;
}
document.write(‘</div>’);
}

for (p=1;p<=numChars;p++) {
randomSelect = Math.ceil(Math.random() * (numChars-p+1));
randomOrder[p] = linearOrder[randomSelect];
linearOrder[randomSelect] = linearOrder[numChars-p+1];
}

function changeTable(p) {
for (q=p;q<p+10;q++) {
coords = randomOrder[q].split(“-“);
document.getElementById(‘r’+coords[0]+’s’+coords[1]).style.color = ‘#cccccc’;
}
if (q<numChars) setTimeout(“changeTable(“+q+”)”,1);
}

onLoad=setTimeout(“changeTable(1)”,1);

</script>
</pre>

I want to make text-only web pages with this kind of changing, but it lasts too long…
Any idea?

Thanks.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceApr 01.2006 — Post a live link to your page on the Internet, please. Thanks.
Copy linkTweet thisAlerts:
@phpnoviceApr 01.2006 — 3,200 executions of [COLOR=Blue]getElementById[/COLOR] is part of what is slowing it down. Otherwise, you can increase the number in [COLOR=Red]red[/COLOR] below to speed it up also.
<i>
</i>function changeTable(p) {
for (q=p;q&lt;p+[COLOR=Red]10[/COLOR];q++) {
coords = randomOrder[q].split("-");
document.[COLOR=Blue]getElementById[/COLOR]('r'+coords[0]+'s'+coords[1]).style.color = '#cccccc';
}
if (q&lt;numChars) setTimeout("changeTable("+q+")",1);
}
Copy linkTweet thisAlerts:
@autorauthorApr 01.2006 — Yes, getElementById is slowing it down, but i do not know if it can be replaced by something "smarter".

Also, the script execution is divided into parts, because when there is only one cycle, nothing can be visible until the end of the cycle (WHY???)

But increasing the lenght of the small parts (p+10) makes the script CUT when viewing...
Copy linkTweet thisAlerts:
@autorauthorApr 01.2006 — In the first part when creating the random table - nothing is visible until the end of "for cycle" (WWHHYY!!), but the whole time is smaller.

Is it possible to make it visible "on the fly" in one cycle? Maybe this way can speed-up changing the table too.

Is there any mystery in "for cycle" I cannot see?
×

Success!

Help @autor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...