File size: 1,249 Bytes
797f80b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff408e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
import matplotlib.pyplot as plt
import gradio as gr


def isprime(x):
    if x < 2:
        return False
    for i in range(2, x):
        if x % i == 0:
            return False
    return True


def stars(n):
    plt.figure(figsize=(20,20), facecolor=(0.5, 0.5, 0.5))
    for i, j in zip(range(1,n), range(n, 1, -1)):
        plt.plot([0, i], [j, 0], "k", linewidth=1)
        plt.plot([0, -i], [j, 0], "w", linewidth=1)
        plt.plot([0, i], [-j, 0], "w", linewidth=1)
        plt.plot([0, -i], [-j, 0], "k", linewidth=1)
    plt.axis('off')
    return plt.gcf()
    
iface = gr.Interface(stars, gr.inputs.Slider(1, 100, 1), "plot")

iface.launch()




# n = 50
# plt.figure(figsize=(20,20), facecolor=(0.5, 0.5, 0.5))
# for i, j in zip(range(1,n), range(n, 1, -1)):

#   zi = i / (2**(1/2))
#   zj = j / (2**(1/2))

#   plt.plot([zi, 0], [zi, j], "k", linewidth=1)
#   plt.plot([zi, j], [zi, 0], "w", linewidth=1)

#   plt.plot([-zi, 0], [zi, j], "w", linewidth=1)
#   plt.plot([-zi, -j], [zi, 0], "k", linewidth=1)

#   plt.plot([zi, 0], [-zi, -j], "w", linewidth=1)
#   plt.plot([zi, j], [-zi, 0], "k", linewidth=1)

#   plt.plot([-zi, 0], [-zi, -j], "k", linewidth=1)
#   plt.plot([-zi, -j], [-zi, 0], "w", linewidth=1)
#   plt.axis('off')