function jeu(win,x,y,a) // jeu is the interactivity function global u sortie ech; if a==ascii('F') then sortie=%T; end // exit if a==ascii('l') then u=[0,-1]; end // slow down if a==ascii('p') then u=[0, 1]; end // acceleration if a==ascii('w') then u=[1,0]; end // turn left if a==ascii('x') then u=[-1,0]; end // turn right if a==ascii('z') then ech=ech*0.95; end // zoom in if a==ascii('Z') then ech=ech/0.95; end // zoom out endfunction //------------------------- function draw_char(x,couleur) M =[ 1 -1 0 0 -2 -2 0 0 -1 1 0 0 3 3 0; -2 -2 -2 -1 -1 1 1 2 2 2 2 1 1 -1 -1; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]; M =[cos(x(3)),-sin(x(3)),x(1);sin(x(3)),cos(x(3)),x(2);0 0 1]*M; xset('color',couleur); xpoly(M(1,:),M(2,:)); endfunction; //------------------------- function v=f(x,u) // evolution function v =[x(4)*cos(x(3)); x(4)*sin(x(3)); u(1);u(2)]; endfunction //------------------------- global u sortie ech; // global variables to be modified by jeu seteventhandler('jeu'); // start interactivity (see the function 'jeu' above) xset("pixmap", 1); x=[0;0;0;1]; // initial state ech=10; //scale of the graphic window u=[0;0]; // control dt=0.01; rouge=5;bleu=2;blanc=8;vert=3;noir=0;magenta=6;jaune=4; t=0; sortie=%F; while sortie==%F, clf();xset('thickness',1); isoview(-1.5*ech,1.5*ech,-ech,ech); draw_char(x,noir); xset("wshow"); x=x+f(x,u)*dt; // euler t=t+dt; end; seteventhandler('') // delete xdel(); // delete the graphic window