From 72eff46498152f4affe14d5cd9489e19b35156e2 Mon Sep 17 00:00:00 2001
From: Robert Kaiser <robert@notebook.(none)>
Date: Sun, 2 Aug 2009 00:59:45 +0200
Subject: [PATCH] Convert rainbow palettes from VB to JS code and make them
 available

---
 .../chrome/mandelbrot/content/mandelbrot.js   | 107 +++++++++---------
 .../chrome/mandelbrot/content/mandelbrot.xul  |   4 +
 .../mandelbrot/locales/en-US/mandelbrot.dtd   |   4 +
 3 files changed, 64 insertions(+), 51 deletions(-)

diff --git a/xulapp/chrome/mandelbrot/content/mandelbrot.js b/xulapp/chrome/mandelbrot/content/mandelbrot.js
index 28b443c..1ead31e 100644
--- a/xulapp/chrome/mandelbrot/content/mandelbrot.js
+++ b/xulapp/chrome/mandelbrot/content/mandelbrot.js
@@ -258,10 +258,62 @@ function getColorPalette(palName) {
       }
       palette[1024] = [0, 0, 0, 255];
       break;
+    case 'rainbow-squared1':
+      for (let i = 0; i < 34; i++) {
+        let cc = Math.floor(i * 255 / 33);
+        palette[i] = [cc, 0, 0, 255];
+      }
+      for (let i = 0; i < 137; i++) {
+        let cc = Math.floor(i * 255 / 136);
+        palette[34 + i] = [255, cc, 0, 255];
+      }
+      for (let i = 0; i < 307; i++) {
+        let cc = Math.floor(i * 255 / 306);
+        palette[171 + i] = [255 - cc, 255, cc, 255];
+      }
+      for (let i = 0; i < 546; i++) {
+        let cc = Math.floor(i * 255 / 545);
+        palette[478 + i] = [cc, 255 - cc, 255, 255];
+      }
+      palette[1024] = [0, 0, 0, 255];
+      break;
+    case 'rainbow-linear2':
+      for (let i = 0; i < 205; i++) {
+        let cc = Math.floor(i * 255 / 204);
+        palette[i] = [255, cc, 0, 255];
+        palette[204 + i] = [255 - cc, 255, 0, 255];
+        palette[409 + i] = [0, 255, cc, 255];
+        palette[614 + i] = [0, 255 - cc, 255, 255];
+        palette[819 + i] = [cc, 0, 255, 255];
+      }
+      palette[1024] = [0, 0, 0, 255];
+      break;
+    case 'rainbow-squared2':
+      for (let i = 0; i < 19; i++) {
+        let cc = Math.floor(i * 255 / 18);
+        palette[i] = [255, cc, 0, 255];
+      }
+      for (let i = 0; i < 74; i++) {
+        let cc = Math.floor(i * 255 / 73);
+        palette[19 + i] = [255 - cc, 255, 0, 255];
+      }
+      for (let i = 0; i < 168; i++) {
+        let cc = Math.floor(i * 255 / 167);
+        palette[93 + i] = [0, 255, cc, 255];
+      }
+      for (let i = 0; i < 298; i++) {
+        let cc = Math.floor(i * 255 / 297);
+        palette[261 + i] = [0, 255 - cc, 255, 255];
+      }
+      for (let i = 0; i < 465; i++) {
+        let cc = Math.floor(i * 255 / 464);
+        palette[559 + i] = [cc, 0, 255, 255];
+      }
+      palette[1024] = [0, 0, 0, 255];
+      break;
   }
