Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. --BRUSH Scene: Amigaball 1.0
  2. --
  3. --Draws the famous 'Amiga ball' in the brush.
  4. --
  5. --by Richard Fhager
  6. --http://hem.fyristorg.com/dawnbringer/
  7.  
  8. -- Copyright 2010 Richard Fhager
  9. --
  10. -- This program is free software; you can redistribute it and/or
  11. -- modify it under the terms of the GNU General Public License
  12. -- as published by the Free Software Foundation; version 2
  13. -- of the License. See <http://www.gnu.org/licenses/>
  14.  
  15. -- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
  16. --http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
  17.  
  18.  
  19.  
  20. w, h = getbrushsize()
  21. if (w<64 or h<64) then
  22.   setbrushsize(64,64)
  23.   w=64
  24.   h=64
  25. end
  26.  
  27. for y = 0, h - 1, 1 do
  28.   for x = 0, w - 1, 1 do
  29.  
  30.    -- Fractionalize image dimensions
  31.    ox = x / w;
  32.    oy = y / h;
  33.  
  34.    -- Ball
  35.    Xr = ox-0.5; Yr = oy-0.5;
  36.    W = (1 - 2*math.sqrt(Xr*Xr + Yr*Yr));
  37.  
  38.    -- 'FishEye' distortion / Fake 3D
  39.    F = (math.cos((ox-0.5)*math.pi)*math.cos((oy-0.5)*math.pi))*0.65;
  40.    ox = ox - (ox-0.5)*F;
  41.    oy = oy - (oy-0.5)*F;
  42.  
  43.    -- Checkers
  44.    V = ((math.floor(0.25+ox*10)+math.floor(1+oy*10)) % 2) * 255 * W;
  45.  
  46.    -- Specularities
  47.    SPEC1 = math.max(0,(1-5*math.sqrt((ox-0.45)*(ox-0.45)+(oy-0.45)*(oy-0.45)))*112);
  48.    SPEC2 = math.max(0,(1-15*math.sqrt((ox-0.49)*(ox-0.49)+(oy-0.48)*(oy-0.48)))*255);
  49.  
  50.    r = W * 255 + SPEC1 + SPEC2
  51.    g = V + SPEC1 + SPEC2
  52.    b = V + SPEC1 + SPEC2
  53.  
  54.    putbrushpixel(x, y, matchcolor(r,g,b));
  55.  
  56.   end
  57. end
  58.