Spaces:
Sleeping
Sleeping
import gradio as gr | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from PIL import Image | |
def generate_water_texture(scale, octaves): | |
def f(x, y): | |
return np.sin(2 * np.pi * (x * scale + y * scale)) / octaves | |
x = np.linspace(0, 1, 500, endpoint=False) | |
y = np.linspace(0, 1, 500, endpoint=False) | |
X, Y = np.meshgrid(x, y) | |
Z = f(X, Y) | |
fig, ax = plt.subplots(figsize=(5, 5)) | |
ax.imshow(Z, cmap='Blues', origin='upper') | |
ax.axis('off') | |
plt.tight_layout(pad=0) | |
fig.canvas.draw() | |
image = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8) | |
image = image.reshape(fig.canvas.get_width_height()[::-1] + (3,)) | |
image = Image.fromarray(image) | |
plt.close(fig) | |
return image | |
iface = gr.Interface( | |
fn=generate_water_texture, | |
inputs=[ | |
gr.Slider(0.1, 10.0, step=0.1, label="Scale"), | |
gr.Slider(1, 10, step=1, label="Octaves") | |
], | |
outputs=gr.Image(), | |
title="Water Texture Generator", | |
description="Adjust the sliders to change the noise parameters and generate a water texture." | |
) | |
iface.launch() | |