# Output an Animated Trigonometry Circle

I want you to write a program that outputs a trigonometry circle like the one below. I also want you to animate this circle, having the sine line move along the circumference with the other lines move around it. The minimum number of unique frames is 5. Any lower and your entry will not be counted.

The lines you will need are:

• Sine (Both)
• Cosine (Both)
• Secant
• Cosecant
• Tangent
• Cotangent
• OA (on diagram)

## Edit: No longer a limit

This is a code golf challenge, but I want you to get your code to below my code which is written in BBC BASIC.

Note: I will remove this requirement if the challenge is too hard.

### My code: BBC BASIC - 185 bytes, 232 characters (Thanks Steve)

a=0:REPEAT:CLS:a+=0.005:CIRCLE600,500,300:s=300*SIN(a)+500:c=300*COS(a)+600:sc=300*1/COS(a)+600:cs=300*1/SIN(a)+500:MOVE600,500:DRAWc,s:DRAWc,500:DRAW600,500:DRAWsc,500:DRAWc,s:MOVE600,500:DRAW600,cs:DRAWc,s:DRAW600,s:WAIT 1:UNTIL0


• An image or gif of what your code produces would be very helpful. – Calvin's Hobbies Aug 19 '14 at 15:56
• @Calvin'sHobbies Added – Beta Decay Aug 19 '14 at 16:00
• I count ASCII 232 characters there, though with tokenisation it probably is 185 bytes. Watch out for that byte counter on BBC Basic for Windows. I usually post as an ASCII count. Your code is probabably golfable down below 185 ASCII characters with VDU's though. – Level River St Aug 19 '14 at 16:19
• And when the tangent or cotangent are infinite, what should be drawn? Also, what does "output" mean? Can a program write a gif or video file, or should it output in real time on a canvas? – Peter Taylor Aug 19 '14 at 16:21
• @PeterTaylor When tan and cot are infinite, you could draw it to a very long length. Regarding the format of the output, it can be anything. – Beta Decay Aug 19 '14 at 16:26

## Mathematica, 142 bytes

Graphics[{Circle[],Line/@{{{c=Cos@t,0},{c,s=Sin@t},{0,s}},{{0,0},{1/c,0},{0,1/s},{0,0},{c,s}}},},PlotRange->{r={-2,2},r}]~Animate~{t,0.01,2Pi}


I'm plotting for angles between 0.01 and 2π which conveniently skips any angles where one of the lines would become actually infinite. You can make a GIF from it by replacing Animate with Table, adding a step width of 0.1 say and then using Export on the result:

So I got a bit bored and thought I'd give the full-blown thing a go (with all lines and colours). I omitted the labels, because they are really annoying to position and just clutter everything up.

Animate[
c = Cos@t;
s = Sin@t;
h = Sign@c;
v = Sign@s;
i = .1 h;
j = .1 v;
Graphics[{
Thick,
Circle[],
Line /@ {{{c, -s}, {0, 0}, {c, s}}, {{-i, 0}, {-i, j}, {0,
j}}, {{-i + c, 0}, {-i + c, j}, {c, j}}, {{c - .1 s,
s + .1 c}, {1.1 c - .1 s, 1.1 s + .1 c}, 1.1 {c, s}}},
Circle[{0, 0}, 0.1, {t, Round[t, Pi]}],
Blue,
Line /@ {{{0, 0}, {c, 0}}, {{0, s}, {c, s}}},
Red,
Line /@ {{{0, 0}, {0, s}}, {{c, 0}, {c, s}}},
Darker@Green,
Line[{{c, 0}, {h, 0}}],
Cyan,
Line[{{0, s}, {0, v}}],
Lighter@Lighter@Magenta,
Line[{{h, 0}, {1/c, 0}}],
Darker@Darker@Green,
Line[{{0, v}, {0, 1/s}}],
Orange,
Line[{{0, 1/s}, {c, s}}],
Lighter@Brown,
Line[{{1/c, 0}, {c, s}}],
Gray,
Line[{{c, 0}, {c, -s}}],
Lighter@Gray,
Line[{{c, s}, {h, 0}}],
Lighter@Pink,
Line /@ {{{-.45 h, 0}, {-.55 h, 0}}, {{-.45 h, 1/s}, {-.55 h,
1/s}}},
Arrow[{{-.5 h, 0}, {-.5 h, 1/s}}],
Darker@Cyan,
Line /@ {{{0, -.45 v}, {0, -.55 v}}, {{1/c, -.45 v}, {1/
c, -.55 v}}},
Arrow[{{0, -.5 v}, {1/c, -.5 v}}],
Dashed,
Black,
Line[{{c, s}, 1.3 {c, s}}],
Lighter@Pink,
Line /@ {{{0, 0}, {-.5 h, 0}}, {{0, 1/s}, {-.5 h, 1/s}}},
Darker@Cyan,
Line /@ {{{0, 0}, {0, -.5 v}}, {{1/c, 0}, {1/c, -.5 v}}}
}, PlotRange -> {r = {-2, 2}, r}],
{t, 0.01, 2 Pi}
];


