Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -81,24 +81,44 @@ def fourier_transform_drawing(input_image, frames, coefficients, img_size):
|
|
81 |
fig.set_size_inches(15, 15)
|
82 |
|
83 |
draw_x, draw_y = [], []
|
|
|
|
|
|
|
|
|
84 |
|
85 |
def animate(i, coefs, time):
|
86 |
t = time[i]
|
87 |
center = (0, 0)
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
x, y = center[0] + r * np.cos(theta), center[1] + r * np.sin(theta)
|
93 |
-
circle_lines[_].set_data([center[0], center[0] + np.real(
|
94 |
circles[_].set_data(x, y)
|
95 |
-
center = (center[0] + np.real(
|
96 |
|
97 |
draw_x.append(center[0])
|
98 |
draw_y.append(center[1])
|
99 |
-
|
100 |
drawing.set_data(draw_x[:i+1], draw_y[:i+1])
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
drawing_time = 1
|
103 |
time = np.linspace(0, drawing_time, num=frames)
|
104 |
anim = animation.FuncAnimation(fig, animate, frames=frames, interval=5, fargs=(coefs, time))
|
@@ -122,7 +142,7 @@ interface = gr.Interface(
|
|
122 |
outputs=gr.Video(),
|
123 |
title="Fourier Transform Drawing",
|
124 |
description="Upload an image and generate a Fourier Transform drawing animation. You can find out more about the project here : https://github.com/staghado/fourier-draw",
|
125 |
-
examples=[["Fourier2.jpg", 100,
|
126 |
)
|
127 |
|
128 |
if __name__ == "__main__":
|
|
|
81 |
fig.set_size_inches(15, 15)
|
82 |
|
83 |
draw_x, draw_y = [], []
|
84 |
+
|
85 |
+
# Pre-compute static values outside the animate function
|
86 |
+
theta = np.linspace(0, tau, 80)
|
87 |
+
coefs_static = [(np.linalg.norm(c), fr) for c, fr in coefs] # Assuming `r` remains constant
|
88 |
|
89 |
def animate(i, coefs, time):
|
90 |
t = time[i]
|
91 |
center = (0, 0)
|
92 |
+
|
93 |
+
# Loop over coefficients
|
94 |
+
for _, (r, fr) in enumerate(coefs_static):
|
95 |
+
c_dynamic = coefs[_][0] * np.exp(1j * (fr * tau * t)) # Dynamic part of 'c'
|
96 |
x, y = center[0] + r * np.cos(theta), center[1] + r * np.sin(theta)
|
97 |
+
circle_lines[_].set_data([center[0], center[0] + np.real(c_dynamic)], [center[1], center[1] + np.imag(c_dynamic)])
|
98 |
circles[_].set_data(x, y)
|
99 |
+
center = (center[0] + np.real(c_dynamic), center[1] + np.imag(c_dynamic))
|
100 |
|
101 |
draw_x.append(center[0])
|
102 |
draw_y.append(center[1])
|
|
|
103 |
drawing.set_data(draw_x[:i+1], draw_y[:i+1])
|
104 |
|
105 |
+
# def animate(i, coefs, time):
|
106 |
+
# t = time[i]
|
107 |
+
# center = (0, 0)
|
108 |
+
# theta = np.linspace(0, tau, 80)
|
109 |
+
# for _, (c, fr) in enumerate(coefs):
|
110 |
+
# c = c * np.exp(1j*(fr * tau * t))
|
111 |
+
# r = np.linalg.norm(c)
|
112 |
+
# x, y = center[0] + r * np.cos(theta), center[1] + r * np.sin(theta)
|
113 |
+
# circle_lines[_].set_data([center[0], center[0] + np.real(c)], [center[1], center[1] + np.imag(c)])
|
114 |
+
# circles[_].set_data(x, y)
|
115 |
+
# center = (center[0] + np.real(c), center[1] + np.imag(c))
|
116 |
+
|
117 |
+
# draw_x.append(center[0])
|
118 |
+
# draw_y.append(center[1])
|
119 |
+
|
120 |
+
# drawing.set_data(draw_x[:i+1], draw_y[:i+1])
|
121 |
+
|
122 |
drawing_time = 1
|
123 |
time = np.linspace(0, drawing_time, num=frames)
|
124 |
anim = animation.FuncAnimation(fig, animate, frames=frames, interval=5, fargs=(coefs, time))
|
|
|
142 |
outputs=gr.Video(),
|
143 |
title="Fourier Transform Drawing",
|
144 |
description="Upload an image and generate a Fourier Transform drawing animation. You can find out more about the project here : https://github.com/staghado/fourier-draw",
|
145 |
+
examples=[["Fourier2.jpg", 100, 200, 224], ["Luffy.png", 100, 100, 224]]
|
146 |
)
|
147 |
|
148 |
if __name__ == "__main__":
|