473,396 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

random image Rotation

Hi there

I have been looking for a script that can randomly rotate 8
different images on 1 page. I used to have a script that
did this but can't find it now.
I have found loads of script that will load a differnet image
each time the page loads, or will rotate 1 image at a time,
but not one that can do 8 images from a list of images

Does anybody know of one?

Brian


--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 544 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Mar 10 '07 #1
7 4530
Brian wrote on 10 mrt 2007 in comp.lang.javascript:
I have been looking for a script that can randomly rotate 8
different images on 1 page. I used to have a script that
did this but can't find it now.
I have found loads of script that will load a differnet image
each time the page loads, or will rotate 1 image at a time,
but not one that can do 8 images from a list of images

Does anybody know of one?
Perhaps it wold be better, in this case of specialized taste,
if you build it from scratch.

Better in the sense that the code acts exactly as you wish,
and better n the sense that you learn from it,
and beter in the sense that you get pleasure and satisfaction from it.

You can use your "loads of script" to guide you.

If you really get stuck, this NG is a place for help.

===========

A good way to start is first to generate a random sequence
in an array that has the right length of your total number of pics.
Then take the top 8 for showing, then the next, etc.

However, there are many ways to Rome, and it wasn't build in one day.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 10 '07 #2
In comp.lang.javascript message <Ln******************@newsfe3-win.ntli.n
et>, Sat, 10 Mar 2007 03:13:47, Brian <br***********@nrwp.co.ukposted:
>
I have been looking for a script that can randomly rotate 8
different images on 1 page. I used to have a script that
did this but can't find it now.
I have found loads of script that will load a differnet image
each time the page loads, or will rotate 1 image at a time,
but not one that can do 8 images from a list of images

Does anybody know of one?
<URL:http://www.merlyn.demon.co.uk/js-randm.htm#IRSSwill instruct you.

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Mar 10 '07 #3
Evertjan wrote
Perhaps it wold be better, in this case of specialized taste,
if you build it from scratch.

Better in the sense that the code acts exactly as you wish,
and better n the sense that you learn from it,
and beter in the sense that you get pleasure and satisfaction from it.

You can use your "loads of script" to guide you.

If you really get stuck, this NG is a place for help.

Hi there

Well I have spent the day trying to write my first javescript, and well its
sort of working,
I'm trying to make it a little neater but I can't work out what's wrong.

I'm trying to change this

imgnum = Math.floor(Math.random()*theimages.length)
document.images.img1.src = theimages[imgnum].src
imgnum = Math.floor(Math.random()*theimages.length)
document.images.img2.src = theimages[imgnum].src
imgnum = Math.floor(Math.random()*theimages.length)
document.images.img3.src = theimages[imgnum].src

to this

for (i=0;i<theimages.length;i++){
imgnum = Math.floor(Math.random()*slideimages.length)
document.images.slide[i].src = slideimages[imgnum].src
}

but it's not working, and I can't work out why, I have posted all the
code below, any help would be great

thanks

Brian

<script language="JavaScript">
<!--
var theimages = new Array()
var thelinks = new Array()

function imagelist(){
for (i=0;i<imagelist.arguments.length;i++){
theimages[i] = new Image()
theimages[i].src = imagelist.arguments[i]
}
}

function linklist(){
for (i=0;i<linklist.arguments.length;i++)
thelinks[i]=linklist.arguments[i]
}

function openurl(){
location.href = thelinks[urllink]
}
//-->
</script>

<a href="javascript:openurl()"><img src="image1.jpg" name="img1" width="150"
height="150" border=0 id="img1"></a>
<a href="javascript:openurl()"><img src="image2.jpg" name="img2" width="150"
height="150" border=0 id="img2"></a>
<a href="javascript:openurl()"><img src="image3.jpg" name="img3" width="150"
height="150" border=0 id="img3"></a></p>

<script>
<!--
imagelist("image1.jpg", "image2.jpg", "image3.jpg")
linklist("http://www.site1.com", "http://www.site2.com",
"http://www.site3.com")

