diff --git a/public/thumb tack 2 plain.png b/public/thumb tack 2 plain.png new file mode 100644 index 0000000..19a7f9e Binary files /dev/null and b/public/thumb tack 2 plain.png differ diff --git a/src/views/Photo.vue b/src/views/Photo.vue index d02c7e4..0a1c6fc 100644 --- a/src/views/Photo.vue +++ b/src/views/Photo.vue @@ -12,6 +12,11 @@ interface PhotoMetadata { exif: {[id: string]: string} } +// Take in a string, use its hash to produce a number from 0 to 1 +function detRandom(seed: string): number { + return Array.from(seed).reduce((acc, char) => (acc + char.charCodeAt(0) * 65535) % 22859, 0) / 22859 +} + @Component({}) export default class Photos extends Vue { photos: PhotoMetadata[] @@ -21,22 +26,28 @@ export default class Photos extends Vue { this.photos = await (await fetch('https://p.aza.moe/photos')).json() this.photos.sort((a, b) => (b.upload_time < a.upload_time ? 1 : -1)) + let rowProbabilityTable = { + 1: 0, 2: 0.5, 3: 0.5 + } + // Generate photo rows: there is a 10% chance that a photo will be the only photo in its row this.photoRows = [] let currentRow: PhotoMetadata[] = [] this.photos.forEach((p) => { - if (currentRow.length === 0) { - currentRow.push(p) - } else { - const singleChance = Math.random() - if (singleChance < 0.1) { + if (currentRow.length === 0) currentRow.push(p) + else if (currentRow.length >= 3) { + this.photoRows.push(currentRow) + currentRow = [ p ] + } + else { + const singleChance = detRandom(p.original_photo) + if (singleChance < rowProbabilityTable[currentRow.length]) { this.photoRows.push(currentRow) currentRow = [ p ] - } else { - currentRow.push(p) - } + } else currentRow.push(p) } }) + if (currentRow.length > 0) this.photoRows.push(currentRow) } url(s: string): string { @@ -45,29 +56,39 @@ export default class Photos extends Vue { } randomRotation(s: string): string { - const hash = Array.from(s).reduce((acc, char) => acc + char.charCodeAt(0), 0) - const angle = (hash % 21) - 10 // -10 to +10 degrees + const angle = (detRandom(s) * 20) - 10 // -10 to +10 degrees return `rotate(${angle}deg)` } } \ No newline at end of file