Skip to content

Instantly share code, notes, and snippets.

@FMJansen
Last active April 23, 2021 13:14
Show Gist options
  • Save FMJansen/c1d6052f13497d1989365facbeb760b6 to your computer and use it in GitHub Desktop.
Save FMJansen/c1d6052f13497d1989365facbeb760b6 to your computer and use it in GitHub Desktop.
<script>
// stolen from https://electrictoolbox.com/pad-number-two-digits-javascript/
function pad(number) {
return (number < 10 ? '0' : '') + number;
}
function set_random_image(artwork_id, image_count){
// Generate a random index
random_index = Math.ceil(Math.random() * image_count);
// ceil in plaats van floor zodat het niet bij 0 maar 1 begint en eindigt bij het aantal plaatjes
// Select an image with the index
padded_index = pad(random_index)
// Display the image by inserting code into the html
document.getElementById(artwork_id).src = `./img/${artwork_id}/${artwork_id}-${padded_index}.svg`
}
window.onload = function() {
set_random_image('squares-in-orbit', 12)
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment