From 2f6a60e21dcb845a1ca3db53ddc0c85ae06637fd Mon Sep 17 00:00:00 2001 From: Khushi Kalra Date: Mon, 1 Jul 2024 23:06:00 +0530 Subject: [PATCH 1/3] Add files via upload --- Depth-Perspective-Visualizer.py | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Depth-Perspective-Visualizer.py diff --git a/Depth-Perspective-Visualizer.py b/Depth-Perspective-Visualizer.py new file mode 100644 index 0000000..bc93a68 --- /dev/null +++ b/Depth-Perspective-Visualizer.py @@ -0,0 +1,88 @@ +import pygame +import random +import numpy as np +import pyaudio + +# Initialize Pygame +pygame.init() + +# Screen dimensions +WIDTH, HEIGHT = 800, 600 +screen = pygame.display.set_mode((WIDTH, HEIGHT)) +pygame.display.set_caption("3D Particle System with Audio") + +# Colors +WHITE = (255, 255, 255) +BLACK = (0, 0, 0) + +# Particle settings +NUM_PARTICLES = 1000 +MAX_DEPTH = 800 + +# PyAudio settings +CHUNK = 1024 +RATE = 44100 +audio_data = None + +# PyAudio initialization +p = pyaudio.PyAudio() +stream = p.open(format=pyaudio.paInt16, + channels=1, + rate=RATE, + input=True, + frames_per_buffer=CHUNK) + +# Particle class +class Particle: + def __init__(self): + self.x = random.uniform(-WIDTH // 2, WIDTH // 2) + self.y = random.uniform(-HEIGHT // 2, HEIGHT // 2) + self.z = random.uniform(1, MAX_DEPTH) + + def update(self, audio_level): + self.z -= audio_level * 50 + if self.z <= 0: + self.z = MAX_DEPTH + self.x = random.uniform(-WIDTH // 2, WIDTH // 2) + self.y = random.uniform(-HEIGHT // 2, HEIGHT // 2) + + def draw(self, screen): + f = 200 / self.z + x = int(WIDTH / 2 + self.x * f) + y = int(HEIGHT / 2 + self.y * f) + size = int((1 - self.z / MAX_DEPTH) * 5) + if size < 1: + size = 1 + pygame.draw.circle(screen, WHITE, (x, y), size) + +# Create particles +particles = [Particle() for _ in range(NUM_PARTICLES)] + +# Main loop +running = True +clock = pygame.time.Clock() + +while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + screen.fill(BLACK) + + # Read audio data from microphone + audio_data = np.frombuffer(stream.read(CHUNK), dtype=np.int16) + audio_level = np.abs(audio_data).mean() / 32767.0 # Calculate audio level + + # Update and draw particles + for particle in particles: + particle.update(audio_level) + particle.draw(screen) + + pygame.display.flip() + clock.tick(60) + +# Close PyAudio stream and terminate PyAudio +stream.stop_stream() +stream.close() +p.terminate() +pygame.quit() From dbad91fc5f8b1d927dcc192137095c3a3aa1794d Mon Sep 17 00:00:00 2001 From: Khushi Kalra Date: Mon, 1 Jul 2024 23:25:57 +0530 Subject: [PATCH 2/3] Updated mainLanding.py --- mainLanding.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mainLanding.py b/mainLanding.py index e9792d8..34cbb48 100644 --- a/mainLanding.py +++ b/mainLanding.py @@ -34,6 +34,7 @@ def build(self): button_layout.add_widget(Button(text="Waveform", on_press=self.launch_visualizer)) button_layout.add_widget(Button(text="Spectrogram", on_press=self.launch_visualizer)) button_layout.add_widget(Button(text="Intensity vs Frequency and Time", on_press=self.launch_visualizer)) + button_layout.add_widget(Button(text="Depth-Perspective Visualizer", on_press=self.launch_visualizer)) theme_button = Button(text="Change Theme", size_hint=(1, 0.1), background_color=(0, 1, 0, 1)) theme_button.bind(on_press=self.change_theme) @@ -88,7 +89,8 @@ def launch_visualizer(self, instance): "Amplitude-Frequency Visualizer": "Amplitude-Frequency-Visualizer.py", "Waveform": "Waveform.py", "Spectrogram": "Spectogram.py", - "Intensity vs Frequency and Time": "Intensity-vs-Frequency-and-Time.py" + "Intensity vs Frequency and Time": "Intensity-vs-Frequency-and-Time.py", + "Depth-Perspective Visualizer": "Depth-Perspective-Visualizer.py" } script_name = instance.text From 91e752dd80ebd6e985a34e2d3fc02c5b90f59f4b Mon Sep 17 00:00:00 2001 From: Khushi Kalra Date: Tue, 16 Jul 2024 09:58:28 +0530 Subject: [PATCH 3/3] Update mainLanding.py --- mainLanding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainLanding.py b/mainLanding.py index d5c7d0f..f1a8e54 100644 --- a/mainLanding.py +++ b/mainLanding.py @@ -142,7 +142,7 @@ def launch_visualizer(self, instance): visualizer_scripts = { "Amplitude-Frequency Visualizer": "Amplitude-Frequency-Visualizer.py", "Waveform": "Waveform.py", - "Spectrogram": "Spectogram.py", + "Spectrogram": "Spectrogram.py", "Intensity vs Frequency and Time": "Intensity-vs-Frequency-and-Time.py", "Depth-Perspective Visualizer": "Depth-Perspective-Visualizer.py" }