By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,508 Members | 1,823 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,508 IT Pros & Developers. It's quick & easy.

slide-show (random images)?

P: n/a
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?

Jul 23 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Michael Burtenshaw wrote:
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?

www.dynamicdrive.com

I thought 250.com went out of the hosting business.
Since I now get a website for "micropatent".
Jul 23 '05 #2

P: n/a
Michael Burtenshaw wrote on 19 dec 2004 in comp.lang.javascript:
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?


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)
Jul 23 '05 #3

P: n/a
On Sun, 19 Dec 2004 00:02:18 -0500, Mi***************@webtv.net
(Michael Burtenshaw) wrote:
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?

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()*maxImg)
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_Random.html ******

<html>
<head>

// ron beitel, 20 Dec 2004

<script language="JavaScript">

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(max) {
for (i=0;i<max;i++) {
pix[i] = new Image()
pix[i].src = "http://250.com/yourPath/image_" + i + ".jpg"
}

nxtSlide()
}

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

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

function stop() {
clearTimeout(tid)
}

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

</script>

</head>

<body onLoad="preloadImgSet(maxImg)">
<table border>
<tr><td colspan=2 align=center>
<h2>My Slide Show</h2>
<h3>Loop or Step Randomly</h3>
</td></tr>

<tr><td><table 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>


Jul 23 '05 #4

P: n/a
On Sun, 19 Dec 2004 00:02:18 -0500, Mi***************@webtv.net
(Michael Burtenshaw) wrote:
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?

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
Jul 23 '05 #5

P: n/a
JRS: In article <iu********************************@4ax.com>, dated
Tue, 21 Dec 2004 23:27:10, seen in news:comp.lang.javascript, Ron Beitel
<ro**@not.here> posted :
To randomly select the next image use....
currImg = Math.round(Math.random()*maxImg)


Bad code - see FAQ.

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

P: n/a
On Wed, 22 Dec 2004 14:31:03 +0000, Dr John Stockton
<sp**@merlyn.demon.co.uk> wrote:
JRS: In article <iu********************************@4ax.com>, dated
Tue, 21 Dec 2004 23:27:10, seen in news:comp.lang.javascript, Ron Beitel
<ro**@not.here> posted :
To randomly select the next image use....
currImg = Math.round(Math.random()*maxImg)


Bad code - see FAQ.

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((Math.random() % 1) * maxImg)


Jul 23 '05 #7

P: n/a
JRS: In article <v5********************************@4ax.com>, dated
Thu, 23 Dec 2004 02:10:58, seen in news:comp.lang.javascript, Ron
Beitel <ro**@not.here> posted :
On Wed, 22 Dec 2004 14:31:03 +0000, Dr John Stockton
<sp**@merlyn.demon.co.uk> wrote:
JRS: In article <iu********************************@4ax.com>, dated
Tue, 21 Dec 2004 23:27:10, seen in news:comp.lang.javascript, Ron Beitel
<ro**@not.here> posted :
To randomly select the next image use....
currImg = Math.round(Math.random()*maxImg)


Bad code - see FAQ.

Oops!

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


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.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #8

P: n/a
ron


Sorry!

I should not have been so rude, but I was annoyed by your curt reply.
Bad code - see FAQ.

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.
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.


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

Jul 23 '05 #9

P: n/a
JRS: In article <n9********************************@4ax.com>, dated
Thu, 23 Dec 2004 23:08:51, seen in news:comp.lang.javascript, ron
<ro*@bebop.inn> posted :

I should not have been so rude, but I was annoyed by your curt reply.


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.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.