...

View Full Version : random images: lots of them



redhead
07-28-2002, 10:46 AM
Hello.

I need a script which will put 10 images into a random order of 20 images, so each image will be used twice. basically its gonna be in a 4x5 grid, so it will look something like this (but randomized, obviously):

http://www.btinternet.com/~chriscaws/example.gif

so... like that but ranomised. If you have any ideas... then please reply :cool:

x_goose_x
07-28-2002, 06:08 PM
name the files 1,2,3,...



<script>
w = 5; //board width
h = 4; //board height
r = 10; //number range
t = 2; //instances of each number
e = "gif"; //file extension

tb = "";
tb +='<table border="0" id="tbl" cellspacing="0" cellpadding="0" style="border-style: solid; border-color: red; border-width: 1;">';
for (y=0; y<h; y++) {
tb +='<tr>';
for (x=0; x<w; x++) {
tb +='<td><img id="'+x+"-"+y+'"></td>';
}
tb +='</tr>';
}
tb +='</table>';
document.write(tb)

imags = new Array();
for (x=0; x<r; x++) {
for (y=0; y<t; y++) {
imags[imags.length] = (x+1)+"."+e;
}
}

for (y=0; y<h; y++) {
for (x=0; x<w; x++) {
n = Math.floor(Math.random()*imags.length);
document.getElementById(x+"-"+y).src = imags[n];
imags[n] = imags[0];
t = imags.shift();
}
}

</script>

redhead
07-28-2002, 08:36 PM
nice one... thanks x_goose_x, thats perfect. :cool:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum