Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More cleaning #102

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/lib/components/EmojiWall.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<script>
const WALL_SIZE = 84

// The first emoji in the array becomes the dominant background
// The others intersperse randomly
const emojis = [
['🌊','🦑','🦀','🐳','🦐','🐡','🐠','🦈','🏄‍♂️','🏝'],
['🌳','🦥','🦜','🐊','🐸','🐒','🌺','🍄','🐯','🐜'],
['🏜','🌵','🌞','🦂','🐍','🤠','🦇','🦉','🐫'],
['🏔','🏕','🌲','🦅','🌝','🏂']
]

// randomly replace array elements with something else
function fillRandom(array, fill, count) {
return function () {
const indices = new Set();
do {
indices.add(Math.floor(Math.random() * array.length));
} while (indices.size < count)
return array.map((v, i) => indices.has(i) ? fill[Math.floor(Math.random() * fill.length)] : v);
};
}

// Create the emoji walls.
const scenes = []
emojis.forEach(set => {
const background = set.shift()
let wall = Array(WALL_SIZE).fill(background)
wall = fillRandom(wall, set, 18)()

return scenes.push(wall)
})

// sort an array by random map, unmap to get new order
function shuffleArray(array) {
return array
.map(value => ({ value, sort: Math.random() }))
.sort((a, b) => a.sort - b.sort)
.map(({ value }) => value)
}

// increment counter and update visible wall
function changeWall() {
initial++
if (initial === scenes.length) initial = 0

visible = shuffleArray(scenes[initial])
}

// set default wall
let initial = 0
let visible = shuffleArray(scenes[initial])
</script>

<div class="block text-shadow text-4xl md:text-6xl mt-4 lg:mt-8 w-full max-h-[400px] md:max-h-[450px] overflow-hidden lg:overflow-visible">
{#each visible as f, i}
<!-- <span>{i}</span> -->
<button
class="emoji emoji-{i} p-1 m-1 text-shadow"
on:click={() => changeWall()}
>
{f}
</button>
{/each}
</div>
96 changes: 0 additions & 96 deletions src/lib/components/Emojis.svelte

This file was deleted.

4 changes: 2 additions & 2 deletions src/routes/(main)/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import Slice from '$lib/components/Slice.svelte'
import Card from '$lib/components/Card.svelte'
import Emojis from '$lib/components/Emojis.svelte'
import EmojiWall from '$lib/components/EmojiWall.svelte'
import {
SITE_URL,
SITE_TITLE,
Expand Down Expand Up @@ -37,7 +37,7 @@
<h1 class="text-shadow text-3xl font-bold lg:text-5xl">
welcome to my page
</h1>
<Emojis />
<EmojiWall />
</Slice>

<Slice title="Hello World!">
Expand Down
Loading