Update StrNoise

This commit is contained in:
MrLetsplay 2023-10-27 07:52:33 +02:00
parent 94bac26a7c
commit 1362386fdc
Signed by: mr
SSH Key Fingerprint: SHA256:0zWNiRisbQ4dq/CCQAaMLoF3UfkF5wKPXO7DcjfFBEU
2 changed files with 6 additions and 2 deletions

View File

@ -3,6 +3,8 @@ import { Component, createEffect, createSignal, on } from 'solid-js';
import styles from './Page.module.css';
import Navigation from '../Navigation';
const SYMBOLS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 _#+';
function murmurHash3(string: string) {
let i = 0, hash: number;
for (hash = 1779033703 ^ string.length; i < string.length; i++) {
@ -43,7 +45,7 @@ const StrNoise: Component = () => {
const [shuffle, setShuffle] = createSignal(true);
const [randomize, setRandomize] = createSignal(true);
const [swapAdjacent, setSwapAdjancent] = createSignal(true);
const [swapAdjacent, setSwapAdjancent] = createSignal(false);
createEffect(on([input, noiseLevel, seed, shuffle, randomize, swapAdjacent], () => {
const s = murmurHash3(seed());
@ -64,7 +66,8 @@ const StrNoise: Component = () => {
const b = Math.floor(generator() * arr.length);
[arr[a], arr[b]] = [arr[b], arr[a]];
} else if (type == 'randomize') {
// TODO
const i = Math.floor(generator() * arr.length);
arr[i] = SYMBOLS[Math.floor(generator() * SYMBOLS.length)];
} else if (type == 'swap_adjacent') {
const a = Math.floor(generator() * (arr.length - 1));
[arr[a], arr[a + 1]] = [arr[a + 1], arr[a]];

View File

@ -17,4 +17,5 @@ export default defineConfig({
build: {
target: 'esnext',
},
base: './'
});