Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions #1679_sine_Wave_Dancer/README.md
Original file line number Diff line number Diff line change
@@ -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`)
56 changes: 56 additions & 0 deletions #1679_sine_Wave_Dancer/sinedancer.py
Original file line number Diff line number Diff line change
@@ -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()