Rename noise folder

This commit is contained in:
Misode
2020-12-06 00:55:39 +01:00
parent 5806d26f42
commit a84822b1cc
7 changed files with 15 additions and 11 deletions

View File

@@ -15,6 +15,15 @@ export function hashString(s: string) {
return (s ?? '').split('').reduce((a, b) => { a = ((a << 5) - a) + b.charCodeAt(0); return a & a }, 0)
}
export function stringToColor(str: string): [number, number, number] {
const h = Math.abs(hashString(str))
return [h % 256, (h >> 8) % 256, (h >> 16) % 256]
}
export function clamp(a: number, b: number, c: number) {
return Math.max(a, Math.min(b, c))
}
export function clampedLerp(a: number, b: number, c: number): number {
if (c < 0) {
return a;

View File

@@ -1,9 +1,9 @@
import { DataModel, Path, ModelPath } from "@mcschema/core"
import { Octicon } from "../components/Octicon"
import { Property } from "../state/Property"
import { hashString, hexId } from "../Utils"
import { hexId, stringToColor } from "../Utils"
import { View } from "../views/View"
import { NormalNoise } from './math/NormalNoise'
import { NormalNoise } from './noise/NormalNoise'
import { Preview } from './Preview'
const LOCAL_STORAGE_BIOME_COLORS = 'biome_colors'
@@ -110,7 +110,7 @@ export class BiomeNoisePreview extends Preview {
getBiomeColor(biome: string): number[] {
const color = this.biomeColors.get()[biome]
if (color === undefined) {
return this.colorFromBiome(biome)
return stringToColor(biome)
}
return color
}
@@ -124,9 +124,4 @@ export class BiomeNoisePreview extends Preview {
getBiomeHex(biome: string): string {
return '#' + this.getBiomeColor(biome).map(e => e.toString(16).padStart(2, '0')).join('')
}
private colorFromBiome(biome: string): number[] {
const h = Math.abs(hashString(biome))
return [h % 256, (h >> 8) % 256, (h >> 16) % 256]
}
}

View File

@@ -2,7 +2,7 @@ import { DataModel, Path, ModelPath } from "@mcschema/core"
import { Preview } from './Preview'
import { toggleMenu, View } from '../views/View'
import { Octicon } from '../components/Octicon'
import { NoiseChunkGenerator } from './NoiseChunkGenerator'
import { NoiseChunkGenerator } from './noise/NoiseChunkGenerator'
export class NoiseSettingsPreview extends Preview {
private width: number = 512

View File

@@ -1,5 +1,5 @@
import { PerlinNoise } from './math/PerlinNoise'
import { clampedLerp, hexId, lerp2 } from '../Utils'
import { PerlinNoise } from './PerlinNoise'
import { clampedLerp, hexId, lerp2 } from '../../Utils'
export class NoiseChunkGenerator {
private minLimitPerlinNoise: PerlinNoise