1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2011 - INRIA - Serge Steer <serge.steer@inria.fr>
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
13 function comet(varargin)
14 //Comet-like trajectory.
15 // comet(y) displays an animated comet plot of the vector y.
16 // comet(x,y) displays an animated comet plot of vector y vs. x.
17 // comet(x,y,p) uses a comet of length p*size(y,'*'). Default is p = 0.1.
20 // t = linspace(0,10*%pi,500);
21 // clf();comet(t.*sin(t),t.*cos(t))
23 // function y=traj(x),y=1.5*sin(x^2),endfunction
24 // clf();comet(linspace(0,5,500),traj)
26 // clf();comet(linspace(-2,4,500),(%s-3)/(%s^3+2*%s^2+1))
29 if nv>=3&varargin(nv-1)=="colors" then
31 if type(c)<>1|~isreal(c) then
32 error(msprintf(_("%s: Wrong type for argument #%d: Real vector expected.\n"),"comet",nv))
34 varargin=list(varargin(1:$-2))
41 if or(size(y)==1) then
53 error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),"comet",1,3))
55 if type(x)<>1|~isreal(x) then
56 error(msprintf(_("%s: Wrong type for argument #%d: Real vector expected.\n"),"comet",1))
58 if type(y)==13 then //a function
59 prot=funcprot();funcprot(0)
62 elseif type(y)==2 then //a polynomial
64 elseif typeof(y)=="rational" then //a rational fraction
67 if type(y)<>1|~isreal(y) then
68 error(msprintf(_("%s: Wrong type for argument #%d: Real vector expected.\n"),"comet",2))
70 if type(p)<>1|~isreal(p)|size(p,"*")>1 then
71 error(msprintf(_("%s: Wrong type for argument #%d: Real scalar expected.\n"),"comet",3))
74 error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the interval %s.\n"),"comet",3,"[0 1["))
77 if or(size(x)==1) then
80 if or(size(y)==1) then
81 if n<>size(y,"*") then
82 error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"comet",1,2))
89 error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same number of rows expected.\n"),"comet",1,2))
96 if or(size(y)<>size(x)) then
97 error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"comet",1,2))
104 if size(c,"*")<>m then
105 error(msprintf(_("%s: Wrong size for argument #%d: %d expected.\n"),"comet",nv,m))
107 if min(c)<1|max(c)>size(fig.color_map,1) then
108 error(msprintf(_( "%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"comet",nv,"1,...,"+string(size(fig.color_map,1))))
113 if axes.children==[] then
114 axes.data_bounds=[min(x) min(y);max(x) max(y)];
115 axes.axes_visible="on";
117 axes.data_bounds=[min(axes.data_bounds(1,:), [min(x) min(y)]);
118 max(axes.data_bounds(2,:), [max(x) max(y)])];
120 //create the head, body and tail polylines
122 tail=[];body=[];head=[];
124 xpoly([],[]);tail(l)=gce();
125 tail(l).foreground=c(l);
126 xpoly([],[]);body(l)=gce();
127 body(l).foreground=c(l);
129 xpoly([],[],"marks");head(l)=gce();
130 head(l).mark_size_unit="point";
132 head(l).mark_style=9;
133 head(l).mark_foreground=c(l);
141 step=ceil(n/200); //used to speed up the drawing
145 head(l).data=[x(i,l),y(i,l)];
147 body(l).data= [body(l).data;[x(i,l),y(i,l)]];
149 body(l).data= [body(l).data(2:$,:);[x(i,l),y(i,l)]];
150 tail(l).data=[ tail(l).data;[x(i-k+1,l),y(i-k+1,l)]];
153 if modulo(i,step)==0 then
154 fig.immediate_drawing = "on"
155 fig.immediate_drawing = "off"
158 fig.immediate_drawing = "on"
159 fig.immediate_drawing = "off"
162 body(l).data= body(l).data(2:$,:);
163 tail(l).data=[tail(l).data;[x(n-k+i,l),y(n-k+i,l)]];
165 if modulo(i,step)==0 then
166 fig.immediate_drawing = "on"
167 fig.immediate_drawing = "off"
170 fig.immediate_drawing = "on"
173 //not to generate an error message if the window is closed
174 exec(anim, "errcatch", -1);