Spaces:
Sleeping
Sleeping
innitial commit
Browse files- .gitignore +2 -0
- app.py +52 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
venv/
|
2 |
+
|
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image, ImageDraw
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
def mandelbrot(c, MAX_ITER):
|
6 |
+
z = 0
|
7 |
+
n = 0
|
8 |
+
while abs(z) <= 2 and n < MAX_ITER:
|
9 |
+
z = z*z + c
|
10 |
+
n += 1
|
11 |
+
return n
|
12 |
+
|
13 |
+
|
14 |
+
def mandelbrot_set(MAX_ITER):
|
15 |
+
# Image size (pixels)
|
16 |
+
WIDTH = 600
|
17 |
+
HEIGHT = 400
|
18 |
+
|
19 |
+
# Plot window
|
20 |
+
RE_START = -2
|
21 |
+
RE_END = 1
|
22 |
+
IM_START = -1
|
23 |
+
IM_END = 1
|
24 |
+
|
25 |
+
palette = []
|
26 |
+
|
27 |
+
im = Image.new('RGB', (WIDTH, HEIGHT), (0, 0, 0))
|
28 |
+
draw = ImageDraw.Draw(im)
|
29 |
+
|
30 |
+
for x in range(0, WIDTH):
|
31 |
+
for y in range(0, HEIGHT):
|
32 |
+
# Convert pixel coordinate to complex number
|
33 |
+
c = complex(RE_START + (x / WIDTH) * (RE_END - RE_START),
|
34 |
+
IM_START + (y / HEIGHT) * (IM_END - IM_START))
|
35 |
+
# Compute the number of iterations
|
36 |
+
m = mandelbrot(c, MAX_ITER)
|
37 |
+
# The color depends on the number of iterations
|
38 |
+
color = 255 - int(m * 255 / MAX_ITER)
|
39 |
+
# Plot the point
|
40 |
+
draw.point([x, y], (color, color, color))
|
41 |
+
|
42 |
+
return im
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
iface = gr.Interface(mandelbrot_set,
|
47 |
+
gr.inputs.Slider(1, 100, 1),
|
48 |
+
"pil",
|
49 |
+
title="Floyd Steinberg dithering",
|
50 |
+
description="Floyd Steinberg dithering algorithm")
|
51 |
+
|
52 |
+
iface.launch()
|