variables + loops using web audio api and jquery - javascript

here's a link to something I've been working on
http://79.170.40.170/johnhartmanportfolio.com/
and a couple of notes
I built a simple 3 band graphic eq and am currently hooking up the filters.
if you click the green button a sine wave will play; the red button will stop it.
if you move any fader (any direction)the low pass filter will tick down (if you open console i am outputting the current filter value to the log)
the problem: I am using if loops to compare the values the problem is once I reach 0 it's kind of like my other loop never gets looked at. I don't know what I am doing wrong perhaps an if loop is not appropriate? that being said its made me revisit assignment and operators but I'm still stuck any help would be much appreciated.
(just the js)
$(document).ready(function() {
var context = new AudioContext();
var oscillator = context.createOscillator();
var volume = context.createGain();
var biquadFilter = context.createBiquadFilter();
biquadFilter.type = "lowshelf";
var eqValue = 1000;
biquadFilter.frequency.value = eqValue;
biquadFilter.gain.value = 1;
volume.gain.value = 0;
oscillator.start(0)
$("#playButton").click(function() {
oscillator.connect(volume);
volume.connect(biquadFilter)
biquadFilter.connect(context.destination);
volume.gain.value = 1;
});
$("#stopButton").click(function() {
volume.gain.value = 0;
});
$(".faderStyle").on("slide", function() {
if (eqValue = 0) {
biquadFilter.frequency.value += 10;
console.log(biquadFilter.frequency.value)
}
if (eqValue = 1000) {
biquadFilter.frequency.value -= 10;
console.log(biquadFilter.frequency.value)
return (eqValue);
}
return (eqValue)
});
$(".faderStyle").slider({
orientation: "vertical",
range: "min",
min: 0,
max: 1000,
value: 60
});
});

Your if's should use either == or === for comparison.
The equals operator will always set your variable's value, which is not what you want.
eqValue = 0 will always evaluate as false and should be eqValue === 0
eqValue = 1000 will always evaluate as true and should be eqValue === 1000

Related

