Skip to content

Instantly share code, notes, and snippets.

@mohayonao
Created October 21, 2015 22:17
Show Gist options
  • Select an option

  • Save mohayonao/b359f61f2018280ea2ce to your computer and use it in GitHub Desktop.

Select an option

Save mohayonao/b359f61f2018280ea2ce to your computer and use it in GitHub Desktop.
function createRandomAutoPanSegment() {
let result = [];
let length = Math.floor(Math.random() * 5 + 5);
let pos = 0;
for (let i = 0; i < length; i++) {
if (Math.random() * 0.8 < i / length) {
pos = 1;
}
if (pos === 0) {
if (Math.random() < 0.2) {
pos += Math.random() * 0.6;
}
} else if (1 <= pos) {
pos = 1;
} else if (Math.random() < 0.1) {
pos += Math.random() * 0.6;
}
result[i] = pos;
}
result[0] = 0;
result = result.map(x => x * 2 - 1);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment