1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2011 - INRIA - Serge Steer <serge.steer@inria.fr>
3 // Copyright (C) 2012 - 2016 - Scilab Enterprises
4 // Copyright (C) 2018 - Samuel GOUGEON
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.
17 // comet(x, y, Lf) // Lf: Leading fraction
18 // comet(x, fun) // fun: function identifier, polynomial, rational
20 // comet(..., "colors",c) // c: -1, 4, "orange", "ma", "#RRGGBB", [r g b]
23 // 2018: colors as "name" "nam" "#RRGGBB" or [r g b] now allowed
26 if nv >= 3 & varargin(nv-1)=="colors" then
27 c = iscolor( varargin(nv))
29 msg = "%s: Argument #%d: Wrong color specification.\n";
30 error(msprintf(msg, "comet", nv))
35 varargin = list(varargin(1:$-2))
43 if or(size(y)==1) then
55 msg = _("%s: Wrong number of input arguments: %d to %d expected.\n");
56 error(msprintf(msg, "comet", 1, 5))
58 if type(x)<>1|~isreal(x) then
59 msg = _("%s: Wrong type for argument #%d: Real vector expected.\n");
60 error(msprintf(msg, "comet", 1))
62 if type(y)==13 then //a function
63 prot=funcprot();funcprot(0)
66 elseif type(y)==2 then //a polynomial
68 elseif typeof(y)=="rational" then //a rational fraction
71 if type(y)<>1|~isreal(y) then
72 msg = _("%s: Wrong type for argument #%d: Real vector expected.\n");
73 error(msprintf(msg, "comet", 2))
75 if type(p)<>1|~isreal(p)|size(p,"*")>1 then
76 msg = _("%s: Wrong type for argument #%d: Real scalar expected.\n");
77 error(msprintf(msg, "comet", 3))
80 msg = _("%s: Wrong value for input argument #%d: Must be in the interval %s.\n");
81 error(msprintf(msg, "comet", 3, "[0 1["))
84 if or(size(x)==1) then
87 if or(size(y)==1) then
88 if n<>size(y,"*") then
89 msg = _("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n");
90 error(msprintf(msg, "comet", 1, 2))
97 msg = _("%s: Incompatible input arguments #%d and #%d: Same number of rows expected.\n")
98 error(msprintf(msg, "comet", 1, 2))
105 if or(size(y)<>size(x)) then
106 msg = _("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n")
107 error(msprintf(msg, "comet", 1, 2))
114 if size(c,"*") <> m then
115 msg = _("%s: Wrong size for argument #%d: %d expected.\n")
116 error(msprintf(msg, "comet", nv, m))
121 if axes.children==[] then
122 axes.data_bounds=[min(x) min(y);max(x) max(y)];
123 axes.axes_visible="on";
125 axes.data_bounds=[min(axes.data_bounds(1,:), [min(x) min(y)]);
126 max(axes.data_bounds(2,:), [max(x) max(y)])];
128 //create the head, body and tail polylines
130 tail=[];body=[];head=[];
132 xpoly([],[]);tail(l)=gce();
133 tail(l).foreground=c(l);
134 xpoly([],[]);body(l)=gce();
135 body(l).foreground=c(l);
137 xpoly([],[],"marks");head(l)=gce();
138 head(l).mark_size_unit="point";
140 head(l).mark_style=9;
141 head(l).mark_foreground=c(l);
149 step=ceil(n/200); //used to speed up the drawing
153 head(l).data=[x(i,l),y(i,l)];
155 body(l).data= [body(l).data;[x(i,l),y(i,l)]];
157 body(l).data= [body(l).data(2:$,:);[x(i,l),y(i,l)]];
158 tail(l).data=[ tail(l).data;[x(i-k+1,l),y(i-k+1,l)]];
161 if modulo(i,step)==0 then
162 fig.immediate_drawing = "on"
163 fig.immediate_drawing = "off"
166 fig.immediate_drawing = "on"
167 fig.immediate_drawing = "off"
170 body(l).data= body(l).data(2:$,:);
171 tail(l).data=[tail(l).data;[x(n-k+i,l),y(n-k+i,l)]];
173 if modulo(i,step)==0 then
174 fig.immediate_drawing = "on"
175 fig.immediate_drawing = "off"
178 fig.immediate_drawing = "on"
181 //not to generate an error message if the window is closed
182 exec(anim, "errcatch", -1);