circulartext commited on
Commit
2257e84
·
verified ·
1 Parent(s): 66f3f0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -3,7 +3,6 @@ import numpy as np
3
  import matplotlib.pyplot as plt
4
  from matplotlib.animation import FuncAnimation, PillowWriter
5
  import scipy.io.wavfile as wavfile
6
- import os
7
 
8
  # Constants for sound generation
9
  SAMPLE_RATE = 48000
@@ -11,8 +10,10 @@ COLUMN_DURATION = 1 # Duration of each column in seconds
11
 
12
  # Mapping of matrix numbers to musical notes
13
  notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
14
- note_map = {2: "A", 3: "A#", 4: "B", 5: "C", 6: "C#", 7: "D", 8: "D#", 9: "E",
15
- 10: "F", 11: "F#", 12: "G", 13: "G#"}
 
 
16
 
17
  def generate_tone(note, duration):
18
  """Generates a tone for a specified note and duration."""
@@ -146,7 +147,7 @@ def create_animation(matrix):
146
  has_changes, matrix = sim.step()
147
  if not has_changes:
148
  ani.event_source.stop()
149
- return
150
 
151
  for i in range(rows):
152
  for j in range(cols):
@@ -171,7 +172,9 @@ def create_animation(matrix):
171
  current_frame[0] += 1
172
  return circles + labels
173
 
174
- ani = FuncAnimation(fig, update, frames=None, interval=1000, blit=True)
 
 
175
 
176
  # Save the animation to a GIF file
177
  gif_path = "matrix_animation.gif"
 
3
  import matplotlib.pyplot as plt
4
  from matplotlib.animation import FuncAnimation, PillowWriter
5
  import scipy.io.wavfile as wavfile
 
6
 
7
  # Constants for sound generation
8
  SAMPLE_RATE = 48000
 
10
 
11
  # Mapping of matrix numbers to musical notes
12
  notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
13
+ note_map = {
14
+ 2: "A", 3: "A#", 4: "B", 5: "C", 6: "C#", 7: "D", 8: "D#", 9: "E",
15
+ 10: "F", 11: "F#", 12: "G", 13: "G#"
16
+ }
17
 
18
  def generate_tone(note, duration):
19
  """Generates a tone for a specified note and duration."""
 
147
  has_changes, matrix = sim.step()
148
  if not has_changes:
149
  ani.event_source.stop()
150
+ return circles + labels
151
 
152
  for i in range(rows):
153
  for j in range(cols):
 
172
  current_frame[0] += 1
173
  return circles + labels
174
 
175
+ # Estimate the number of frames needed
176
+ max_steps = 100 # Set a reasonable limit for the number of steps
177
+ ani = FuncAnimation(fig, update, frames=max_steps, interval=1000, blit=True, cache_frame_data=False)
178
 
179
  # Save the animation to a GIF file
180
  gif_path = "matrix_animation.gif"