slide-show (random images)?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Burtenshaw

    slide-show (random images)?

    I would like to make a slide show using random images. The problem is my
    host is 250.com, and they don't support cgi-programs. Is there another
    way to accomplish random images?

  • Richard

    #2
    Re: slide-show (random images)?

    Michael Burtenshaw wrote:
    [color=blue]
    > I would like to make a slide show using random images. The problem is my
    > host is 250.com, and they don't support cgi-programs. Is there another
    > way to accomplish random images?[/color]




    I thought 250.com went out of the hosting business.
    Since I now get a website for "micropaten t".


    Comment

    • Evertjan.

      #3
      Re: slide-show (random images)?

      Michael Burtenshaw wrote on 19 dec 2004 in comp.lang.javas cript:
      [color=blue]
      > I would like to make a slide show using random images. The problem is my
      > host is 250.com, and they don't support cgi-programs. Is there another
      > way to accomplish random images?[/color]

      Clientside scripting, surely.

      You uploading a different page every 5 minutes,
      works as long as you don't fall asleep.

      Serverside scripting, like ASP or PHP, if on your ISP.
      [No, I don't want to have a look at your ISP's specs]

      CGI-programming is not a primary method for such simple tasks, IMHO.

      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      • Ron Beitel

        #4
        Re: slide-show (random images)?

        On Sun, 19 Dec 2004 00:02:18 -0500, MichaelBurtensh aw@webtv.net
        (Michael Burtenshaw) wrote:
        [color=blue]
        >I would like to make a slide show using random images. The problem is my
        >host is 250.com, and they don't support cgi-programs. Is there another
        >way to accomplish random images?[/color]


        Michael,

        I have been working on a client-side script to automatically loop
        though mulitple sets of images. Each slide is name with a sequential
        number such as myImage1.jpg, myImage2.jpg myImage3.jpg. This
        lets me us a "for loop" in the preload images into an Array, then I
        can sequential step through the images by incrementing the counter
        (currImg++). To randomly select the next image use....
        currImg = Math.round(Math .random()*maxIm g)


        Here is a greatly simplified example of my script. I have stripped
        off a lot of functions/buttoms, such First, Last, Prev, FrameRate and
        the ability for the user to select different set of images.

        Good Luck,
        Ron Beitel


        //***** SlideShow_Rando m.html ******

        <html>
        <head>

        // ron beitel, 20 Dec 2004

        <script language="JavaS cript">

        var delay = 500 // 1000 is 1 sec.
        var currImg = 0 // index to the current image
        var maxImg = 25 // default number of images (0 to 24)
        var tid // timeout Id

        var pix = new Array()

        function preloadImgSet(m ax) {
        for (i=0;i<max;i++) {
        pix[i] = new Image()
        pix[i].src = "http://250.com/yourPath/image_" + i + ".jpg"
        }

        nxtSlide()
        }

        function nxtSlide() {
        clearTimeout(ti d)
        currImg = Math.round(Math .random()*maxIm g)
        document.images .Slide.src = pix[currImg].src
        tid = setTimeout('nxt Slide()', delay)
        }

        function loop() {
        tid = setTimeout('nxt Slide()', delay)
        }

        function stop() {
        clearTimeout(ti d)
        }

        function next() {
        currImg = Math.round(Math .random()*maxIm g)
        document.images .Slide.src = pix[currImg].src
        }

        </script>

        </head>

        <body onLoad="preload ImgSet(maxImg)" >


        <table border>
        <tr><td colspan=2 align=center>
        <h2>My Slide Show</h2>
        <h3>Loop or Step Randomly</h3>
        </td></tr>

        <tr><td><tabl e border="0" cellpadding="0" cellspacing="0" >

        <tr><td align="center">
        <img src="" name='Slide'>
        </td></tr>

        <tr align="center"> <td>
        <form name="buttons">
        <input type="button" value="Loop" onclick="loop() "/>
        <input type="button" value="Stop" onclick="stop() "/>
        <input type="button" value="Next" onclick="next() "/>
        </form>
        </td></tr>

        </table></td></tr>

        </table>




        </body>
        </html>






        Comment

        • Ron Beitel

          #5
          Re: slide-show (random images)?

          On Sun, 19 Dec 2004 00:02:18 -0500, MichaelBurtensh aw@webtv.net
          (Michael Burtenshaw) wrote:
          [color=blue]
          >I would like to make a slide show using random images. The problem is my
          >host is 250.com, and they don't support cgi-programs. Is there another
          >way to accomplish random images?[/color]


          Michael,

          If you don't want to sequential number your filenames, change the

          function preloadImgSet() {
          pix[0] = new Image(); pix[0].src = "yourURL/imageA.jpg";
          pix[1] = new Image(); pix[1].src = "yourURL/imageB.jpg";
          pix[2] = new Image(); pix[2].src = "yourURL/imageC.jpg";

          I didn't want to explicitly list the 500+ image files in my SlideShow.

          Hope this helps,
          Ron Beitel

          Comment

          • Dr John Stockton

            #6
            Re: slide-show (random images)?

            JRS: In article <iuahs01klt55de qemlpncnqdfjivq rafsn@4ax.com>, dated
            Tue, 21 Dec 2004 23:27:10, seen in news:comp.lang. javascript, Ron Beitel
            <ronb@not.her e> posted :
            [color=blue]
            > To randomly select the next image use....
            >currImg = Math.round(Math .random()*maxIm g)[/color]

            Bad code - see FAQ.

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
            <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
            <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
            <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

            Comment

            • Ron Beitel

              #7
              Re: slide-show (random images)?

              On Wed, 22 Dec 2004 14:31:03 +0000, Dr John Stockton
              <spam@merlyn.de mon.co.uk> wrote:
              [color=blue]
              >JRS: In article <iuahs01klt55de qemlpncnqdfjivq rafsn@4ax.com>, dated
              >Tue, 21 Dec 2004 23:27:10, seen in news:comp.lang. javascript, Ron Beitel
              ><ronb@not.here > posted :
              >[color=green]
              >> To randomly select the next image use....
              >>currImg = Math.round(Math .random()*maxIm g)[/color]
              >
              >Bad code - see FAQ.
              >[/color]


              Oops!

              What Doctor John is either to busy or to arrogant to explain
              is my use of Math.round() instead of Math.floor().

              In my example, currImg gets a value between 0 and 25 inclusive.
              But the Array of images holds 25 images, numbered 0 to 24.

              0 <= Math.round(Math .random()*x) <= x
              0 <= Math.floor(Math .random()*x) < x


              Also apparently some browsers (i.e. Opera) don't implement
              the random function and return [0 .. 1.0] instead of [0 .. 1.0).
              Use a modulus 1 to gaurd against this. So change the lines...

              currImg = Math.floor((Mat h.random() % 1) * maxImg)




              Comment

              • Dr John Stockton

                #8
                Re: slide-show (random images)?

                JRS: In article <v59ks0lihb35kn g4b9991bpod7rg0 587bl@4ax.com>, dated
                Thu, 23 Dec 2004 02:10:58, seen in news:comp.lang. javascript, Ron
                Beitel <ronb@not.her e> posted :[color=blue]
                >On Wed, 22 Dec 2004 14:31:03 +0000, Dr John Stockton
                ><spam@merlyn.d emon.co.uk> wrote:
                >[color=green]
                >>JRS: In article <iuahs01klt55de qemlpncnqdfjivq rafsn@4ax.com>, dated
                >>Tue, 21 Dec 2004 23:27:10, seen in news:comp.lang. javascript, Ron Beitel
                >><ronb@not.her e> posted :
                >>[color=darkred]
                >>> To randomly select the next image use....
                >>>currImg = Math.round(Math .random()*maxIm g)[/color]
                >>
                >>Bad code - see FAQ.
                >>[/color]
                >
                >
                >Oops!
                >
                >What Doctor John is either to busy or to arrogant to explain
                >is my use of Math.round() instead of Math.floor().[/color]

                When you use Math.round in that manner, you are not choosing at random.
                The first and last options are only half as probable as the others.
                Choosing at random, which is what the OP asked for, and what your
                comment claims that you are doing, means that all possibilities must be
                substantially equi-probable.

                Posting an answer without a sufficient understanding of a newsgroup's
                regularly-posted FAQ shows either arrogance or ignorance.

                The regulars, of course, all know why it is bad code. The others should
                read the FAQ. That is why we have a FAQ.

                --
                © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
                <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                Comment

                • ron

                  #9
                  Re: slide-show (random images)? Sorry!



                  Sorry!

                  I should not have been so rude, but I was annoyed by your curt reply.
                  [color=blue][color=green][color=darkred]
                  >>>Bad code - see FAQ.[/color][/color][/color]

                  This was not that helpful. It is true, I just started visiting here
                  last week. And until I saw the footer on your reply, I did not know
                  where to find the FAQ. I must say they are very informative. I was
                  really impressed and bookmarked them. I am sure they will be a great
                  asset as I try to learn JavaScript.

                  Your explanation was much more helpful, and I immediately understood
                  the your point.
                  [color=blue]
                  >When you use Math.round in that manner, you are not choosing at random.
                  >The first and last options are only half as probable as the others.
                  >Choosing at random, which is what the OP asked for, and what your
                  >comment claims that you are doing, means that all possibilities must be
                  >substantiall y equi-probable.[/color]

                  Since, at first, I misunderstood your reasoning, perhaps my irritation
                  was justified. I thought your objection was the possibility of
                  Math.round(...) giving 25, while pix[25] did not exist. I was more
                  embarassed by this novice mistake, then the fact that the
                  nonsequential display of slides would not be statistically random.

                  Finally, I must object to the implication that only the masters may
                  contribute here. I alway found a seminar more stimulating then a
                  lecture. Certianly, this dialog has thought me two important
                  lessions--the proper way to find a random number and to keep my foot
                  out of my mouth. I only posted my solution, because a previous reply
                  indicated it was necessary to use some server-side technique. Since I
                  am currently writing a script to sequentially loop through a set of
                  images, I checked either Goodman's or Flaganan's book for
                  Math.random(), and quickly modified currImg++. In the future, I
                  promise to think, proof-read and test before posting. (That reminds
                  me, I need to take a red pen to that book. I'm sure the example used
                  Math.round())

                  Please accept my apology and thanks.

                  Ron

                  Comment

                  • Dr John Stockton

                    #10
                    Re: slide-show (random images)? Sorry!

                    JRS: In article <n9kms0d049kcsv dm6hpa1103j2fkm ttf53@4ax.com>, dated
                    Thu, 23 Dec 2004 23:08:51, seen in news:comp.lang. javascript, ron
                    <ron@bebop.in n> posted :[color=blue]
                    >
                    >I should not have been so rude, but I was annoyed by your curt reply.[/color]

                    Longwindedness is an American custom not favoured elsewhere.

                    --
                    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                    Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
                    PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
                    Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

                    Comment

                    Working...