add more rando
This commit is contained in:
@ -5,17 +5,28 @@ export interface JustifiedImage extends JustifiedInputImage {
|
|||||||
height: number;
|
height: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shuffleImages<T>(arr: T[]): T[] {
|
||||||
|
const shuffled = [...arr];
|
||||||
|
for (let i = shuffled.length - 1; i > 0; i--) {
|
||||||
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
|
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
||||||
|
}
|
||||||
|
return shuffled;
|
||||||
|
}
|
||||||
|
|
||||||
export function justifyPortfolioImages(
|
export function justifyPortfolioImages(
|
||||||
images: JustifiedInputImage[],
|
images: JustifiedInputImage[],
|
||||||
containerWidth: number,
|
containerWidth: number,
|
||||||
rowHeight: number,
|
rowHeight: number,
|
||||||
gap: number = 4
|
gap: number = 4
|
||||||
): JustifiedImage[][] {
|
): JustifiedImage[][] {
|
||||||
|
const shuffledImages = shuffleImages(images);
|
||||||
|
|
||||||
const rows: JustifiedImage[][] = [];
|
const rows: JustifiedImage[][] = [];
|
||||||
let currentRow: JustifiedInputImage[] = [];
|
let currentRow: JustifiedInputImage[] = [];
|
||||||
let currentWidth = 0;
|
let currentWidth = 0;
|
||||||
|
|
||||||
for (const image of images) {
|
for (const image of shuffledImages) {
|
||||||
const scale = rowHeight / image.height;
|
const scale = rowHeight / image.height;
|
||||||
const scaledWidth = image.width * scale;
|
const scaledWidth = image.width * scale;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user