What I want to do is to draw graphics part by part, because I made a function that generates coordinates according to which I will draw graphics. The problem is that MMA does not operate as I expected. To figure out what I'm doing here's simplified example:
Graphics[{
a = 1;
Label[tag];
If[a < 3,
{Circle[{a, 1}, 1],
a = a + 1;
Goto[tag];},
{Text["It's finished", {0, 0}]}]
}]
And what I get as output is simply text "It's finished". But what I want as output is graphics with two circles with radii 1 and centers positioned at {1,1} and {2,1} together with text "It's finished".
I figure out the way MMA thinks, and why it gives me this as output. But how can I accomplish my desired output?
Edit:
Here's the code, It's really messy and tips on how to neatly write code in MMA would be appreciated.
Manipulate[
Graphics[{
(*calculating incident angle*)
α = ArcSin[H/R];
(*calculating x-coordinate where incident ray leaves prism*)
p = Sqrt[R^2 - H^2];
(*Drawing incident ray*)
{Red, Thick, Line[{{-2, H}, {p, H}}]},
(*Drawing prism*)
{Blue, Opacity[.5], Disk[{0, 0}, R, {0, Pi/2}]},
(*checking whether it's reflection or refraction*)
If[H < R/n,
{(*refraction*)
(*calculating x-coordinate where refracted ray hits surface*)
l = (R^2 n)/(Sqrt[R^2 - H^2] n - Sqrt[R^2 - H^2 n^2]);
(*Drawing refracted ray*)
{Red, Thick, Line[{{p, H}, {l, 0}}]}
},
{(*internal reflection*)
(*calculating x-coordinate where after internal reflection ray hits \
surface*)
new = H;
k = 1;
Label[tag];
s = R Cos[α] - new/Tan[2 α];
If[s <= R,
{
{Red, Thick, Line[{{p, new}, {s, 0}}]}
},
{
θ = (2 k + 1) α - k Pi;
f = R Cos[θ];
h = R Sin[θ];
k = k + 1;
Line[{{{p, new}, {f, h}}}],
new = h;
p = f;
Goto[tag];
}
]
}
]
}],
{{H, 3, "Height"}, 0.0001, R - 0.0001, Appearance -> "Labeled"},
{{n, 1.5, "Refraction"}, 1.001, 2, Appearance -> "Labeled"},
{{R, 10, "Radius"}, 0, 10, Appearance -> "Labeled"}
]
Goto
? It'll be more complicated than what I gave below. $\endgroup$