?login_element?

Subversion Repositories NedoOS

Rev

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

  1. -- Tile graphic test
  2.  
  3.  
  4. function main ()
  5.  if mappy.msgBox ("Graphic test", "This is a test LUA script which generates a new block and graphic and shades it. In 8bit, the palette is set to greyscale. This script has no useful function and is provided so it can be modified for a purpose (see the text file luascr\\Tile graphic test.lua).\n\nRun the script?", mappy.MMB_OKCANCEL, mappy.MMB_ICONQUESTION) == mappy.MMB_OK then
  6.  
  7.   local w = mappy.getValue(mappy.BLOCKWIDTH)
  8.   local h = mappy.getValue(mappy.BLOCKHEIGHT)
  9.   local depth = mappy.getValue(mappy.BLOCKDEPTH)
  10.  
  11.   if (w == 0) then
  12.    mappy.msgBox ("Graphic test", "You need to load or create a map first", mappy.MMB_OK, mappy.MMB_ICONINFO)
  13.   else
  14.  
  15.    local p = 0
  16.    local a,r,g,b
  17.    while p < 256 do
  18. -- a,r,g,b = mappy.getValue((mappy.PALETTEARGB)+p)
  19. -- io.write("old index #",p," = ",a,",",r,",",g,",",b,"\n")
  20.     a = 255
  21.     r = p
  22.     g = p
  23.     b = p
  24. -- io.write("rgb=",r,g,b,"\n")
  25.     mappy.setValue((mappy.PALETTEARGB)+p, a, r, g, b)
  26.     p = p + 1
  27.    end
  28.  
  29.    local newblock = mappy.createBlock (1)
  30.    local newgraphic = mappy.createGraphic (1)
  31.    mappy.setBlockValue (newblock, mappy.BLKBG, newgraphic);
  32.    mappy.setBlockValue (newblock, mappy.BLKUSER1, 123);
  33.    mappy.setBlockValue (newblock, mappy.BLKFLAG1, 1);
  34.    local y = 0
  35.    while y < h do
  36.     local x = 0
  37.     while x < w do
  38.      local pval = (x*(128/w))+(y*(128/h))
  39.      if depth == 8 then
  40.       mappy.setPixel (x, y, newgraphic, pval);
  41.      else
  42.       mappy.setPixel (x, y, newgraphic, 255, pval, pval, pval);
  43.      end
  44.      x = x + 1
  45.     end
  46.     y = y + 1
  47.    end
  48.    mappy.updateScreen()
  49.   end
  50.  end
  51. end
  52.  
  53. test, errormsg = pcall( main )
  54. if not test then
  55.     mappy.msgBox("Error ...", errormsg, mappy.MMB_OK, mappy.MMB_ICONEXCLAMATION)
  56. end
  57.