Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. --PALETTE: Fill ColorCube voids v1.0
  2. --by Richard Fhager
  3. --http://hem.fyristorg.com/dawnbringer/
  4. -- Email: dawnbringer@hem.utfors.se
  5. -- MSN:   annassar@hotmail.com
  6. --
  7. -- Copyright 2010 Richard Fhager
  8. --
  9. -- This program is free software; you can redistribute it and/or
  10. -- modify it under the terms of the GNU General Public License
  11. -- as published by the Free Software Foundation; version 2
  12. -- of the License. See <http://www.gnu.org/licenses/>
  13.  
  14. --
  15. -- Create a palette by continously filling the greatest void in the RGB color-cube
  16. --
  17.  
  18.  
  19. SHADES = 16 -- Going 24bit will probably be too slow and steal too much memory, so we're 12bit (4096 colors) for now
  20.  
  21. ini = 0
  22. exp = 255
  23.  
  24. OK,ini,exp = inputbox("Fill Palette Color voids",
  25.                        "From/Keep #: 0-254",    0,  0,254,0,
  26.                        "Replace to #: 1-255",  31,  1,255,0
  27. );
  28.  
  29.  
  30. function initColorCube(sha)
  31.   ary = {}
  32.   for z = 0, sha-1, 1 do
  33.    ary[z+1] = {}
  34.    for y = 0, sha-1, 1 do
  35.     ary[z+1][y+1] = {}
  36.    end
  37.   end
  38.   return ary
  39. end
  40.  
  41.  
  42. function addColor2Cube(cube,sha,r,g,b) -- Gravity model
  43.   star = 1000000
  44.   fade = 1000
  45.  
  46.   cube[r+1][g+1][b+1] = star
  47.   for z = 0, sha-1, 1 do
  48.    for y = 0, sha-1, 1 do
  49.     for x = 0, sha-1, 1 do
  50.  
  51.       d = fade / ( (x-b)^2 + (y-g)^2 + (z-r)^2 )
  52.  
  53.       if cube[z+1][y+1][x+1] ~= nil then
  54.          cube[z+1][y+1][x+1] = cube[z+1][y+1][x+1] + d
  55.          else
  56.          cube[z+1][y+1][x+1] = d
  57.       end
  58.  
  59.   end;end;end
  60. end
  61.  
  62.  
  63. function findVoid(cube,sha)
  64.   weakest = 999999999999
  65.    weak_i = {-1,-1,-1}
  66.   for z = 0, sha-1, 1 do
  67.    for y = 0, sha-1, 1 do
  68.     for x = 0, sha-1, 1 do
  69.  
  70.       w = cube[z+1][y+1][x+1]
  71.       if w <= weakest then weakest = w; weak_i = {z,y,x}; end
  72.      
  73.   end;end;end
  74.   return weak_i[1],weak_i[2],weak_i[3]
  75. end
  76.  
  77. --
  78.  
  79. if OK == true then
  80.  
  81.   cube = initColorCube(SHADES)
  82.   -- Fill cube with initial colors
  83.   for n = 0, ini-1, 1 do
  84.     r,g,b = getcolor(n)
  85.     div = SHADES
  86.     addColor2Cube(cube,SHADES,math.floor(r/div),math.floor(g/div),math.floor(b/div))
  87.   end
  88.  
  89.   if ini == 0 then -- With no inital color, some inital data must be added to the colorcube.
  90.     addColor2Cube(cube,SHADES,0,0,0)
  91.     setcolor(0, 0,0,0)
  92.     ini = ini + 1
  93.   end
  94.  
  95.   for n = ini, exp, 1 do
  96.     r,g,b = findVoid(cube,SHADES)
  97.     mult = 255 / (SHADES - 1)
  98.     setcolor(n, r*mult,g*mult,b*mult)  
  99.     addColor2Cube(cube,SHADES,r,g,b)
  100.   end
  101.  
  102. end
  103.  
  104.  
  105.  
  106.