var speed=1000
var whichimage=0
var imgnum = 0
function chnageimages(){
if (!document.images)
return
for (i=0;i<theimages.length;i++){
imgnum = Math.floor(Math.random()*slideimages.length)
document.images.img[i].src = slideimages[imgnum].src
}
imgnum = Math.floor(Math.random()*theimages.length)
document.images.img1.src = theimages[imgnum].src
imgnum = Math.floor(Math.random()*theimages.length)
document.images.img2.src = theimages[imgnum].src
imgnum = Math.floor(Math.random()*theimages.length)
document.images.img3.src = theimages[imgnum].src

urllink = imgnum

setTimeout("chnageimages()",speed)
}
chnageimages()
//-->
</script>

--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 615 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Mar 11 '07 #4
Brian wrote on 11 mrt 2007 in comp.lang.javascript:
Hi there

Well I have spent the day trying to write my first javescript, and
well its sort of working,
I'm trying to make it a little neater but I can't work out what's
wrong.
I seem to remember I wrote the following:
A good way to start is first to generate a random sequence
in an array that has the right length of your total number of pics.
Then take the top 8 for showing, then the next, etc.
So let's start [NOT TESTED],
you can position the imgs later with absolute css:

<img id='p0' src=''><br>
<img id='p1' src=''><br>
<img id='p2' src=''><br>
<img id='p3' src=''><br>
<img id='p4' src=''><br>
<img id='p5' src=''><br>
<img id='p6' src=''><br>
<img id='p7' src=''><br>

<script type='text/javascript'>

var a = []; // array
var max = 100; // number of pics
for (var i=0;i<max;i++)
a[i]=i; // fill with numbers 0 - 99
for (var i=0;i<max*3;i++) {
n1 = Math.floor(Math.random()*max);
n2 = Math.floor(Math.random()*max);
// never mind if some swap with themselves
temp = a[n1];
a[n1] = a[n2];
a[n2] = temp; // swap the numbers at random
};

// "a" is now a reasonable random sequence array of 100 unique numbers

var where = 0; // sequence pointer

function fill8(){
for (var i=0;i<8;i++){
document.getElementById("p"+i).src = // fill p0 - p7
"/images/myImageNr" + a[where] + ".jpg"; // with the next random 8
where = (where < max-1) ? where+1 : 0; // increment the pointer
circular
};
setTimeout('fill8()',6000); // next change 6 seconds in future
};

fill8(); // start, or do this in body onload

</script>

If you have made this wokring,
I am sure to have made some silly mistakes,
you can add preloading.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 11 '07 #5
ASM
Brian a écrit :
>
for (i=0;i<theimages.length;i++){
imgnum = Math.floor(Math.random()*slideimages.length)
document.images.slide[i].src = slideimages[imgnum].src
}

but it's not working, and I can't work out why, I have posted all the
code below, any help would be great
for (i=0;i<theimages.length;i++){
imgnum = Math.floor(Math.random()*slideimages.length)
document.images.['img'+i].src = slideimages[imgnum].src
}

but ... in your example bellow
for your array of images you don't use 'slideimages' but 'theimages'
<script language="JavaScript">
<!--
var theimages = new Array()
var thelinks = new Array()

function imagelist(){
for (i=0;i<imagelist.arguments.length;i++){
theimages[i] = new Image()
theimages[i].src = imagelist.arguments[i]
}
}

function linklist(){
for (i=0;i<linklist.arguments.length;i++)
thelinks[i]=linklist.arguments[i]
}
this one is curious :
function openurl(){
location.href = thelinks[urllink]
}
after changing images the 3 links will send to same url
on each call of chnageimages()
//-->
</script>

<a href="javascript:openurl()"><img src="image1.jpg" name="img1" width="150"
height="150" border=0 id="img1"></a>
<a href="javascript:openurl()"><img src="image2.jpg" name="img2" width="150"
height="150" border=0 id="img2"></a>
<a href="javascript:openurl()"><img src="image3.jpg" name="img3" width="150"
height="150" border=0 id="img3"></a></p>

<script>
<!--
imagelist("image1.jpg", "image2.jpg", "image3.jpg")
linklist("http://www.site1.com", "http://www.site2.com",
"http://www.site3.com")

var speed=1000
var whichimage=0
var imgnum = 0
function chnageimages(){
if (!document.images)
return
for (i=0;i<theimages.length;i++){
imgnum = Math.floor(Math.random()*slideimages.length)
imgnum = Math.floor(Math.random()*theimages.length)
document.images['img'+(+1+i)].src = theimages[imgnum].src;
// or :
// document.images[i].src = theimages[imgnum].src;
document.links[i].href = thelinks[imgnum];
}
setTimeout("chnageimages()",speed)
}
chnageimages()
//-->
</script>


