Add noise preview

This commit is contained in:
Misode
2021-10-21 02:32:11 +02:00
parent 749a54802d
commit 794a094e7e
6 changed files with 152 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
import { DataModel } from '@mcschema/core'
import { NoiseParameters, NormalNoise, Random } from 'deepslate'
import type { VersionId } from '../Schemas'
export type NoiseOptions = {
offset: [number, number],
scale: number,
seed: bigint,
version: VersionId,
}
export function normalNoise(state: any, img: ImageData, options: NoiseOptions) {
const random = new Random(options.seed)
const params = NoiseParameters.fromJson(DataModel.unwrapLists(state))
const noise = new NormalNoise(random, params)
const ox = -options.offset[0] - 100
const oz = -options.offset[1] - 100
const data = img.data
for (let x = 0; x < 256; x += 1) {
for (let y = 0; y < 256; y += 1) {
const i = x * 4 + y * 4 * 256
const xx = (x + ox) * options.scale
const yy = (y + oz) * options.scale
const color = (noise.sample(xx, yy, 0) + 1) * 128
data[i] = color
data[i + 1] = color
data[i + 2] = color
data[i + 3] = 255
}
}
}

View File

@@ -1,3 +1,4 @@
export * from './BiomeSource'
export * from './Decorator'
export * from './NoiseSettings'
export * from './NormalNoise'