Spaces:
Runtime error
Runtime error
innitial commit
Browse files- .gitignore +2 -0
- app.py +51 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
venv/
|
2 |
+
|
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import matplotlib.pyplot as plt
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
def isprime(x):
|
6 |
+
if x < 2:
|
7 |
+
return False
|
8 |
+
for i in range(2, x):
|
9 |
+
if x % i == 0:
|
10 |
+
return False
|
11 |
+
return True
|
12 |
+
|
13 |
+
|
14 |
+
def ulamspiral(n):
|
15 |
+
x = 0
|
16 |
+
y = 0
|
17 |
+
estado = 0
|
18 |
+
numsteps = 1
|
19 |
+
cambio_dir = 0
|
20 |
+
last_x = 0
|
21 |
+
last_y = 0
|
22 |
+
plt.axis('off')
|
23 |
+
for step in range(1, n+1):
|
24 |
+
if isprime(step):
|
25 |
+
plt.plot(x, y, "ko")
|
26 |
+
if step != 1:
|
27 |
+
plt.plot([last_x, x], [last_y, y], "k-")
|
28 |
+
last_x = x
|
29 |
+
last_y = y
|
30 |
+
if estado == 4:
|
31 |
+
estado = 0
|
32 |
+
if estado == 0:
|
33 |
+
x += 1
|
34 |
+
elif estado == 1:
|
35 |
+
y += 1
|
36 |
+
elif estado == 2:
|
37 |
+
x -= 1
|
38 |
+
elif estado == 3:
|
39 |
+
y -= 1
|
40 |
+
|
41 |
+
if step % numsteps == 0:
|
42 |
+
estado = (estado + 1) % 4
|
43 |
+
cambio_dir += 1
|
44 |
+
if cambio_dir % 2 == 0:
|
45 |
+
numsteps += 1
|
46 |
+
|
47 |
+
return plt.gcf()
|
48 |
+
|
49 |
+
iface = gr.Interface(ulamspiral, gr.inputs.Slider(1, 1000, 1), "plot")
|
50 |
+
|
51 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
matplotlib
|
2 |
+
|