--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Mar 11 '07 #6
In comp.lang.javascript message <Xn********************@194.109.133.242>
, Sun, 11 Mar 2007 21:11:47, Evertjan. <ex**************@interxnl.net>
posted:
>var a = []; // array
var max = 100; // number of pics
for (var i=0;i<max;i++)
a[i]=i; // fill with numbers 0 - 99
for (var i=0;i<max*3;i++) {
n1 = Math.floor(Math.random()*max);
n2 = Math.floor(Math.random()*max);
// never mind if some swap with themselves
temp = a[n1];
a[n1] = a[n2];
a[n2] = temp; // swap the numbers at random
};

// "a" is now a reasonable random sequence array of 100 unique numbers
One can do better than that, by following a link in the FAQ.

function Deal(N) { var J, K, Q = new Array(N)
for (J=0; J<N; J++) { K = Random(J+1) ; Q[J] = Q[K] ; Q[K] = J }
return Q }

That, with minimum effort, and assuming that Math.random is perfect,
generates any of the possible sequences with exactly equal probability;
yours does not give exactly equal probability, only very nearly so, and
takes longer. Note that Random(1) is used.
But the OP does not want all of that array; there is no need to
randomise the order of the unwanted elements.

function PickSubsetSequenced(Q, M) { var J, K, L = Q.length, T
for ( K = L ; K L-M ; K-- ) { J = Random(K)
T = Q[K-1] ; Q[K-1] = Q[J] ; Q[J] = T }
return Q.slice(L-M) }
The OP probably wants the first 8 images to be chosen at random, but
different; and to be replaced after an interval by another 8 similarly
chosen but perhaps required to be different. Alternatively, after
loading the first 8 "instantly", the replacements might occur one at a
time or in rapid sequence.

By using the method of "Indefinite Random Slide Show" and writing in
turn to each of the 8 positions in order at appropriately-varying
intervals including nominal zero[*], many likely possibilities can be
achieved (including making changes at random intervals).

var J = 0, Delay = [10,10,10,10,10,10,10,3000]
function Go() { // untested
Image[J] = next-one
setTimeout("Go()", Delay[J]
J = (J+1)%8 }

Random sequences should not be generated with a method chosen at random;
they should be generated by a method chosen from Knuth.

[*] Has any difficulty been reported with setTimeout(xxx, 0) ? If so,
use a delay of say 10.

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Mar 12 '07 #7
Thanks for all your help guys, i have it working now :)

Brian

--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 723 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Mar 13 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Deepa | last post by:
Hi All, I'm facing problem displaying image of size 5000X5000 .My window size is smaller than image size so i'm not able to see the complete image.i can use scroll bars to view the image but i...
2
by: Novice Computer User | last post by:
If you can help me, I'd be grateful. Long story short... I am looking for cut/paste html code (that even a dummy like me can't screw up). Here is what I want: I want a web page to display ten...
17
by: santel_helvis | last post by:
Hi All, Could anyone tell me how to rotate the image in javascript. Which concepts I should concentrate to rotate the image
3
by: Mark Szlazak | last post by:
The following page simulates a pool cue and cue ball: http://members.aol.com/myscript/cue.html Mouse cursor position around the cue ball determines where a roll-over of 179 pool cue images is...
5
by: Ricardo Furtado | last post by:
I'm trying, for a week or two, to create a procedure in order to rotate the image in any picturebox control in a cephalometry software. I've found a web site that shows how that can be done:...
10
by: Joey_Stacks | last post by:
Does anyone know of a scipt that will rotate random div layers on page refresh? I have a primary content area front and center on my site homepage, and I'd like to rotate various chunks of html...
9
by: Ohann | last post by:
Hi I have a page with 9 images on, each one placed within a table cell. I want to be able to have a different image displayed each time the page is refreshed as well as being able to have the...
3
by: kimiraikkonen | last post by:
Hi, Here is a very interesting issue, Assume i have picturebox and loaded a image into picturebox, however whenever i want to rotate image using: 'For example 90 degree...
8
by: infoseekar | last post by:
Image Resize & Rotation Hi I have 2 scripts, one for Image rotation and other image resize and they both are working. Image resize scripts load the picture and resize it and Image rotation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.