boxmein

Various particle functions for TPT

Aug 2nd, 2012
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | None | 0 0
  1. --`NAME=Various element drawing functions.
  2. --`AUTHOR=boxmein
  3. --`VERSION=1
  4. --`FILE=drawrect.lua
  5. -- to anyone wanting to download this via mniip's script, here are metadatas
  6. --[[
  7.     - drawrect.lua -
  8.     Edit the value show_help_every_start to false or true according to whether you want the help message to display automatically.
  9.    
  10.     Functions:
  11.         drawPartRect(x, y, width, height, part, coords): Draws a rectangle. If coords is true,then consider w to be "x2" and h to be "y2".
  12.         drawPartGrid(x, y, width, height, first-element, second-element, grid-width): Draws a grid of two elements. This can't do coords.
  13.         drawPartChecker(x, y, width, height, element): Draws a checkerboard of a single element. This can't do coords.
  14.         help (): Shows a help message.
  15.         cleanDraw() or cleanText() - Dismisses help message.
  16.    
  17.     For hackers and other awesome people:
  18.         helpmessage() produces the help message itself for a single frame.
  19.    
  20.     Thanks, boxmein
  21. --]]--
  22.  
  23. local show_help_every_start = true
  24.  
  25. function drawPartRect(x, y, w, h, part, coords)
  26.     if coords then -- If you want to draw with two points
  27.         for ry = y, h, 1 do
  28.             for rx = x, w, 1 do
  29.                 tpt.create(rx,ry,part)
  30.             end
  31.         end
  32.     else -- Otherwise draw with width and height
  33.         for ry = y, y+h, 1 do
  34.             for rx = x, x+w, 1 do
  35.                 tpt.create(rx, ry, part)
  36.             end
  37.         end
  38.     end
  39. end
  40. function drawPartGrid(x,y,w,h,oneel,twoel, width) -- Draws grid of two elements
  41.     if width == nil then width = 2 end
  42.     for ry = y, y+h, 1 do
  43.         for rx = x, x+w, 1 do
  44.             if ry % width == 0 or rx % width == 0 then
  45.                 tpt.create(rx,ry,oneel)
  46.             else
  47.                 tpt.create(rx,ry,twoel)
  48.             end
  49.         end
  50.     end
  51. end
  52. function drawPartChecker(x, y, w, h, element)
  53.     for ry = y, y+h, 1 do
  54.         for rx = x, x+w, 1 do
  55.             if ( rx % 2 == 0 and ry % 2 == 0 ) or (rx % 2 ~= 0 and ry % 2 ~= 0) then
  56.                 tpt.create(rx, ry, "whol")
  57.             end
  58.         end
  59.     end
  60. end
  61. function helpmessage()
  62.     tpt.drawtext(10, 100,"- Drawrect.lua -\n\nFunctions: \
  63.     drawPartRect (x, y, width, height, element, coords) - draws rectangle. Set coords to true if you want to specify x1,x2 \
  64.         and y1, y2 etc \
  65.     drawPartChecker (x, y, width, heights, element) - draws checkerboard pattern. \
  66.     drawPartGrid (x, y, width, height, first, second, width) - draws a grid of two particles. width specifies grid size. \
  67.     cleanText() or cleanDraw() - removes this message. Write help() to recreate this message.\
  68. By boxmein 2012, use freely with attribution.\
  69.     ",0,0,255)
  70.     --tpt.drawtext(130,370,"drawPartRect(x,y,w,h,part,coords)",0,0,0)
  71. end
  72. function cleanDraw()
  73.     tpt.unregister_step(helpmessage)
  74. end
  75. function cleanText() --Other nickname for cleanDraw()
  76.     cleanDraw()
  77. end
  78. function help ()
  79.     tpt.unregister_step(helpmessage) -- Prevents stacking
  80.     tpt.register_step(helpmessage)
  81. end
  82. if show_help_every_start then
  83.     tpt.register_step(helpmessage)
  84. end
Advertisement
Add Comment
Please, Sign In to add comment