File:Incoherent sum of speckles.webm
Summary
Description |
English: Coherent light passing through a scattering medium is scrambled into a speckle pattern. But if there are multiple sources incoherent with each other, the resulting pattern will be the incoherent sum of the speckle patterns generated by each source. |
Date | |
Source | https://twitter.com/j_bertolotti/status/1553005005304696832 |
Author | Jacopo Bertolotti |
Permission (Reusing this file) |
https://twitter.com/j_bertolotti/status/1030470604418428929 |
Mathematica 13.0 code
dim = 256;
texture = ExampleData[{"Texture", "Sand3"}];
color1[x_] := RGBColor[0.368417, 0.506779, 0.709798, x];
color2[x_] := RGBColor[0.922526, 0.385626, 0.209179, x];
speckle[] :=
Abs[Fourier[
RandomComplex[{-1 - I, 1 + I}, {dim, dim}]*
GaussianMatrix[{dim/2, dim/30}][[1 ;; -2, 1 ;; -2]]]]^2;
tmp1 = speckle[]*
GaussianMatrix[{dim/2, dim/4}][[1 ;; -2, 1 ;; -2]]; tmp1 = tmp1/
Max[tmp1];
tmp2 = speckle[]*
GaussianMatrix[{dim/2, dim/4}][[1 ;; -2, 1 ;; -2]]; tmp2 = tmp2/
Max[tmp2];
tmp3 = speckle[]*
GaussianMatrix[{dim/2, dim/4}][[1 ;; -2, 1 ;; -2]]; tmp3 = tmp3/
Max[tmp3];
source1 =
RotateRight[
GaussianMatrix[{dim/2, dim/40}][[1 ;; -2, 1 ;; -2]], {-50,
20}]; source1 = source1/Max[source1];
source2 =
RotateRight[
GaussianMatrix[{dim/2, dim/40}][[1 ;; -2, 1 ;; -2]], {50,
80}]; source2 = source2/Max[source2];
source3 =
RotateRight[
GaussianMatrix[{dim/2, dim/40}][[1 ;; -2,
1 ;; -2]], {20, -50}]; source3 = source3/Max[source3];
frames1 = Table[
s = ArrayPlot[a*tmp1, DataReversed -> True,
ColorFunction -> "SunsetColors", ColorFunctionScaling -> False,
PlotRangePadding -> None];
sourceplot =
ArrayPlot[a*source1, DataReversed -> True,
ColorFunction -> "SunsetColors", ColorFunctionScaling -> False,
PlotRangePadding -> None];
Graphics3D[{
Texture[texture],
Polygon[{{-1.5, 2, -1.5}, {-1.5, 2, 1.5}, {1.5, 2, 1.5}, {1.5,
2, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}],
Texture[sourceplot],
Polygon[{{-1.5, 5, -1.5}, {-1.5, 5, 1.5}, {1.5, 5, 1.5}, {1.5,
5, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
, Black, Thick,
Line[{{-1.5, 2, -1.5}, {-1.5, 2, 1.5}, {1.5, 2, 1.5}, {1.5,
2, -1.5}, {-1.5, 2, -1.5}}],
Texture[s],
Polygon[{{-1.5, -1, -1.5}, {-1.5, -1, 1.5}, {1.5, -1,
1.5}, {1.5, -1, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
}, PlotRange -> {{-2, 2}, {-1.5, 5}, {-2, 2}},
ViewPoint -> {-1.3, - 2.4, 2.}, Boxed -> False,
Lighting -> "Neutral", Background -> White]
, {a, 0, 1, 0.1}];
frames2 = Table[
s = ArrayPlot[a*tmp2, DataReversed -> True,
ColorFunction -> "SunsetColors", ColorFunctionScaling -> False,
PlotRangePadding -> None];
sourceplot =
ArrayPlot[a*source2, DataReversed -> True,
ColorFunction -> "SunsetColors", ColorFunctionScaling -> False,
PlotRangePadding -> None];
Graphics3D[{
Texture[texture],
Polygon[{{-1.5, 2, -1.5}, {-1.5, 2, 1.5}, {1.5, 2, 1.5}, {1.5,
2, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}],
Texture[sourceplot],
Polygon[{{-1.5, 5, -1.5}, {-1.5, 5, 1.5}, {1.5, 5, 1.5}, {1.5,
5, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
, Black, Thick,
Line[{{-1.5, 2, -1.5}, {-1.5, 2, 1.5}, {1.5, 2, 1.5}, {1.5,
2, -1.5}, {-1.5, 2, -1.5}}],
Texture[s],
Polygon[{{-1.5, -1, -1.5}, {-1.5, -1, 1.5}, {1.5, -1,
1.5}, {1.5, -1, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
}, PlotRange -> {{-2, 2}, {-1.5, 5}, {-2, 2}},
ViewPoint -> {-1.3, - 2.4, 2.}, Boxed -> False,
Lighting -> "Neutral", Background -> White]
, {a, 0, 1, 0.1}];
frames3 = Table[
s = ArrayPlot[a*tmp3, DataReversed -> True,
ColorFunction -> "SunsetColors", ColorFunctionScaling -> False,
PlotRangePadding -> None];
sourceplot =
ArrayPlot[a*source3, DataReversed -> True,
ColorFunction -> "SunsetColors", ColorFunctionScaling -> False,
PlotRangePadding -> None];
Graphics3D[{
Texture[texture],
Polygon[{{-1.5, 2, -1.5}, {-1.5, 2, 1.5}, {1.5, 2, 1.5}, {1.5,
2, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}],
Texture[sourceplot],
Polygon[{{-1.5, 5, -1.5}, {-1.5, 5, 1.5}, {1.5, 5, 1.5}, {1.5,
5, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
, Black, Thick,
Line[{{-1.5, 2, -1.5}, {-1.5, 2, 1.5}, {1.5, 2, 1.5}, {1.5,
2, -1.5}, {-1.5, 2, -1.5}}],
Texture[s],
Polygon[{{-1.5, -1, -1.5}, {-1.5, -1, 1.5}, {1.5, -1,
1.5}, {1.5, -1, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
}, PlotRange -> {{-2, 2}, {-1.5, 5}, {-2, 2}},
ViewPoint -> {-1.3, - 2.4, 2.}, Boxed -> False,
Lighting -> "Neutral", Background -> White]
, {a, 0, 1, 0.1}];
frames4 = Table[
s = ArrayPlot[a*(tmp1 + tmp2 + tmp3), DataReversed -> True,
ColorFunction -> "SunsetColors", ColorFunctionScaling -> False,
PlotRangePadding -> None];
sourceplot =
ArrayPlot[a*(source1 + source2 + source3), DataReversed -> True,
ColorFunction -> "SunsetColors", ColorFunctionScaling -> False,
PlotRangePadding -> None];
Graphics3D[{
Texture[texture],
Polygon[{{-1.5, 2, -1.5}, {-1.5, 2, 1.5}, {1.5, 2, 1.5}, {1.5,
2, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}],
Texture[sourceplot],
Polygon[{{-1.5, 5, -1.5}, {-1.5, 5, 1.5}, {1.5, 5, 1.5}, {1.5,
5, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
, Black, Thick,
Line[{{-1.5, 2, -1.5}, {-1.5, 2, 1.5}, {1.5, 2, 1.5}, {1.5,
2, -1.5}, {-1.5, 2, -1.5}}],
Texture[s],
Polygon[{{-1.5, -1, -1.5}, {-1.5, -1, 1.5}, {1.5, -1,
1.5}, {1.5, -1, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
}, PlotRange -> {{-2, 2}, {-1.5, 5}, {-2, 2}},
ViewPoint -> {-1.3, - 2.4, 2.}, Boxed -> False,
Lighting -> "Neutral", Background -> White]
, {a, 0, 1, 0.1}];
time1 = Sum[
UnitStep[t - \[Tau]] E^(-0.5 (t - \[Tau])), {\[Tau],
Evaluate[
Accumulate@RandomVariate[ExponentialDistribution[0.1], {20}]]}];
timeseries1 = Table[time1, {t, 1, 100, 1}];
time2 = Sum[
UnitStep[t - \[Tau]] E^(-0.5 (t - \[Tau])), {\[Tau],
Evaluate[
Accumulate@RandomVariate[ExponentialDistribution[0.1], {20}]]}];
timeseries2 = Table[time2, {t, 1, 100, 1}];
time3 = Sum[
UnitStep[t - \[Tau]] E^(-0.5 (t - \[Tau])), {\[Tau],
Evaluate[
Accumulate@RandomVariate[ExponentialDistribution[0.1], {20}]]}];
timeseries3 = Table[time3, {t, 1, 100, 1}];
frames5 = Table[
s = ArrayPlot[(timeseries1[[t]]*tmp1 + timeseries2[[t]]*tmp2 +
timeseries3[[t]]*tmp3), DataReversed -> True,
ColorFunction -> "SunsetColors", ColorFunctionScaling -> False,
PlotRangePadding -> None];
sourceplot =
ArrayPlot[(timeseries1[[t]]*source1 + timeseries2[[t]]*source2 +
timeseries3[[t]]*source3), DataReversed -> True,
ColorFunction -> "SunsetColors", ColorFunctionScaling -> False,
PlotRangePadding -> None];
Graphics3D[{
Texture[texture],
Polygon[{{-1.5, 2, -1.5}, {-1.5, 2, 1.5}, {1.5, 2, 1.5}, {1.5,
2, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}],
Texture[sourceplot],
Polygon[{{-1.5, 5, -1.5}, {-1.5, 5, 1.5}, {1.5, 5, 1.5}, {1.5,
5, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
, Black, Thick,
Line[{{-1.5, 2, -1.5}, {-1.5, 2, 1.5}, {1.5, 2, 1.5}, {1.5,
2, -1.5}, {-1.5, 2, -1.5}}],
Texture[s],
Polygon[{{-1.5, -1, -1.5}, {-1.5, -1, 1.5}, {1.5, -1,
1.5}, {1.5, -1, -1.5}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
}, PlotRange -> {{-2, 2}, {-1.5, 5}, {-2, 2}},
ViewPoint -> {-1.3, - 2.4, 2.}, Boxed -> False,
Lighting -> "Neutral", Background -> White]
, {t, 1, 100, 1}];
Export["path/filename.mp4",
Join[frames1, Reverse[frames1], frames2, Reverse[frames2], frames3,
Reverse[frames3], frames4, Reverse[frames4], frames5]
, "AnimationRepetitions" -> \[Infinity], "DisplayDurations" -> 0.1]
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
![]() ![]() |
This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication. |
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
|