Skip to content

Commit

Permalink
Merge pull request #102 from tjheffner/more-cleaning
Browse files Browse the repository at this point in the history
More cleaning
  • Loading branch information
tjheffner authored Jan 24, 2024
2 parents e3a8cc2 + d5e01d2 commit d5f6fbe
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 98 deletions.
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

0 comments on commit d5f6fbe

Please sign in to comment.