bmoren / jQuery-Generative-Engines

Generative Engines for jQuery Projects
MIT License
1 stars 1 forks source link

added nonRepRand #8

Closed alex-carlson closed 8 years ago

alex-carlson commented 8 years ago

details:

I added your gist at the bottom of the js file.

the caveat is that it loops through the random order the same every time, aka:

3214 3214 3214.

On a refresh the order will randomize, so maybe you'll get

2143 2143 2143.

We could update the variable when it hits the end, but this might be better, because if we did that you could get something like

2134 4312 2431 1423

so you would get adjacent numbers, and thus not "feel" like non-repeating.

bmoren commented 8 years ago

This is the never ending issue with non-rep-rand, maybe try to implement your own approach directly in instead of basing it on my gist, that thing might be way overkill anyway?

b.

bmoren commented 8 years ago

on a second look, its looking you should take another stab at it

this section:

       if(stored_index == 0){
              $(this).children().eq(length-1).data('populate-next', true );
            }else{
              $(this).children().eq(stored_index-1).data('populate-next', true );
            }

            stored_index++;

            if(stored_index > $(this).children().length){
              stored_index = 0;
            }

i think should be something more like this:


var nextnonrep = nonrep.next()

$(this).children().eq( nextnonrep  ).data('populate-next', true );

the hard part of this is that since that non-rep is OOP we it will make a new instance of the class at each step.

~~~~~~~~~_~

I think the real approach should be to make another .data() attribute with an order that is generated eg:

forloop children.length{
     child.data("playback", nonrep#)
}

later.....

if( child.data('playback') == children.length ){
     do the above forloop again to repopulate the playback data
}
alex-carlson commented 8 years ago

yeah,

var nextnonrep = nonrep.next()

$(this).children().eq( nextnonrep  ).data('populate-next', true );

is effectively just regular random done in a more convoluted way. It would work if it wasn't regenerating the pattern every time it executes.

I'm going to explore the data attribute solution.

bmoren commented 8 years ago

keep in mind that $.data() != htlm 5's data-* check the documentation

alex-carlson commented 8 years ago

see updates. I think that's more in the right direction.

bmoren commented 8 years ago

an easier way!

  var pRandom = 1;

  var total = 5;

  var gogo = setInterval(function(){
    var rand = Math.floor( Math.random()*total );

    while(rand == pRandom){
      rand = Math.floor( Math.random()*total );
    }

    pRandom = rand;
    console.log(rand);

  },200)

could use .data() on the main container to store the pRand value

bmoren commented 8 years ago

Can you test the more efficient implementation I just pushed