Node terminal animation is not working (it's only showing the first two items in the array)

I am trying to create a terminal animation for a CLI about food. While one of my requests is being made, I wanted to run a loading animation until the promise is resolved. The animation is composed of two arrays, one representing a person opening and closing their mouth and the other is the "sandwich" (a bunch of equals signs) that is to be eaten. See below.
var face = [":D", ":|"];
var sandwich = ['======', '=====', '====', '===', '==', '='];
I am using setInterval to increment the values of x and y (which represent the indexes of their respective arrays) until they reach a threshold. For face that threshold is 1 (since first index is 0) and for sandwich it is 5.
What I want to happen is as the values of x/y are incremented, the next item in their respective arrays is written out to the console. See the code below.
const muncher = () =>{
var face = [":D", ":|"];
var sandwich = ['======', '=====', '====', '===', '==', '='];
var x = 0;
var y = 0;
return setInterval(() => {
process.stdout.write("\r" + face[x++] + sandwich[y++]);
x &= 1;
y &= 5;
}, 250);
};
Once y is 5 and x is 1, they should go back to 0 and start the incrementing over again. Rather than the sandwich becoming less and less each time (======... =====... ====... etc) but it appears both arrays just toggle between the first and second element. For sandwich it looks like this: ====== and =====. I also tried making the arrays of equal length and having x and y be the same number but it still isn't working.
My problem is occurring within node but I adapted it to browser JS in the snippet to better illustrate my issue.
var targ = document.getElementById('muncher');
const muncher = () => {
var face = [":D", ":|"];
//also tried var face = [":D", ":|", ":/", ":o", ":D", ":|"];
var sandwich = ['======', '=====', '====', '===', '==', '='];
var x = 0;
var y = 0;
return setInterval(() => {
targ.innerText = "\r" + face[x++] + sandwich[y++];
x &= 1;
// also tried x&= 5 when face is the same length as sandwich
y &= 5;
}, 250);
};
muncher()
<div id='muncher'>
</div>
I guess your problme is the bitwise operator which is changing the value of x and y to 0 and 1 respectively. Something like this should work
var targ = document.getElementById('muncher');
const muncher = () => {
var face = [":D", ":|"];
//also tried var face = [":D", ":|", ":/", ":o", ":D", ":|"];
var sandwich = ['======', '=====', '====', '===', '==', '='];
var x = 0;
var y = 0;
return setInterval(() => {
targ.innerText = "\r" + face[x++] + sandwich[y++];
x = x > 1 ? 0 : x;
y = y > 5 ? 0 : y;
}, 250);
};
muncher()
<div id="muncher"/>
As a second option, you can try this package I've created:
https://github.com/ErAz7/Termination
First install the package (npm i termination or yarn add termination), then with this code you can achieve what you want (with a better animation loop):
SEE DEMO HERE
const { Animation } = require('termination');
const personFrames = [':|', ':D'];
const createObject = (x, y, content, color) => animation.add({
x: x,
y: y,
content: content,
replaceSpace: true,
color: color,
});
const animation = new Animation({
maxSize: {
width: 10,
height: 1,
},
});
const sandwich = createObject(8, 0, '======', 'yellow');
const person = createObject(0, 0, personFrames[0], 'green');
const personFramesTransition = person.transition([
{
props: { content: personFrames[1] },
duration: 100
}
], { loop: true, alternate: true });
const sandwichMoveTransition = sandwich.transition([
{
props: { x: -8, y: 0 },
func: 'linear',
duration: 1400
}
], { loop: true, loopInterval: 100 });
animation.start();
personFramesTransition.run();
sandwichMoveTransition.run();
This is a little longer but offers much more control over animation properties.
the package supports
promise based tranition
easing transition functions
looped transition
frame rate control
playback speed control
canvas size options
colors
and some other useful features to create animations on terminal

this.functionName is not a function error

I am writing a simulation for bunny survival in a meadow and have to detect the minimal plant growth rate for the bunny to survive. I decided to go with OOP. Hence, tried to design my "classes" in js. I haven't done much OOP in JS, so I am stuck. I don't understand why I keep getting "this.checkElementExists" is not a function.
I tried to follow OOP that was shown in Mozilla MDN for JS and here I am stuck. I updated to ES6 classes.
class Meadow{
constructor(){
this.grid = this.makeGrid();
//console.log(this.grid);
}
makeGrid(){
let grid = new Array(30);
for(var i=0; i < 30; i++){
grid[i] = new Array(30).fill(null);
}
return grid;
}
checkElementExists(coordinates){
if(this.grid[coordinates[0]][coordinates[1]] != null){
return true;
}else{
return false;
}
}
growAPlant(timeRate){
if(timeRate == null){
clearInterval(this.growAPlant);
}
let plant = new Plant();
let coord = plant.generateCoordinateInMeadow();
//console.log(coord);
// add a plant to the 2d array, but check if the that spot is free
// otherwise use the generateCOordinate in the meadow function
//console.log(this.grid[coord[0]][coord[1]]);
//var that = this;
var ans = checkElementExists(coord).bind(this);
console.log(ans);
while(!checkElementExists(coord)){
coord = plant.generateCoordinateInMeadow();
}
//console.log(coord);
//console.log(this.grid[coord[0]] == undefined);
this.grid[coord[0]][coord[1]] = plant;
//console.log(this.grid);
}
}
class Simulation{
constructor(){
this.passRateArray = []; // this array will be used to plot the data
this.failureRateArray = []; // array that will hold failure growth rates
this.timeToEnergyData = []; // an example would be [{0: 1000, 1: 999, 2: 998, ....., 10000: 0}]
this.rateToEnergyTimeData = {};
this.timeCounter = 100; // 10000
this.growthTimeRate = 1000; // 1 second
this.gap = 0.05;
this.meadow = new Meadow();
this.bunny = new Bunny();
}
timeToEnergyDataPopulator(currTime, energy){
var relation = {currTime : energy};
this.timeToEnergyData.push(relation);
}
simulation(){
// HERE I MAKE A CALL TO MEADOW.GROWAPLANT
setInterval(this.meadow.growAPlant.bind(this.meadow), this.growthTimeRate);
//meadow.growAPlant(this.growthTimeRate);
let bunnyMove = this.bunny.move();
// not enough energy, bunny did not survive
if(bunnyMove == false){
this.timeToEnergyDataPopulator(this.timeCounter, bunny.getBunnyEnergy());
let rate = this.growthTimeRate / 1000;
this.rateToEnergyTimeData = {rate : this.timeToEnergyData};
// add the failure rate to the failureRateArray
this.failureRateArray.push(this.growthTimeRate);
// increase the rate of plant growth
if(this.passRateArray.length < 1){
this.growthTimeRate = this.growthTimeRate + this.growthTimeRate * 0.5;
}else{
let lastSurvivalRate = this.passRateArray[this.passRateArray.length - 1];
this.growthTimeRate = lastSurvivalRate - ((lastSurvivalRate - this.growthTimeRate)*0.5);
}
// stop the meadow from growing a plant
meadow.growAPlant(null);
// stop the simulation
clearInterval(this.simulation);
}
while(!this.meadow.checkValidBunnyMove(bunnyMove).bind(this.meadow)){
bunnyMove = bunny.move();
}
if(meadow.checkIfBunnyEats(bunnyMove)){
// since bunny made still a move, -1 energy
bunny.decreaseEnergyByOne();
// and since the meadow at that coordinate had food, we add +10 to energy via eatPlant method
bunny.eatPlant();
// track the time to energy data
this.timeToEnergyDataPopulator(this.timeCounter, bunny.getBunnyEnergy);
}else{
// no food, -1 energy
bunny.decreaseEnergyByOne();
// track the time to energy data
this.timeToEnergyDataPopulator(this.timeCounter, bunny.getBunnyEnergy);
}
// decrement the timeCounter
this.timeCounter -= 1;
if(this.timeCounter <= 0){
this.timeToEnergyDataPopulator(this.timeCounter, bunny.getBunnyEnergy());
let rate = this.growthTimeRate / 1000;
this.rateToEnergyTimeData = {rate : this.timeToEnergyData};
this.passRateArray.push(this.growthTimeRate);
// bunny survived, adjust the growth rate
if(this.failureRateArray.length < 1){
this.growthTimeRate = this.growthTimeRate - (this.growthTimeRate * 0.5);
}else{
let lastFailureRate = this.failureRateArray[this.failureRateArray.length - 1];
this.growthTimeRate = this.growthTimeRate - ((this.growthTimeRate - lastFailureRate) * 0.5);
}
clearInterval(this.simulation);
}
}
runner(){
while(this.passRateArray[this.passRateArray.length - 1] - this.failureRateArray[this.failureRateArray.length - 1] > this.gap || this.passRateArray.length == 0 || this.failureRateArray.length == 0){
setInterval(this.simulation(), 1000);
}
console.log("The minimum plant regeneration rate required to sustain the bunny for 10000 units of time is " +
this.growthTimeRate + " regenerations/unit time");
}
}
Errors that I get:
1) simulation.js:62 Uncaught TypeError: this.meadow.checkValidBunnyMove is not a function
at Simulation.simulation (simulation.js:62)
at Simulation.runner (simulation.js:101)
at (index):24
2) meadow.js:1 Uncaught SyntaxError: Identifier 'Meadow' has already been declared
at VM16689 meadow.js:1
3) VM16689 meadow.js:37 Uncaught ReferenceError: checkElementExists is not defined
at Meadow.growAPlant (VM16689 meadow.js:37)
My question is why the number 1 and 3 errors persist?
clearInterval(this.growAPlant);
This clearInterval isn’t correct, because you need pass the return value of setInterval to it, not a function. It does helpfully imply that you have a setInterval(someMeadow.growAPlant, …) somewhere, though, and that’s where the issue is. When you reference a function without calling it – like when you pass it to setInterval – the object it belonged to doesn’t come with it. Then, when the timer fires, it calls the function without a this value.
In JavaScript, the value of this inside a non-arrow function is determined entirely by how the function is called, not where it’s declared. You can read about how this works in various other questions and pieces of documentation. Fixing the problem involves giving growAPlant the correct this somehow, either by:
placing a reference to it in a containing scope (i.e. moving your var that = this out one level and using that instead of this throughout)
wrapping the function in one that’ll preserve the correct value, as in
setInterval(someMeadow.growAPlant.bind(someMeadow), …);
(Function.prototype.bind) or
setInterval(function () {
someMeadow.growAPlant();
}, …);
(the someMeadow.growAPlant reference is now part of a call, so someMeadow becomes the this value for the call)
changing it into an arrow function, which doesn’t have its own this and uses the one from the containing scope
Only (2) will work when you convert to the simplest form of an ES6 class, so it’s the approach I recommend.
Explanation
First, this always refers to the first parent function. In your case it is:
this.growAPlant = function(timeRate){
//content
var that = this; // this is growAPlant
}
And
this.checkElementExists = function(coordinates){ }
Is accessible with Meadow object. However, your var that is referring to this.growAPlant = function(timeRate) not Meadow.
Solution
Create that in the beginning
function Meadow(){
var that = this;
that.growAPlant = function(timeRate){
}
that.checkElementExists = function(coordinates){
if(this.grid[coordinates[0]][coordinates[1]] != null){
return true;
}else{
return false;
}
};
return that;
}

