function next_step() {
      if (trial.stimuli.length == which_image) {
        endTrial();
      } else {

        var d = directions[next_direction];
        next_direction === 0 ? next_direction = 1 : next_direction = 0;
        var i = trial.stimuli[which_image];
        which_image++;

        c.animate(d[0].params, d[0].ms, mina.linear, function() {
          c.animate(d[1].params, d[1].ms, mina.linear, function() {
            next_step();
          });
        });

        c.attr({
          href: i
        });

        // start timer for this trial
        start_time = performance.now();
      }
    }
jsPsych plugin for showing animations that mimic the experiment described in

Fiser, J., & Aslin, R. N. (2002). Statistical learning of higher-order
temporal structure from visual shape sequences. Journal of Experimental
Psychology: Learning, Memory, and Cognition, 28(3), 458.

Josh de Leeuw

documentation: docs.jspsych.org