Update StrNoise
This commit is contained in:
parent
94bac26a7c
commit
1362386fdc
@ -3,6 +3,8 @@ import { Component, createEffect, createSignal, on } from 'solid-js';
|
|||||||
import styles from './Page.module.css';
|
import styles from './Page.module.css';
|
||||||
import Navigation from '../Navigation';
|
import Navigation from '../Navigation';
|
||||||
|
|
||||||
|
const SYMBOLS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 _#+';
|
||||||
|
|
||||||
function murmurHash3(string: string) {
|
function murmurHash3(string: string) {
|
||||||
let i = 0, hash: number;
|
let i = 0, hash: number;
|
||||||
for (hash = 1779033703 ^ string.length; i < string.length; i++) {
|
for (hash = 1779033703 ^ string.length; i < string.length; i++) {
|
||||||
@ -43,7 +45,7 @@ const StrNoise: Component = () => {
|
|||||||
|
|
||||||
const [shuffle, setShuffle] = createSignal(true);
|
const [shuffle, setShuffle] = createSignal(true);
|
||||||
const [randomize, setRandomize] = 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], () => {
|
createEffect(on([input, noiseLevel, seed, shuffle, randomize, swapAdjacent], () => {
|
||||||
const s = murmurHash3(seed());
|
const s = murmurHash3(seed());
|
||||||
@ -64,7 +66,8 @@ const StrNoise: Component = () => {
|
|||||||
const b = Math.floor(generator() * arr.length);
|
const b = Math.floor(generator() * arr.length);
|
||||||
[arr[a], arr[b]] = [arr[b], arr[a]];
|
[arr[a], arr[b]] = [arr[b], arr[a]];
|
||||||
} else if (type == 'randomize') {
|
} 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') {
|
} else if (type == 'swap_adjacent') {
|
||||||
const a = Math.floor(generator() * (arr.length - 1));
|
const a = Math.floor(generator() * (arr.length - 1));
|
||||||
[arr[a], arr[a + 1]] = [arr[a + 1], arr[a]];
|
[arr[a], arr[a + 1]] = [arr[a + 1], arr[a]];
|
||||||
|
@ -17,4 +17,5 @@ export default defineConfig({
|
|||||||
build: {
|
build: {
|
||||||
target: 'esnext',
|
target: 'esnext',
|
||||||
},
|
},
|
||||||
|
base: './'
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user