Enjoy!

And because this is still a code-golf question I golfed this down as well, to see how short I could get it. Currently, 719 bytes:

Graphics[{Thick,Arrowheads@{-.05,.05},(z=Circle)[],(n=Line)/@{{p={c=Cos@t,s=Sin@t},o={0,0},{c,-s}},{-{i=.1(h=Sign@c),0},{-i,j=.1(v=Sign@s)},{0,j}},{{-i+c,0},{-i+c,j},{c,j}},{p+(q={-.1s,.1c}),1.1p+q,1.1p}},z[o,0.1,{t,Round[t,Pi]}],{e=Dashed,n[{p,1.3p}]},Blue,n/@{{o,a={c,0}},{b={0,s},p}},Red,n/@{{o,b},{a,p}},g=(d=Darker)@Green,n@{a,{h,0}},y=Cyan,n@{b,{0,v}},(l=Lighter)@l@Magenta,n@{{h,0},f={1/c,0}},d@g,n@{{0,v},u={0,1/s}},Orange,n@{u,p},l@Brown,n@{f,p},r=Gray,n@{a,{c,-s}},l@r,n@{p,{h,0}},l@Pink,n/@{q={{-.45h,0},{-.55h,0}},{u,u}+q},Arrow@{q={-.5h,0},u+q},{e,n/@{{o,q},{u,u+q}}},d@y,n/@{q={{0,-.45v},{0,-.55v}},{f,f}+q},Arrow@{q={0,-.5v},f+q},{e,n/@{{o,q},{f,f+q}}}},PlotRange->{r={-2,2},r}]~Animate~{t,0.01,2Pi,0.05}

• Nice, the colours are great! – Beta Decay Aug 19 '14 at 18:33

# APL (dzaima/APL), 125 bytes

P5.size←2⌿300
t←0
g←P5.G
z←0 0
P5.draw←{g.bg¯1
g.circle 3⌿90
g.ln a←90×1+z,2 1○t
g.rect a
g.ln 90×1+z,(÷2○t),z,z,⍨÷1○t
t+←.1}


Try it online!

Displays it at the top left corner:

## Explanation

P5.size←2⌿300 make a 300x300 canvas

t←0 set angle $$\\theta=0.\$$

g←P5.G shorten drawing namespace

z←0 0 save [0,0] in z

P5.draw←{ Do the following repeatedly:

g.bg¯1 Draw a white background

g.circle 3⌿90 draw a circle of radius 90 at $$\(90, 90)\$$

g.ln a←90×1+z,2 1○t Line from $$\(90,90)\$$ to $$\(90cos\theta, 90sin\theta)\$$ for angle

g.rect a rectangle using the same coordinates

g.ln 90×1+z,(÷2○t),z,z,⍨÷1○t triangle with the points $$\(90, 90),(90,90/cos\theta),(90/sin\theta,90)\$$

t+←.1 increment angle $$\\theta\$$