Advertisement
FeynmanTech

Powder Toy Lua Utilities

Jul 16th, 2013
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.83 KB | None | 0 0
  1. local cF = 0
  2. local cX = 60
  3. willDrawFPS = true
  4. function fpsbar()
  5.  tpt.drawrect(4,354,200,12,255,255,255,255)
  6.  tpt.fillrect(205,354,29,12,255,255,255,255)
  7.  tpt.drawtext(208,357,"Reset",0,0,0,255)
  8.  tpt.fillrect(5,355,cX,10,255,255,255,255)
  9.  tpt.fillrect(5, 355,cFPS,10,0,155,0,155)
  10.  tpt.drawtext(4,346,"Target FPS: " .. cX .. ", Current FPS: " .. math.floor(cFPS),255,255,255,150)
  11.  tpt.setfpscap(cX)
  12. end
  13. function mTest()
  14.  if tpt.mousex >= 10 and tpt.mousex <= 204 and tpt.mousey >= 355 and tpt.mousey <= 375 then
  15.  cX = tpt.mousex - 4
  16.  elseif tpt.mousex >= 205 and tpt.mousex <= 234 and tpt.mousey >= 354 and tpt.mousey <= 366 then
  17.  cX = 60
  18.  end
  19. end
  20. function currentFPS()
  21.  f=os.clock()
  22.  cFPS=1/(f-cF)
  23.  cF=f
  24. end
  25. tpt.register_mouseclick(mTest)
  26. tpt.register_step(fpsbar)
  27. tpt.register_step(currentFPS)
  28. local running = false
  29. local frameCount = 0
  30. function drawmeter()
  31.  tpt.fillrect(4,335,25,10,255,255,255,255)
  32.  tpt.drawtext(6,337,"Start",0,0,0,255)
  33.  tpt.fillrect(29,335,22,10,255,255,255,255)
  34.  tpt.drawtext(31,337,"Stop",0,0,0,255)
  35.  tpt.fillrect(51,335,27,10,255,255,255,255)
  36.  tpt.drawtext(53,337,"Reset",0,0,0,255)
  37.  tpt.drawtext(80,337,frameCount .. " frames",155,155,155,255)
  38.  if running == true then
  39.  frameCount = frameCount + 1
  40.  end
  41. end
  42. function mouseTesting()
  43.  if tpt.mousex >= 4 and tpt.mousex <= 29 and tpt.mousey >= 335 and tpt.mousey <= 345 then
  44.  running = true
  45.  elseif tpt.mousex >= 29 and tpt.mousex <= 51 and tpt.mousey >= 335 and tpt.mousey <= 345 then
  46.  running = false
  47.  elseif tpt.mousex >= 51 and tpt.mousex <= 78 and tpt.mousey >= 335 and tpt.mousey <= 345 then
  48.  running = false
  49.  frameCount = 0
  50.  end
  51. end
  52. tpt.register_step(drawmeter)
  53. tpt.register_mouseclick(mouseTesting)
  54. sensorX = 200
  55. sensorY = 200
  56. sensorFileStr = tpt.input("Sensor output file","This is the file the sensor will write all of its data to.")
  57. if sensorFileStr == "" then
  58.  sensorFileStr = "luasensor_Standard_Output.txt"
  59. end
  60. local sFile = io.open(sensorFileStr,"w")
  61. function drawSensor()
  62.  tpt.fillrect(4,367,63,12,255,255,255,255)
  63.  tpt.drawtext(7,370,"Take reading",0,0,0,255)
  64.  tpt.drawpixel(sensorX,sensorY,255,0,0,275)
  65.  tpt.drawtext(sensorX+2,sensorY,"Sensor",255,0,0,75)
  66. end
  67. function sensorMouseTest()
  68.  if tpt.mousex >= 4 and tpt.mousex <= 67 and tpt.mousey >= 367 and tpt.mousey <= 377 and type(tpt.get_property("type",sensorX,sensorY)) == "number" and tpt.get_property("type",sensorX,sensorY) >= 1 then
  69.  sTemp = tpt.get_property("temp",sensorX,sensorY)
  70.  sType = tpt.get_property("type",sensorX,sensorY)
  71.  sTime = os.date()
  72.  sFile:write(sTime .. ": Type: " .. sType .. ", Temp: " .. sTemp .. "\n")
  73.  end
  74. end
  75. function placeSensor(x,y)
  76.  sFile:close()
  77.  sensorX = x
  78.  sensorY = y
  79.  sensorFileStr = tpt.input("Sensor output file","This is the file the sensor will write all of its data to.")
  80.  if sensorFileStr == "" then
  81.  sensorFileStr = "luasensor_Standard_Output.txt"
  82.  end
  83. sFile = io.open(sensorFileStr,"w")
  84. tpt.register_step(drawSensor)
  85. tpt.register_mouseclick(sensorMouseTest)
  86.  
  87. And a basic texter:
  88.  
  89. v.1.1 - Created!
  90.  
  91. --To use, press T and it creates text under the cursor.
  92. local w = 5
  93. local h = 5
  94. pixtext = function(str, x, y, s)
  95. for c = 1,str.len(str) do
  96. cs = string.sub(str,c, c);
  97. if string.sub(str,c,c+1) == "\n" then
  98. y = y + (h + 2) * s;
  99. x = origX - (w + 2) * s;
  100. end
  101. if cs == "A" or cs == "a" then
  102. textMatrix = {{0,0,1,0,0},{0,1,0,1,0},{1,1,1,1,1},{1,0,0,0,1},{1,0,0,0,1}};
  103. elseif cs == "B" or cs == "b" then
  104. textMatrix = {{1,1,1,1,0},{1,0,0,0,1},{1,1,1,1,0},{1,0,0,0,1},{1,1,1,1,0}};
  105. elseif cs == "C" or cs == "c" then
  106. textMatrix = {{0,1,1,1,0},{1,0,0,0,1},{1,0,0,0,0},{1,0,0,0,1},{0,1,1,1,0}};
  107. elseif cs == "D" or cs == "d" then
  108. textMatrix = {{1,1,1,1,0},{1,0,0,0,1},{1,0,0,0,1},{1,0,0,0,1},{1,1,1,1,0}};
  109. elseif cs == "E" or cs == "e" then
  110. textMatrix = {{1,1,1,1,1},{1,0,0,0,0},{1,1,1,0,0},{1,0,0,0,0},{1,1,1,1,1}};
  111. elseif cs == "F" or cs == "f" then
  112. textMatrix = {{1,1,1,1,1},{1,0,0,0,0},{1,1,1,0,0},{1,0,0,0,0},{1,0,0,0,0}};
  113. elseif cs == "G" or cs == "g" then
  114. textMatrix = {{0,1,1,1,0},{1,0,0,0,0},{1,1,1,1,0},{1,0,0,0,1},{0,1,1,1,0}};
  115. elseif cs == "H" or cs == "h" then
  116. textMatrix = {{1,0,0,0,1},{1,0,0,0,1},{1,1,1,1,1},{1,0,0,0,1},{1,0,0,0,1}};
  117. elseif cs == "I" or cs == "i" then
  118. textMatrix = {{1,1,1,1,1},{0,0,1,0,0},{0,0,1,0,0},{0,0,1,0,0},{1,1,1,1,1}};
  119. elseif cs == "J" or cs == "j" then
  120. textMatrix = {{1,1,1,1,1},{0,0,1,0,0},{0,0,1,0,0},{0,0,1,0,0},{1,1,0,0,0}};
  121. elseif cs == "K" or cs == "k" then
  122. textMatrix = {{1,0,0,0,1},{1,0,0,1,0},{1,1,1,0,0},{1,0,0,1,0},{1,0,0,0,1}};
  123. elseif cs == "L" or cs == "l" then
  124. textMatrix = {{1,0,0,0,0},{1,0,0,0,0},{1,0,0,0,0},{1,0,0,0,0},{1,1,1,1,1}};
  125. elseif cs == "M" or cs == "m" then
  126. textMatrix = {{1,0,0,0,1},{1,1,0,1,1},{1,0,1,0,1},{1,0,1,0,1},{1,0,0,0,1}};
  127. elseif cs == "N" or cs == "n" then
  128. textMatrix = {{1,0,0,0,1},{1,1,0,0,1},{1,0,1,0,1},{1,0,0,1,1},{1,0,0,0,1}};
  129. elseif cs == "O" or cs == "o" then
  130. textMatrix = {{0,1,1,1,0},{1,0,0,0,1},{1,0,0,0,1},{1,0,0,0,1},{0,1,1,1,0}};
  131. elseif cs == "P" or cs == "p" then
  132. textMatrix = {{1,1,1,1,0},{1,0,0,0,1},{1,1,1,1,0},{1,0,0,0,0},{1,0,0,0,0}};
  133. elseif cs == "Q" or cs == "q" then
  134. textMatrix = {{0,1,1,1,0},{1,0,0,0,1},{1,0,1,0,1},{1,0,0,1,0},{0,1,1,0,1}};
  135. elseif cs == "R" or cs == "r" then
  136. textMatrix = {{1,1,1,1,0},{1,0,0,0,1},{1,1,1,1,0},{1,0,0,0,1},{1,0,0,0,1}};
  137. elseif cs == "S" or cs == "s" then
  138. textMatrix = {{0,1,1,1,0},{1,0,0,0,0},{0,1,1,1,0},{0,0,0,0,1},{0,1,1,1,0}};
  139. elseif cs == "T" or cs == "t" then
  140. textMatrix = {{1,1,1,1,1},{0,0,1,0,0},{0,0,1,0,0},{0,0,1,0,0},{0,0,1,0,0}};
  141. elseif cs == "U" or cs == "u" then
  142. textMatrix = {{1,0,0,0,1},{1,0,0,0,1},{1,0,0,0,1},{1,0,0,0,1},{0,1,1,1,0}};
  143. elseif cs == "V" or cs == "v" then
  144. textMatrix = {{1,0,0,0,1},{1,0,0,0,1},{1,0,0,0,1},{0,1,0,1,0},{0,0,1,0,0}};
  145. elseif cs == "W" or cs == "w" then
  146. textMatrix = {{1,0,0,0,1},{1,0,0,0,1},{1,0,1,0,1},{1,0,1,0,1},{0,1,0,1,0}};
  147. elseif cs == "X" or cs == "x" then
  148. textMatrix = {{1,0,0,0,1},{0,1,0,1,0},{0,0,1,0,0},{0,1,0,1,0},{1,0,0,0,1}};
  149. elseif cs == "Y" or cs == "y" then
  150. textMatrix = {{1,0,0,0,1},{1,0,0,0,1},{0,1,0,1,0},{0,0,1,0,0},{0,0,1,0,0}};
  151. elseif cs == "Z" or cs == "z" then
  152. textMatrix = {{1,1,1,1,1},{0,0,0,1,0},{0,0,1,0,0},{0,1,0,0,0},{1,1,1,1,1}};
  153. elseif cs == "1" then
  154. textMatrix = {{0,0,1,0,0},{0,1,1,0,0},{1,0,1,0,0},{0,0,1,0,0},{1,1,1,1,1}};
  155. elseif cs == "2" then
  156. textMatrix = {{0,1,1,1,0},{1,0,0,0,1},{0,0,1,1,0},{0,1,0,0,0},{1,1,1,1,1}};
  157. elseif cs == "3" then
  158. textMatrix = {{0,1,1,1,0},{1,0,0,0,1},{0,0,1,1,0},{1,0,0,0,1},{0,1,1,1,0}};
  159. elseif cs == "4" then
  160. textMatrix = {{1,0,0,1,0},{1,0,0,1,0},{1,1,1,1,1},{0,0,0,1,0},{0,0,0,1,0}};
  161. elseif cs == "5" then
  162. textMatrix = {{1,1,1,1,1},{1,0,0,0,0},{1,1,1,1,0},{0,0,0,0,1},{1,1,1,1,0}};
  163. elseif cs == "6" then
  164. textMatrix = {{0,1,1,1,0},{1,0,0,0,0},{1,1,1,1,0},{1,0,0,0,1},{0,1,1,1,0}};
  165. elseif cs == "7" then
  166. textMatrix = {{1,1,1,1,1},{0,0,0,1,0},{0,0,1,0,0},{0,1,0,0,0},{1,0,0,0,0}};
  167. elseif cs == "8" then
  168. textMatrix = {{0,1,1,1,0},{1,0,0,0,1},{0,1,1,1,0},{1,0,0,0,1},{0,1,1,1,0}};
  169. elseif cs == "9" then
  170. textMatrix = {{0,1,1,1,1},{1,0,0,0,1},{0,1,1,1,1},{0,0,0,0,1},{0,0,0,0,1}};
  171. elseif cs == "0" then
  172. textMatrix = {{0,1,1,1,0},{1,0,0,1,1},{1,0,1,0,1},{1,1,0,0,1},{0,1,1,1,0}};
  173. elseif cs == "!" then
  174. textMatrix = {{0,0,1,0,0},{0,0,1,0,0},{0,0,1,0,0},{0,0,0,0,0},{0,0,1,0,0}};
  175. elseif cs == "@" then
  176. textMatrix = {{0,1,1,1,0},{1,0,1,0,1},{1,0,1,1,1},{1,0,0,0,0},{0,1,1,1,0}};
  177. elseif cs == "#" then
  178. textMatrix = {{0,1,0,1,0},{1,1,1,1,1},{0,1,0,1,0},{1,1,1,1,1},{0,1,0,1,0}};
  179. elseif cs == "$" then
  180. textMatrix = {{0,1,1,1,0},{1,0,1,0,0},{0,1,1,1,0},{0,0,1,0,1},{0,1,1,1,0}};
  181. elseif cs == "%" then
  182. textMatrix = {{1,1,0,0,1},{1,1,0,1,0},{0,0,1,0,0},{0,1,0,1,1},{1,0,0,1,1}};
  183. elseif cs == "^" then
  184. textMatrix = {{0,0,1,0,0},{0,1,0,1,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};
  185. elseif cs == "&" then
  186. textMatrix = {{0,1,1,1,0},{1,0,0,0,0},{0,1,0,0,0},{1,0,1,0,1},{0,1,0,1,0}};
  187. elseif cs == "*" then
  188. textMatrix = {{0,0,1,0,0},{1,0,1,0,1},{0,1,1,1,0},{1,0,1,0,1},{0,0,1,0,0}};
  189. elseif cs == "(" then
  190. textMatrix = {{0,0,1,0,0},{0,1,0,0,0},{0,1,0,0,0},{0,1,0,0,0},{0,0,1,0,0}};
  191. elseif cs == ")" then
  192. textMatrix = {{0,0,1,0,0},{0,0,0,1,0},{0,0,0,1,0},{0,0,0,1,0},{0,0,1,0,0}};
  193. elseif cs == "," then
  194. textMatrix = {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,1,0,0},{0,1,0,0,0}};
  195. elseif cs == "." then
  196. textMatrix = {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,1,0,0}};
  197. elseif cs == "\n" or cs == " " then
  198. textMatrix = {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};
  199. else
  200. textMatrix = {{1,1,1,1,1},{1,0,0,0,1},{1,0,0,0,1},{1,0,0,0,1},{1,1,1,1,1}};
  201. end
  202. for cx = 1,5 do
  203. for cy = 1,5 do
  204. if textMatrix[cy][cx] == 1 then
  205. tpt.create(x + cx, y + cy, "dmnd")
  206. end
  207. end
  208. end
  209.  
  210. x = x + (w + 1) * s;
  211. end
  212. end
  213. function texterKeyTest(a)
  214. if a == "t" then
  215. pixtext(tpt.input("Text to draw","This is the text it will draw at the cursor position"),tpt.mousex,tpt.mousey,1)
  216. end
  217. end
  218. tpt.register_keypress(texterKeyTest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement