Last active
April 23, 2021 13:14
-
-
Save FMJansen/c1d6052f13497d1989365facbeb760b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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