doppler effect sketch

This commit is contained in:
Xevion
2019-11-02 15:41:19 -05:00
parent 45f8d88625
commit 401cdb52dc
3 changed files with 55 additions and 1 deletions

View 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()

View File

@@ -0,0 +1,2 @@
mode=Python
mode.id=jycessing.mode.PythonMode

View File

@@ -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.