Why won't this loop?

I have written a javascript program that changes the picture on a header, waits, then shows the next one.
I have tried to make it loop round back to 1 when it reaches the last picture, but it's not working, the computer keeps crashing and I'm really stuck.
Later on it's going to have options to fade and have different transitions, but right now, I can't even get the function to loop forever without crashing the computer.
Can anyone offer a solution?
Thank you,
Andrew
var $initialDelay = 0;
var $delay = 200;
var $picture = 1;
var $pictureAmount = 4;
function myFunction() {
//first picture loaded in CSS
//loop through pictures
for (i=0;i<$pictureAmount;i++) {
setTimeout(function(){
document.getElementById("header").style.backgroundImage = "url(img/slideshow/slideshow"+$picture+".jpg)";
$picture++;
}, $initialDelay);
$initialDelay += $delay;
}
}
myFunction();
If you want this to continuously change picture every 200ms
var delay = 200;
var picture = 1;
var pictureAmount = 4;
function myFunction() {
setTimeout(function() {
document.getElementById("header").style.backgroundImage = "url(img/slideshow/slideshow" + picture + ".jpg)";
picture = (picture % pictureAmount) + 1;
myFunction();
}, delay);
}
myFunction();
Here is an example for looping over a 4 images with a timeout. I think you should be able to use this in your code to do what you want.
const
delayBetweenPictures = 1000,
numberOfPictures = 4,
initialPicture = 1,
image = document.getElementById('slideshow');
function changeToPicture(pictureIndex) {
console.log(`Changing picture to index ${pictureIndex}`);
// Change the image
image.src = `http://lorempixel.com/320/200/cats/${pictureIndex}`;
// Use a modulo operator to turn 4 (number of pictures) back to 0 and add 1 so the range becomes 1...number of pictures.
pictureIndex = (pictureIndex % numberOfPictures) + 1;
// Set a timeout of X ms after which the changeToPicture method is called again, this time with the new value of pictureIndex.
setTimeout((newIndex) => changeToPicture(newIndex), delayBetweenPictures, [pictureIndex]);
}
changeToPicture(initialPicture);
<img id="slideshow">
By using the modulo operation you can loop between the values 1 to 4 over and over.
It would be easier if your pictures were "0-indexed" :
for (i=0; /* infinite loop */; i=(i+1)%$pictureAmount) {
// loops through 0, 1, ..., $pictureAmount - 1
}
but can be adjusted for a 1-indexed iteration :
for (i=1; /* infinite loop */; i=(i%$pictureAmount)+1) {
// loops through 1, 2, ..., $pictureAmount
}
Example iteration over 1 to 9 :
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function loop() {
for (i=1; /* infinite loop */; i=(i%9)+1) {
document.getElementById("view").innerHTML=i;
await sleep(1000);
}
}
loop();
<p id="view"></p>

