Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --`NAME=Various element drawing functions.
- --`AUTHOR=boxmein
- --`VERSION=1
- --`FILE=drawrect.lua
- -- to anyone wanting to download this via mniip's script, here are metadatas
- --[[
- - drawrect.lua -
- Edit the value show_help_every_start to false or true according to whether you want the help message to display automatically.
- Functions:
- 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".
- drawPartGrid(x, y, width, height, first-element, second-element, grid-width): Draws a grid of two elements. This can't do coords.
- drawPartChecker(x, y, width, height, element): Draws a checkerboard of a single element. This can't do coords.
- help (): Shows a help message.
- cleanDraw() or cleanText() - Dismisses help message.
- For hackers and other awesome people:
- helpmessage() produces the help message itself for a single frame.
- Thanks, boxmein
- --]]--
- local show_help_every_start = true
- function drawPartRect(x, y, w, h, part, coords)
- if coords then -- If you want to draw with two points
- for ry = y, h, 1 do
- for rx = x, w, 1 do
- tpt.create(rx,ry,part)
- end
- end
- else -- Otherwise draw with width and height
- for ry = y, y+h, 1 do
- for rx = x, x+w, 1 do
- tpt.create(rx, ry, part)
- end
- end
- end
- end
- function drawPartGrid(x,y,w,h,oneel,twoel, width) -- Draws grid of two elements
- if width == nil then width = 2 end
- for ry = y, y+h, 1 do
- for rx = x, x+w, 1 do
- if ry % width == 0 or rx % width == 0 then
- tpt.create(rx,ry,oneel)
- else
- tpt.create(rx,ry,twoel)
- end
- end
- end
- end
- function drawPartChecker(x, y, w, h, element)
- for ry = y, y+h, 1 do
- for rx = x, x+w, 1 do
- if ( rx % 2 == 0 and ry % 2 == 0 ) or (rx % 2 ~= 0 and ry % 2 ~= 0) then
- tpt.create(rx, ry, "whol")
- end
- end
- end
- end
- function helpmessage()
- tpt.drawtext(10, 100,"- Drawrect.lua -\n\nFunctions: \
- drawPartRect (x, y, width, height, element, coords) - draws rectangle. Set coords to true if you want to specify x1,x2 \
- and y1, y2 etc \
- drawPartChecker (x, y, width, heights, element) - draws checkerboard pattern. \
- drawPartGrid (x, y, width, height, first, second, width) - draws a grid of two particles. width specifies grid size. \
- cleanText() or cleanDraw() - removes this message. Write help() to recreate this message.\
- By boxmein 2012, use freely with attribution.\
- ",0,0,255)
- --tpt.drawtext(130,370,"drawPartRect(x,y,w,h,part,coords)",0,0,0)
- end
- function cleanDraw()
- tpt.unregister_step(helpmessage)
- end
- function cleanText() --Other nickname for cleanDraw()
- cleanDraw()
- end
- function help ()
- tpt.unregister_step(helpmessage) -- Prevents stacking
- tpt.register_step(helpmessage)
- end
- if show_help_every_start then
- tpt.register_step(helpmessage)
- end
Advertisement
Add Comment
Please, Sign In to add comment