]> Creatis software - CreaPhase.git/blob - octave_packages/vrml-1.0.13/checker_color.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / vrml-1.0.13 / checker_color.m
1 ## Copyright (C) 2010-2012 Etienne Grossmann <etienne@egdn.net>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## col = checker_color (R,C, checker, col)
17
18 function col = checker_color (checker, col, R,C)
19
20 if length (checker) == 1, checker = [checker, checker]; end
21
22 if checker(1) > 0, checker(1) = - (C-1)/checker(1); end
23 if checker(2) > 0, checker(2) = - (R-1)/checker(2); end
24
25 checker *= -1;
26
27 colx = 2 * (rem (0:C-2,2*checker(1)) < checker(1)) - 1;
28 coly = 2 * (rem (0:R-2,2*checker(2)) < checker(2)) - 1;
29 icol = 1 + ((coly'*colx) > 0);
30                                 # Keep at most 1st 2 colors of col for the
31                                 # checker
32 if prod (size (col)) == 2,
33   col = [1;1;1]*col;
34 elseif  prod (size (col)) < 6, # Can't be < 3 because of previous code
35   col = col(1:3)(:);
36   if all (col >= 1-eps), col = [col [0;0;0]];   # Black and White
37   else                   col = [col [1;1;1]];   # X and White
38   end
39 end
40 col = reshape (col(:),3,2);
41 col = col(:,icol);