Spaces:
Runtime error
Runtime error
File size: 1,415 Bytes
c7ce504 72d2c17 c7ce504 72d2c17 c7ce504 8e31e74 c7ce504 c71253d c7ce504 8e31e74 c7ce504 8e31e74 c7ce504 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
from asyncio import constants
import gradio as gr
import requests
import os
import re
import random
import numpy as np
from perlin_numpy import generate_fractal_noise_2d
def create_fractal_noise(input_seed,input_size,res,n_octaves,persistence):
"""
Generate fractal noise using the Perlin noise algorithm.
"""
np.random.seed(input_seed)
noise = generate_fractal_noise_2d((input_size, input_size), (res, res), n_octaves, persistence)
#reshape
n3=np.repeat(n[:,:,np.newaxis],3,axis=2)
#change from [-1,1] to [0,255]
n3=(n3+1)/2*255
return n3
demo = gr.Blocks()
with demo:
gr.Markdown("<h1><center>LiteDungeon</center></h1>")
gr.Markdown(
"<div>Create fractal-like noise (useful for map generation and such)</div>"
)
with gr.Row():
input_seed = gr.Number(label="seed",value=0)
input_size = seed=gr.Number(value=256, label='size')
res=gr.Number(value=2, label='res')
n_octaves=gr.Number(value=8, label='n-octaves')
persistence=gr.Number(value=0.5, label='persistence')
with gr.Row():
output_image = gr.outputs.Image(type="filepath", label='Output')
with gr.Row():
b0 = gr.Button("Submit")
b0.click(create_fractal_noise,inputs=[input_seed,input_size,res,n_octaves,persistence],outputs=[output_image])
#examples=examples
demo.launch(enable_queue=True, debug=True) |