Skip to content

Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.

C#

A source's amplitude takes decimals

Alexander Graef8028d4ef318e
diff --git a/CLAUDE.md b/CLAUDE.md
index deb8cba..7985b73 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -96,7 +96,7 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDA
`Reset`, `SetEmitters`, `SetProbes`. Numerics are Jeroen's (dx = dt = 1, leapfrog, 9-point or 4th-order
Laplacian, soft sources, EMA intensity; a scene pixel with red 0 is a mirror, n = 1000, his V0.30 rule,
2026-10-18), verified CPU = GPU by the harness; seeds from `Pcg32` make CPU = GPU
- bit for bit on random gaps. A source's frequency level and phase take decimals (2026-10-19, Jeroen's point 10); the
+ bit for bit on random gaps. A source's frequency level, amplitude and phase take decimals (2026-10-19, Jeroen's point 10); the
level is capped at 255, above which the grid cannot sample the wave; object sources carry their frequency as a float on
the GPU, the 256-entry table serves the image sources. The importer's fallbacks differ from the model's defaults on purpose.
- **Frames vs steps**: frame k is the state after step `k × VisualizeEvery`.
diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
index 786fb96..97c6cb1 100644
--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
@@ -436,7 +436,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Label.Source.Frequency">Frequenz</s:String>
<s:String x:Key="Hint.Source.Frequency">Frequenz als Stufe bis 255, Dezimalstellen erlaubt, dieselbe Skala wie der Grünkanal der Bildquellen. Über 255 kann das Gitter die Welle nicht mehr abtasten.</s:String>
<s:String x:Key="Label.Source.Amplitude">Amplitude</s:String>
- <s:String x:Key="Hint.Source.Amplitude">Amplitude in Prozent, 0 bis 100.</s:String>
+ <s:String x:Key="Hint.Source.Amplitude">Amplitude in Prozent, 0 bis 100, Dezimalstellen erlaubt.</s:String>
<s:String x:Key="Label.Source.Phase">Phase</s:String>
<s:String x:Key="Hint.Source.Phase">Phasenversatz in Grad, -180 bis 180.</s:String>
<s:String x:Key="Label.Source.Mode">Modus</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
index 75f3b1f..9304ff9 100644
--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
@@ -438,7 +438,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Label.Source.Frequency">Frequency</s:String>
<s:String x:Key="Hint.Source.Frequency">Frequency as a level up to 255, decimals allowed, the same scale as the green channel of image sources. Above 255 the grid cannot sample the wave.</s:String>
<s:String x:Key="Label.Source.Amplitude">Amplitude</s:String>
- <s:String x:Key="Hint.Source.Amplitude">Amplitude in percent, 0 to 100.</s:String>
+ <s:String x:Key="Hint.Source.Amplitude">Amplitude in percent, 0 to 100, decimals allowed.</s:String>
<s:String x:Key="Label.Source.Phase">Phase</s:String>
<s:String x:Key="Hint.Source.Phase">Phase offset in degrees, -180 to 180.</s:String>
<s:String x:Key="Label.Source.Mode">Mode</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
index 635e93c..eb82d15 100644
--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
@@ -436,7 +436,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Label.Source.Frequency">Fréquence</s:String>
<s:String x:Key="Hint.Source.Frequency">Fréquence sous forme de niveau jusqu'à 255, décimales admises, la même échelle que le canal vert des sources d'image. Au-delà de 255, la grille ne peut plus échantillonner l'onde.</s:String>
<s:String x:Key="Label.Source.Amplitude">Amplitude</s:String>
- <s:String x:Key="Hint.Source.Amplitude">Amplitude en pour cent, 0 à 100.</s:String>
+ <s:String x:Key="Hint.Source.Amplitude">Amplitude en pour cent, 0 à 100, décimales admises.</s:String>
<s:String x:Key="Label.Source.Phase">Phase</s:String>
<s:String x:Key="Hint.Source.Phase">Décalage de phase en degrés, -180 à 180.</s:String>
<s:String x:Key="Label.Source.Mode">Mode</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
index bd163d3..a066c48 100644
--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
@@ -436,7 +436,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Label.Source.Frequency">Frequentie</s:String>
<s:String x:Key="Hint.Source.Frequency">Frequentie als niveau tot 255, decimalen toegestaan, dezelfde schaal als het groene kanaal van beeldbronnen. Boven 255 kan het raster de golf niet meer bemonsteren.</s:String>
<s:String x:Key="Label.Source.Amplitude">Amplitude</s:String>
- <s:String x:Key="Hint.Source.Amplitude">Amplitude in procent, 0 tot 100.</s:String>
+ <s:String x:Key="Hint.Source.Amplitude">Amplitude in procent, 0 tot 100, decimalen toegestaan.</s:String>
<s:String x:Key="Label.Source.Phase">Fase</s:String>
<s:String x:Key="Hint.Source.Phase">Faseverschuiving in graden, -180 tot 180.</s:String>
<s:String x:Key="Label.Source.Mode">Modus</s:String>
diff --git a/WaveDudeNext/Model/LegacyProject.cs b/WaveDudeNext/Model/LegacyProject.cs
index d5a6744..b20810e 100644
--- a/WaveDudeNext/Model/LegacyProject.cs
+++ b/WaveDudeNext/Model/LegacyProject.cs
@@ -187,7 +187,7 @@ public static class LegacyProject
}
source.DetachAfter = Bool(item, "detach_source", false) ? Int(item, "detach_after_steps", 1000) : Source.NeverDetach;
source.Frequency = Double(item, "frequency", Source.DefaultLevel);
- source.Amplitude = Int(item, "amplitude", Source.DefaultAmplitude);
+ source.Amplitude = Double(item, "amplitude", Source.DefaultAmplitude);
source.Phase = Double(item, "phase_deg", 0.0);
source.Mode = Text(item, "mode", "continuous") == "pulsed" ? SourceMode.Pulsed : SourceMode.Continuous;
source.PulseShape = Text(item, "pulse_shape", "gaussian") == "smoothed_square" ? PulseShape.SmoothedSquare : PulseShape.Gaussian;
diff --git a/WaveDudeNext/Model/Source.cs b/WaveDudeNext/Model/Source.cs
index 75cf2e7..3049671 100644
--- a/WaveDudeNext/Model/Source.cs
+++ b/WaveDudeNext/Model/Source.cs
@@ -54,7 +54,7 @@ public sealed class Source : ObservableObject
/// <summary>Default <see cref="Frequency"/>.</summary>
public const double DefaultLevel = 100.0;
/// <summary>Default <see cref="Amplitude"/> in percent.</summary>
- public const int DefaultAmplitude = 100;
+ public const double DefaultAmplitude = 100.0;
/// <summary>Default <see cref="PulseWidth"/> and <see cref="OffWidth"/> in cycles.</summary>
public const int DefaultWidth = 10;
/// <summary>Value of <see cref="DetachAfter"/> meaning the source stays on for the whole run.</summary>
@@ -65,7 +65,7 @@ public sealed class Source : ObservableObject
private int _x;
private int _y;
private double _frequency = DefaultLevel;
- private int _amplitude = DefaultAmplitude;
+ private double _amplitude = DefaultAmplitude;
private double _phase;
private SourceMode _mode = SourceMode.Continuous;
private PulseShape _pulseShape = PulseShape.Gaussian;
@@ -126,12 +126,12 @@ public sealed class Source : ObservableObject
set => SetProperty(ref _frequency, value);
}
- /// <summary>Amplitude in percent, 0 to 100.</summary>
+ /// <summary>Amplitude in percent, 0 to 100, decimals allowed: the engines scale the source by a real factor, and whole percents were only a spin-box setting in Wave Dude 2D.</summary>
[XmlAttribute]
[DefaultValue(DefaultAmplitude)]
[Category("Wave")]
- [Description("Amplitude in percent, 0 to 100.")]
- public int Amplitude
+ [Description("Amplitude in percent, 0 to 100, decimals allowed.")]
+ public double Amplitude
{
get => _amplitude;
set => SetProperty(ref _amplitude, value);
@@ -267,7 +267,7 @@ public sealed class Source : ObservableObject
{
Name ??= "";
Frequency = double.IsFinite(Frequency) ? Math.Clamp(Frequency, MinLevel, MaxLevel) : DefaultLevel;
- Amplitude = Math.Clamp(Amplitude, 0, 100);
+ Amplitude = double.IsFinite(Amplitude) ? Math.Clamp(Amplitude, 0.0, 100.0) : DefaultAmplitude;
Phase = double.IsFinite(Phase) ? Math.Clamp(Phase, -180.0, 180.0) : 0.0;
PulseWidth = Math.Max(1, PulseWidth);
OffWidth = Math.Max(1, OffWidth);
diff --git a/_tools/library_check/Program.cs b/_tools/library_check/Program.cs
index 8354ad2..6463833 100644
--- a/_tools/library_check/Program.cs
+++ b/_tools/library_check/Program.cs
@@ -628,7 +628,7 @@ internal static class Program
private static void CheckDecimalLevels(int W, int H)
{
- Console.WriteLine("--- decimal frequency and phase");
+ Console.WriteLine("--- decimal frequency, amplitude and phase");
var project = new Project();
project.Scene.Width = W;
project.Scene.Height = H;
@@ -636,17 +636,20 @@ internal static class Program
source.X = 20;
source.Y = 24;
source.Frequency = 120.5;
+ source.Amplitude = 33.3;
source.Phase = 12.5;
RunSpec spec = RunSpec.Create(project, null, preferGpu: false);
- Check(spec.Emitters.Length == 1 && spec.Emitters[0].Level == 120.5 && Math.Abs(spec.Emitters[0].PhaseRadians - 12.5 * Math.PI / 180.0) < 1e-12, "a decimal frequency and phase reach the emitter as typed");
+ Check(spec.Emitters.Length == 1 && spec.Emitters[0].Level == 120.5 && Math.Abs(spec.Emitters[0].Amplitude - 0.333) < 1e-12 && Math.Abs(spec.Emitters[0].PhaseRadians - 12.5 * Math.PI / 180.0) < 1e-12, "a decimal frequency, amplitude and phase reach the emitter as typed");
source.Frequency = 300;
+ source.Amplitude = 100.5;
source.Phase = -200;
source.Normalize();
- Check(source.Frequency == 255 && source.Phase == -180, "the level is capped at 255 (the grid cannot sample above it), the phase at -180");
+ Check(source.Frequency == 255 && source.Amplitude == 100 && source.Phase == -180, "the level is capped at 255 (the grid cannot sample above it), the amplitude at 100, the phase at -180");
source.Frequency = 0;
source.Normalize();
Check(source.Frequency == Source.MinLevel, "a level of 0 becomes the least level");
source.Frequency = 120.5;
+ source.Amplitude = 33.3;
source.Phase = 12.5;
using (var stream = new MemoryStream())
{
@@ -654,7 +657,7 @@ internal static class Program
string xml = System.Text.Encoding.UTF8.GetString(stream.ToArray());
stream.Position = 0;
Project back = Project.Load(stream);
- Check(xml.Contains("Frequency=\"120.5\"") && xml.Contains("Phase=\"12.5\"") && back.Sources[0].Frequency == 120.5 && back.Sources[0].Phase == 12.5, "decimals round-trip through the file");
+ Check(xml.Contains("Frequency=\"120.5\"") && xml.Contains("Amplitude=\"33.3\"") && xml.Contains("Phase=\"12.5\"") && back.Sources[0].Frequency == 120.5 && back.Sources[0].Amplitude == 33.3 && back.Sources[0].Phase == 12.5, "decimals round-trip through the file");
}
SceneData scene = SceneData.Empty(W, H, 0);
var emitters = new List<Emitter> { Make(20, 24, 120, 1.0) with { Level = 120.5, PhaseRadians = 12.5 * Math.PI / 180.0 } };