Qubit passing through quantum gate animation
Perhaps something like this?
Animate[
Graphics[
{ FaceForm[White]
, EdgeForm[{Thick, Black}]
, {Gray, Line[{{-12, 0}, {12, 0}}]}
, Disk[{t, 0}, 2]
, Text[Style[If[t < 0, "|0〉", "|1〉"], 32], {t, 0}]
, Rectangle[{-3, -3}, {3, 3}]
, Text[Style["X", 64], {0, 0}]
}
, PlotRange -> {{-12, 12}, Automatic}
]
, {t, -10, 10}
]
The key to making the qubit disappear behind the gate is to ensure that the Rectangle
is opaque and drawn after the Disk
is drawn (i.e. the rectangle appears later in the list of Graphics
directives than the disk). The label change is accomplished by the If
expression which evaluates to |0〉 prior to time zero and |1〉 thereafter. Finally, the unsightly resizing of the graphic is prevented by explicitly specifying the left and right edges of the plot range.
Going off WReach's clever transition, here are a couple of alternative transitions. These transitions all have a sort of "sharpness" parameter, so I've put them in a Manipulate
and you can let the time play and adjust the parameter as you wish. Mix and match them as you please (and remember that the order in which the Graphics
elements are drawn matters)!
Fade
Manipulate[
Graphics[{
Thick, Opacity[Abs[opacityfactor*t]], Circle[{t, 0}, 2],
Text[Style[
If[t < 0, "|0〉", "|1〉"],
32], {t, 0}],
Opacity[1], EdgeForm[Thick], FaceForm[White],
Rectangle[{-3, -3}, {3, 3}], Text[Style["X", 64]]
}, PlotRange -> {{-12, 12}, Automatic}]
, {t, -10, 10}, {{opacityfactor, .1}, .05, .3}]
Highlight
Manipulate[
Graphics[{
Thick, Circle[{t, 0}, 2],
Style[Circle[{t, 0}, Max[Abs[1.5*t], 2]], Red, Thick,
Opacity[If[Abs[t] < cutoff, 1, 0]]],
Text[Style[
If[t < 0, "|0〉", "|1〉"],
32], {t, 0}],
Opacity[1], EdgeForm[Thick], FaceForm[White],
Rectangle[{-3, -3}, {3, 3}], Text[Style["X", 64]]
}, PlotRange -> {{-12, 12}, {-5, 5}}]
, {t, -10, 10}, {{cutoff, 4}, 1, 6}]
Exporting
And for your convenience, here are the exportable commands:
Fade
opacityfactor = .1;
fade = Table[
Graphics[{
Thick, Opacity[Abs[opacityfactor*t]], Circle[{t, 0}, 2],
Text[
Style[If[t < 0, "|0〉",
"|1〉"], 32], {t, 0}],
Opacity[1], EdgeForm[Thick], FaceForm[White],
Rectangle[{-3, -3}, {3, 3}], Text[Style["X", 64]]
}, PlotRange -> {{-12, 12}, Automatic}], {t, -10, 10, 0.4}];
Export["fade.gif", fade]
Highlight
cutoff = 4;
highlight = Table[
Graphics[{
Thick, Circle[{t, 0}, 2],
Style[Circle[{t, 0}, Max[Abs[1.5*t], 2]], Red, Thick,
Opacity[If[Abs[t] < cutoff, 1, 0]]],
Text[
Style[If[t < 0, "|0〉",
"|1〉"], 32], {t, 0}],
Opacity[1], EdgeForm[Thick], FaceForm[White],
Rectangle[{-3, -3}, {3, 3}], Text[Style["X", 64]]
}, PlotRange -> {{-12, 12}, {-5, 5}}], {t, -10, 10, 0.4}];
Export["highlight.gif", highlight]