-/*
-Select Case palnr
-Case 1  'Standard-Palette (QB-Colors)
+  /*
+     'Standard-Palette (QB-Colors)
      For i = 0 To 1024
          xx = CInt(i * 500 / 1024 + 2)
          If xx <= 15 Then clr = xx
@@ -269,54 +321,7 @@ Case 1  'Standard-Palette (QB-Colors)
          If xx >= 500 Then clr = 0
          palette(i) = QBColor(clr)
      Next
-Case 3  'Regenbogen-Palette 1 (qu.)
-     For i = 0 To 33
-         clr = CInt(i * 255 / 33)
-         palette(i) = RGB(clr, 0, 0)
-     Next
-     For i = 0 To 136
-         clr = CInt(i * 255 / 136)
-         palette(34 + i) = RGB(255, clr, 0)
-     Next
-     For i = 0 To 306
-         clr = CInt(i * 255 / 306)
-         palette(171 + i) = RGB(255 - clr, 255, clr)
-     Next
-     For i = 0 To 545
-         clr = CInt(i * 255 / 545)
-         palette(478 + i) = RGB(clr, 255 - clr, 255)
-     Next
-Case 4  'Regenbogen-Palette 2 (linear)
-     For i = 0 To 204
-         clr = CInt(i * 255 / 204)
-         palette(i) = RGB(255, clr, 0)
-         palette(204 + i) = RGB(255 - clr, 255, 0)
-         palette(409 + i) = RGB(0, 255, clr)
-         palette(614 + i) = RGB(0, 255 - clr, 255)
-         palette(819 + i) = RGB(clr, 0, 255)
-     Next
-Case 5  'Regenbogen-Palette 2 (qu.)
-     For i = 0 To 18
-         clr = CInt(i * 255 / 18)
-         palette(i) = RGB(255, clr, 0)
-     Next
-     For i = 0 To 73
-         clr = CInt(i * 255 / 73)
-         palette(20 + i) = RGB(255 - clr, 255, 0)
-     Next
-     For i = 0 To 167
-         clr = CInt(i * 255 / 167)
-         palette(93 + i) = RGB(0, 255, clr)
-     Next
-     For i = 0 To 297
-         clr = CInt(i * 255 / 297)
-         palette(261 + i) = RGB(0, 255 - clr, 255)
-     Next
-     For i = 0 To 464
-         clr = CInt(i * 255 / 464)
-         palette(559 + i) = RGB(clr, 0, 255)
-     Next
-*/
+  */
   return palette;
 }
 
diff --git a/xulapp/chrome/mandelbrot/content/mandelbrot.xul b/xulapp/chrome/mandelbrot/content/mandelbrot.xul
index 596a4e7..5719872 100644
--- a/xulapp/chrome/mandelbrot/content/mandelbrot.xul
+++ b/xulapp/chrome/mandelbrot/content/mandelbrot.xul
@@ -96,6 +96,10 @@
             <menupopup id="menu_palettePopup" onpopupshowing="updatePaletteMenu();" oncommand="setPalette(event.target.value);">
               <menuitem type="radio" name="palette" value="bw" label="&colorBW.label;"/>
               <menuitem type="radio" name="palette" value="kairo" label="&colorKairo.label;"/>
+              <menuitem type="radio" name="palette" value="rainbow-linear1" label="&colorRBLin1.label;"/>
+              <menuitem type="radio" name="palette" value="rainbow-squared1" label="&colorRBSq1.label;"/>
+              <menuitem type="radio" name="palette" value="rainbow-linear2" label="&colorRBLin2.label;"/>
+              <menuitem type="radio" name="palette" value="rainbow-squared2" label="&colorRBSq2.label;"/>
             </menupopup>
           </menu>
           <menuitem id="imgSettings" label="&imgSettings.label;" oncommand="imgSettings();"/>
diff --git a/xulapp/chrome/mandelbrot/locales/en-US/mandelbrot.dtd b/xulapp/chrome/mandelbrot/locales/en-US/mandelbrot.dtd
index 738b7fb..1a9ff9f 100644
--- a/xulapp/chrome/mandelbrot/locales/en-US/mandelbrot.dtd
+++ b/xulapp/chrome/mandelbrot/locales/en-US/mandelbrot.dtd
@@ -55,6 +55,10 @@
 <!ENTITY colorMenu.label  "Color Palette">
 <!ENTITY colorBW.label    "Black &amp; White">
 <!ENTITY colorKairo.label "KaiRo.at">
+<!ENTITY colorRBLin1.label "Rainbow 1 Linear">
+<!ENTITY colorRBSq1.label "Rainbow 1 Squared">
+<!ENTITY colorRBLin2.label "Rainbow 2 Linear">
+<!ENTITY colorRBSq2.label "Rainbow 2 Squared">
 <!ENTITY imgSettings.label "Image Settings…">
 
 <!ENTITY debugMenu.label  "Debug">
-- 
2.43.0