summaryrefslogtreecommitdiff
path: root/Master/texmf/doc/asymptote/examples/animations/wheel.asy
blob: 2ea45f75613cf74cbfb2ea2d4e100e5b3e4d1d4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import graph;
import animation;

size(0,200);

defaultpen(3);
dotfactor=4;

pair wheelpoint(real t)
{
  return (t+cos(t),-sin(t));
}

guide wheel(guide g=nullpath, real a, real b, int n)
{
  real width=(b-a)/n;
  for(int i=0; i <= n; ++i) {
    real t=a+width*i;
    g=g--wheelpoint(t);
  }
  return g;
}

real t1=0; 
real t2=t1+2*pi;

draw(circle((0,0),1));
draw(wheel(t1,t2,100),linetype("0 2"));
yequals(Label("$y=-1$",1.0),-1,extend=true,linetype("4 4"));
xaxis(Label("$x$",align=3SW),0);
yaxis("$y$",0,1.2);
pair z1=wheelpoint(t1);
pair z2=wheelpoint(t2);
dot(z1);
dot(z2);

animation a;

int n=10;
real dt=(t2-t1)/n;
for(int i=0; i <= n; ++i) {
  save();
  
  real t=t1+dt*i;
  draw(circle((t,0),1),red);
  dot(wheelpoint(t));

  a.add(); // Add currentpicture to animation.
  restore();
}

// Produce the final merged gif.
a.movie(BBox(0.25cm),loops=10,delay=250);