summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/examples/animations/wheel.asy
blob: 6620d5908506ef8f1370431d0374c1f5cec534f8 (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
54
55
56
57
58
59
60
61
62
63
import graph;

// Uncomment the following 2 lines to support pdf animations:
// usepackage("animate");
// settings.tex="pdflatex";

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;

animation a;

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);

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();
}

erase();

// Merge the images into a gif animation.
a.movie(BBox(0.25cm),loops=10,delay=250);

// Merge the images into a pdf animation.
// label(a.pdf(BBox(0.25cm),delay=250,"controls",multipage=false));