Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    United Kingdom Confused: Often
    Posts
    859
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation random images: lots of them

    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):



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

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    name the files 1,2,3,...

    Code:
    <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>

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    United Kingdom Confused: Often
    Posts
    859
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    nice one... thanks x_goose_x, thats perfect.
    redhead


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •