diff --git a/#1679_sine_Wave_Dancer/README.md b/#1679_sine_Wave_Dancer/README.md new file mode 100644 index 0000000..0186e99 --- /dev/null +++ b/#1679_sine_Wave_Dancer/README.md @@ -0,0 +1,31 @@ +# Dancing Sine Wave Animation + +A simple Python program using `pygame` to create a **moving sine wave with dancing dots**. The dots follow a sine wave and exhibit subtle random vertical movements, giving a lively "dancing" effect. + +## Features + +- Animated sine wave with moving dots. +- Dots have slight vertical offsets for a dancing effect. +- Adjustable parameters: amplitude, frequency, speed, number of dots, colors. +- Smooth 60 FPS animation. + +## How It Works + +1. Dots are evenly spaced along the x-axis of the screen. +2. Y-position of each dot is calculated using a sine function with a time-based offset for horizontal motion. +3. Random vertical offsets are added to each dot for the dancing effect. +4. `pygame` renders the dots on a dark background. + +## Parameters + +- `AMPLITUDE` – wave height. +- `FREQUENCY` – number of waves across the screen. +- `SPEED` – horizontal movement speed. +- `NUM_DOTS` – number of dots along the wave. +- `DOT_RADIUS` – size of each dot. +- `BG_COLOR` and `DOT_COLOR` – customize colors. + +## Requirements + +- Python 3.6+ +- `pygame` (`pip install pygame`) \ No newline at end of file diff --git a/#1679_sine_Wave_Dancer/sinedancer.py b/#1679_sine_Wave_Dancer/sinedancer.py new file mode 100644 index 0000000..e3b547e --- /dev/null +++ b/#1679_sine_Wave_Dancer/sinedancer.py @@ -0,0 +1,56 @@ +import pygame +import math +import random + +# --- Pygame Initialization & Constants --- +pygame.init() +W, H = 800, 400 +SCREEN = pygame.display.set_mode((W, H)) +pygame.display.set_caption("Dancing Sine Wave") +CLOCK = pygame.time.Clock() + +# --- Colors and Wave Parameters --- +BG_COLOR = (20, 20, 40) # Dark background +DOT_COLOR = (150, 200, 255) # Light blue dots +AMPLITUDE = 80 # Height of the wave +FREQUENCY = 0.02 # How many waves fit on screen (lower = more waves) +SPEED = 0.05 # How fast the wave moves horizontally +NUM_DOTS = 50 # Number of dots on the wave +DOT_RADIUS = 5 + +# --- Global Wave Offset --- +wave_offset = 0.0 + +# --- Main Animation Loop --- +running = True +while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + SCREEN.fill(BG_COLOR) + + # Update wave offset for movement + wave_offset += SPEED + + # Calculate and draw dots + for i in range(NUM_DOTS): + # Evenly distribute dots across the screen width + x = i * (W / (NUM_DOTS - 1)) + + # Calculate y-position based on sine wave + # Add wave_offset to x to make the wave appear to move + y_wave = math.sin(x * FREQUENCY + wave_offset) + + # Scale to amplitude and center vertically + y = H / 2 + (y_wave * AMPLITUDE) + + # Add a subtle "dance" (random vertical offset) to each dot + dance_offset = random.uniform(-5, 5) # Smaller range for subtle effect + + pygame.draw.circle(SCREEN, DOT_COLOR, (int(x), int(y + dance_offset)), DOT_RADIUS) + + pygame.display.flip() + CLOCK.tick(60) # Smooth animation at 60 FPS + +pygame.quit()