shuffling cards with Javascript and inconsistent array values?

I'm building a little module in javascript to act like a pack of cards. My first method works but was quite simple, and so i wanted to create some shuffle methods that mimic the idea behind real world card shuffling.
Amongst some other useful functions I've create riffle, overhand and cut functions, that all seem to do there job, but when calling them repeatedly in sequence the returned pack amount is inconsistent, from running it over and over again it appears to be some sort of race condition, but can't seem to get my head around how to avoid it.
The relevant private methods are :
riffle : function riffle() {
var top = Pack.slice(0, 26);
var bottom = Pack.slice(26, 52);
Pack = [];
console.log('top is '+top.length+" and bottom is "+bottom.length);
var hand = 'right';
var result = [];
var i = 52;
while (i > 0) {
var drop = Math.floor(Math.random()*3)+1;
var cards;
if (hand === 'right' ) {
if (drop >= top.length) {
cards = top;
} else {
cards = top.splice(0, drop);
}
hand = 'left';
} else {
if (drop >= bottom.length) {
cards = bottom;
} else {
cards = bottom.splice(0, drop);
}
hand = 'right';
}
result = result.concat(cards);
i -= drop;
}
Pack = result;
console.log(Pack.length+" after riffle");
return this;
},
cut : function cut(fn) {
var top = Pack.slice(0, 26);
var bottom = Pack.slice(26, 52);
Pack = [];
console.log(top);
Pack = bottom.concat(top);
console.log(Pack.length+" after cut");
if (fn && typeof(fn) === 'function') { fn(); }
return this;
}
Later on I have a privileged method called shuffle that calls them :
shuffle : function shuffle(cb) {
State.cardsOut = [];
Internal.generatePack().cut().riffle().riffle()
.riffle().riffle().riffle();
if (cb && typeof(cb) === 'function') { cb(); }
}
Note : I start with a generate function that creates an arrray of objects representing a full pack of 52 cards. The results I get when I console log the pack at different times after shuffles and cuts vary and I can't seem to figure out why.
you can see what i'km working on here
https://gist.github.com/Pushplaybang/66bc7a1fa5d84eee2236
Any help would be awesome.
The drop variable stores the number of cards you are supposed to be riffling from either the left or right hand. However, there are two instances:
if (drop >= top.length) {
cards = top;
}
and
if (drop >= bottom.length) {
cards = bottom;
}
where drop can be greater than the number of remaining cards in the half of the pack so more cards will be subtracted from i than you have actually riffled. You can fix this by:
if (drop >= top.length) {
drop = top.length;
cards = top;
top = [];
}
and
if (drop >= bottom.length) {
drop = top.length;
cards = bottom;
bottom = [];
}
(You need to empty the arrays or you may end up adding the same cards twice).
Other issues
You have magic numbers in the code (26 and 52) these could be constants defined in the class and given appropriate names (i.e. PACK_SIZE = 52) which would mean that if you create a sub-class representing a different number of cards then it would still work.
hand has two possible values which could be represented as a boolean but you assign it strings (again you could use constants LEFT_HAND = true, RIGHT_HAND = !LEFT_HAND).
Pack appears to be a global variable - I would have thought it ought to be a member of the class.
You do not need to name the functions as this is just polluting the global namespace: riffle : function riffle() { can just be an anonymous function riffle : function() {.
Performance - you create additional arrays with each iteration and the cards are moved multiple times. This could be more efficient.
Something like this:
PACK_SIZE: 52,
riffle : function() {
var index_of_cards_riffled_from_top = 0;
var index_of_cards_riffled_from_bottom = this.PACK_SIZE / 2;
var riffled_cards = [];
while ( index_of_cards_riffled_from_top < this.PACK_SIZE / 2
|| index_of_cards_riffled_from_bottom < this.PACK_SIZE ) {
var num_cards_to_riffle_top = Math.min( this.PACK_SIZE / 2 - index_of_cards_riffled_from_top, Math.floor( Math.random() * 3 ) + 1 );
var num_cards_to_riffle_bottom = Math.min( this.PACK_SIZE - index_of_cards_riffled_from_bottom, Math.floor( Math.random() * 3 ) + 1 );
while ( num_cards_to_riffle_top > 0 ) {
riffled_cards.push( this.Pack[ index_of_cards_riffled_from_top++ ] );
num_cards_to_riffle_top--;
}
while ( num_cards_to_riffle_bottom > 0 ) {
riffled_cards.push( this.Pack[ index_of_cards_riffled_from_bottom++ ] );
num_cards_to_riffle_bottom--;
}
}
this.Pack = riffled_cards;
}
while #MTO 's answer did solve my problem, I'd like to shed some light on how I've chosen to begin refactoring this function.
riffle : function riffle() {
var cutPos = Math.floor(Math.random()*rv)+( (cardCount-rv) / 2 );
var splitPack = {
left : Pack.splice(0, cutPos),
right : Pack.splice(0, Pack.length)
};
var hand = 'right',result = [], i = 52, cards;
while(i > 0) {
drop = Math.floor(Math.random()*3)+1;
if (drop >= splitPack[ hand ].length) {
drop = splitPack[ hand ].length;
}
cards = splitPack[ hand ].splice(0, drop);
hand = (hand === 'left') ? 'right' : 'left';
result = result.concat(cards);
cards = [];
i -= drop;
}
Pack = result;
console.log(Pack.length+" after riffle");
return this;
},
a few things :
the elements that seem global are not really, as this is all wrapped within a function that creates a new "deck" object, and some elements need to be private, such as the cards remaining in the pack once dealing has begin.
While booleans would work well for the hands, I wanted to boil this down somewhat and so use the strings to select obj properties.
everything MTO said about using constants is absolutely valid.
by now splicing each time, we're removing the elements from the array.
I prefer this approach as it only uses one while loop.
lastly, this type of shuffle is meant to emulate hand shuffling, and must be combined with other hand shuffling methods, ideally in a repetitive sequence, to produce something useful,
if you want something consistently random and efficient use fischer-yates algorithm.

changing images automatically with javascript

I have the current JavaScript problem. I have four divisions next to each other on my website that constantly rotate images on a 10 seconds interval. I need these intervals to keep rotating images at the current interval but start 5 seconds apart from each other in order to obtain a nice waterfall effect. How can I accomplish this using JavaScript?
image of how it looks on my websites' header
This is an example of the code I am currently using to display a single division and handle the rotation of the images.
<div class = "TestRotator">
<img src="http://bushveld.info/wp-content/uploads/2013/07/image1.png" alt="rotating" width="100" height="232" id="rotator">
<script type="text/javascript">
(function () {
var rotator = document.getElementById('rotator'); // change to match image ID
var imageDir = 'http://bushveld.info/wp-content/uploads/2013/07/';
var delayInSeconds = 5;
// set number of seconds delay
// list image names
var images = ['image2.png', 'image3.png', 'image4.png'];
var num = 0;
var changeImage = function () {
var len = images.length;
rotator.src = imageDir + images[num++];
if (num == len) {
num = 0;
}
};
setInterval(changeImage, delayInSeconds * 1000);
})();
</script>
</div>
I've fiddled it a lot! (I changed it big time.)
chenged setInterval() with setTimeout() and many others.
Is this what you wanted?
PS: state holds the 1st image to which the imgs change. and the difference in the timeout (200 milliseconds is in order to just to make some difference in between them, yuo can change it to a round number if you want to).
If I've understood your question correctly, you need something like this:
window.onload = function () {
var // Customable parameters
imageDir = 'http://bushveld.info/wp-content/uploads/2013/07/',
interval = 2, // Interval between "flushes" in seconds. Must be > speed * maxScreens
speed = 0.1, // "Flush" speed in seconds
maxScreens = 4, // amount of used image tags
images = 4, // amount of image sources, can be > maxScreens
dir = 1, // 1 = from left to right, -1 = from right to left
// Program
flush,
target = (dir > 0) ? 1 : maxScreens,
targetOrigo = target,
changeImage = function() {
var img = document.getElementById('rotator' + target),
id = parseInt(img.src.substr(img.src.length - 5, 1), 10) - dir;
if (id < 1) {
id = images;
}
if (id > images) {
id = 1;
}
img.src = imageDir + 'image' + id + '.png';
if (target !== maxScreens - targetOrigo + 1) {
target += dir;
setTimeout(changeImage, speed * 1000);
} else {
target = targetOrigo;
setTimeout(runRotation, interval * 1000);
}
return;
},
runRotation = function () {
setTimeout(changeImage, speed * 1000);
};
setTimeout(runRotation, 1000);
}
A live demo at jsFiddle
Notice, that I've put the function at window.onload, looks better when all the images are already loaded, before the rotation starts.
The snippet doesn't use setInterval() at all, instead it's based on nested setTimeout()s. This way you can avoid a mess, which you might get (depends on used browser), if user visits at other tab and then comes back to your site.
You can play with interval, "flush" speed, number of images you have on the rotation and even how many different images you like to use (max. = 9). You can also switch the direction of the rotation.
If you want to avoid two similar images to be shown at the same time, you can add image5.png to your image folder, and set images = 5.
Also version using an image source array available.
Thanx alot for the input. I solved this issue by adapting the code in this manner...
(function() {
var rotator3 = document.getElementById('rotator3'); // change to match image ID
var imageDir = 'http://bushveld.info/wp-content/uploads/2013/07/';
// set number of seconds delay
// list image names
var images = ['image2.png', 'image3.png', 'image4.png', 'image1.png'];
// don't change below this line
var num = 0;
var changeImage = function()
{
var len = images.length;
rotator3.src = imageDir + images[num++];
if (num == len)
{
num = 0;
}
};
function SwImg() {
var rotate = setInterval(changeImage, 20000);
}
setTimeout(SwImg,15000);
})();
This tweak basically creates an initial delay of 5++ seconds at each division with the standard 20 seconds delay interval between switches, rotating each image in each division 5 seconds after the other. Here is a link to the website , will be done end of this week. Thanks again for the input, really awesome and creative ways of solving this issue!
Cheers

Categories