Skip to content

Commit

Permalink
Attempted to fix random not working on prod and background not render…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
originalnicodr committed Dec 22, 2023
1 parent 2b8042b commit fc1db82
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
31 changes: 30 additions & 1 deletion components/home/year-cover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,38 @@ const creditsTextStyle: CSS.Properties = {
//color: '#dbdfd8',
}

function shuffle(array: any[]) {
var i = 0;
var j = 0;
var temp = null;
for (i = array.length - 1; i > 0; i -= 1) {
j = Math.floor(Math.random() * (i + 1))
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}

function genRan(quantity: number, length: number) {
// Ensure that quantity is never greater than length
if (quantity > length) {
quantity = length;
}
// Create an array of consecutive numbers from 1 to N
var array = Array.from({
length: length
}, (value, key = 0) => key + 1);
// Run shuffle get the returned shuffled array
var shuffled = shuffle(array);
// return an array of N (quantity) random numbers
return shuffled.splice(0, quantity);
}


export const YearCover = (year: number) => {
const covers = getCovers(year);
var selectedCover = covers[Math.floor(Math.random() * Math.floor(covers.length))];
var selectedCover = covers[genRan(1, covers.length)[0]];
//var selectedCover = {shotUrl: "https://cdn.framedsc.com/images/1650423560_eldenring_2022-03-17_13-54-54.png", author: "test" };
//var selectedCover = {shotUrl: "https://cdn.framedsc.com/images/1659302449_Stray-Win64-Shipping.exe_2022-07-24_13-42-01_86x.png", author: "test" };

Expand Down
2 changes: 1 addition & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function App({ Component, pageProps }: AppProps) {
<picture>
<img
className="absolute top-0 left-0 object-cover"
src="/wrapped-images/Topography.svg"
src="wrapped-images/Topography.svg"
alt=""
style = {{zIndex: "-1", objectFit: "cover", minHeight: "200%"}}
/>
Expand Down
2 changes: 1 addition & 1 deletion pages/_year-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ export default function WrapYear(year: number) {
<img
loading="lazy"
className="absolute top-0 left-0 w-full h-full object-cover"
src="/wrapped-images/Topography.svg"
src="wrapped-images/Topography.svg"
alt=""
/>
</picture>
Expand Down

0 comments on commit fc1db82

Please sign in to comment.