diff scripts/image/rainbow.m @ 16466:ac332eb727dd

Simplify calculation of colormaps * scripts/image/copper.m: Replace slower linspace with range operator. * scripts/image/hot.m: Add test for n==2 to allow elimination of subsequent if conditional tests. Replace mod calculation with simpler expression. * scripts/image/rainbow.m: Replace slower linspace with range operator. Align columns of calculation for better code readability.
author Rik <rik@octave.org>
date Sun, 07 Apr 2013 22:24:34 -0700
parents 1a800034d443
children d63878346099
line wrap: on
line diff
--- a/scripts/image/rainbow.m	Sun Apr 07 17:24:53 2013 -0700
+++ b/scripts/image/rainbow.m	Sun Apr 07 22:24:34 2013 -0700
@@ -49,17 +49,18 @@
   if (n == 1)
     map = [1, 0, 0];
   elseif (n > 1)
-    x = linspace (0, 1, n)';
+    x = [0:(n-1)]' / (n - 1);
 
-    r = ((x < 2/5)
+    r = (  (x < 2/5)
          + (x >= 2/5 & x < 3/5) .* (-5 * x + 3)
          + (x >= 4/5) .* (10/3 * x - 8/3));
 
-    g = ((x < 2/5) .* (5/2 * x)
+    g = (  (x < 2/5) .* (5/2 * x)
          + (x >= 2/5 & x < 3/5)
          + (x >= 3/5 & x < 4/5) .* (-5 * x + 4));
 
-    b = (x >= 3/5 & x < 4/5) .* (5 * x - 3) + (x >= 4/5);
+    b = (  (x >= 3/5 & x < 4/5) .* (5 * x - 3)
+         + (x >= 4/5));
 
     map = [r, g, b];
   else