mirror of
https://github.com/Xevion/processing-projects.git
synced 2025-12-06 15:16:04 -06:00
doppler effect sketch
This commit is contained in:
50
physics/Doppler_Effect/Doppler_Effect.pyde
Normal file
50
physics/Doppler_Effect/Doppler_Effect.pyde
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# Represents a single wave emission
|
||||||
|
class SoundWave(object):
|
||||||
|
def __init__(self, x, y, speed=1, radius=1):
|
||||||
|
self.x, self.y = x, y
|
||||||
|
self.speed, self.radius = speed, radius
|
||||||
|
|
||||||
|
def tick(self):
|
||||||
|
self.radius += self.speed
|
||||||
|
|
||||||
|
# Moved into a function to allow fast adjustment of opacity degradation
|
||||||
|
# whilst still observing current opacity from external "garbage collectors"
|
||||||
|
@property
|
||||||
|
def stroke(self):
|
||||||
|
return self.radius * 0.75
|
||||||
|
|
||||||
|
def render(self):
|
||||||
|
stroke(self.stroke) # Opacity Controls
|
||||||
|
circle(self.x, self.y, self.radius * 2) # diameter
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
size(1000, 1000)
|
||||||
|
|
||||||
|
noFill()
|
||||||
|
|
||||||
|
global sounds, x, y
|
||||||
|
sounds = []
|
||||||
|
x, y = width // 2 - 250, height // 2
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
XRATE = 2
|
||||||
|
def draw():
|
||||||
|
global sounds, XRATE, x, y, i
|
||||||
|
|
||||||
|
x += XRATE
|
||||||
|
i += 1
|
||||||
|
if i % (15 // XRATE) == 0:
|
||||||
|
sounds.append(SoundWave(x, y, 0.1 + XRATE))
|
||||||
|
|
||||||
|
if i % 200 == 0:
|
||||||
|
sounds = [s for s in sounds if s.stroke < 255]
|
||||||
|
|
||||||
|
if x >= 1300:
|
||||||
|
x = -100
|
||||||
|
|
||||||
|
print(len(sounds))
|
||||||
|
|
||||||
|
background(255)
|
||||||
|
for sound in sounds:
|
||||||
|
sound.tick()
|
||||||
|
sound.render()
|
||||||
2
physics/Doppler_Effect/sketch.properties
Normal file
2
physics/Doppler_Effect/sketch.properties
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
mode=Python
|
||||||
|
mode.id=jycessing.mode.PythonMode
|
||||||
@@ -4,4 +4,6 @@
|
|||||||
|
|
||||||
Sketches that simulate physics or physical phenomena in some way or another.
|
Sketches that simulate physics or physical phenomena in some way or another.
|
||||||
|
|
||||||
## Sketches
|
## Sketches
|
||||||
|
|
||||||
|
- **Doppler_Effect** - Simulates the doppler effect with apparent high accuracy.
|
||||||
Reference in New Issue
Block a user