mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-26 08:26:51 +00:00
Add noise preview
This commit is contained in:
32
src/app/previews/NormalNoise.ts
Normal file
32
src/app/previews/NormalNoise.ts
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './BiomeSource'
|
||||
export * from './Decorator'
|
||||
export * from './NoiseSettings'
|
||||
export * from './NormalNoise'
|
||||
|
||||
Reference in New Issue
Block a user