Skip to content

Instantly share code, notes, and snippets.

@kogens
Created September 22, 2023 12:02
Show Gist options
  • Save kogens/8f0e12206e7aa018c526e2ec32813878 to your computer and use it in GitHub Desktop.
Save kogens/8f0e12206e7aa018c526e2ec32813878 to your computer and use it in GitHub Desktop.
Grating for Falstad Rippletank
# Creates a diffraction grating for the Falstad ripple tank simulator
# http://www.falstad.com/ripple/
# Basic parameters
brightness = 480
scale = 1.5625e-8
resolution = 1020
print('$ 3 {} 64 0 1 {} {}'.format(resolution, brightness, scale))
# Line source
x1, y1 = 350, 0
x2, y2 = 500, 0
print('S 2 {} {} {} {} 0 0.5 0 10 100 1 0'.format(x1, y1, x2, y2))
# Grating parameters
refractive_idx = 0.4
height = 40
width = 6
spacing = 6
start_height = 300
max_width, max_height = (resolution, resolution)
period_length = width + spacing
n_periods = int((resolution / period_length))
# Construct grating
for i in range(n_periods):
x0, y0 = (period_length * i, start_height)
x1, y1 = (x0 + width, start_height + height)
print('g 0 {} {} {} {} 0 {} {}'.format(x0, y0, x1, y1, refractive_idx, refractive_idx))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment