Advertisement
FeynmanTech

Powder Toy Graphics Library

Apr 10th, 2013
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.66 KB | None | 0 0
  1. MANAGER_PRINT("FeynmanTechnologies Graphics Library is running!",255,125,0)
  2. --CHANGELOG: Added save-to-script conversion, fake deco. If you want something really good use Mniip's.
  3. --CHANGELOG: Added image plotting (Almost all by Mniip, just barely edited), line, property line, line with color
  4. --r,g,b, monochrome image plotting with threshold (Also based off of Mniip's script)
  5. ---FeynmanTechnologies Graphics Library---
  6. --------Plugins--------
  7. --Draws a shade using a property at x,y
  8. function ftgl_propshade(element,property,value,x,y)
  9. tpt.create(x,y,element)
  10. tpt.set_property('type',element,x,y)
  11. tpt.set_property(property,value,x,y)
  12. end
  13. --Anti-alias the deco layer from firstx,firsty to secondx,secondy
  14. function ftgl_antialias(firstx,firsty,secondx,secondy)
  15. for x=firstx,secondx do
  16. for y=firsty,secondy do
  17. decocolor = (((tpt.get_property('dcolor',x-1,y)+tpt.get_property('dcolor',x+1,y))/2)+tpt.get_property('dcolor',x,y))/2
  18. tpt.set_property('dcolor',decocolor,x,y)
  19. end
  20. end
  21. end
  22. --Draw a solid rectangle in an element
  23. function ftgl_rect(element,firstx,firsty,secondx,secondy)
  24. for x=firstx,secondx do
  25. for y=firsty,secondy do
  26. tpt.create(x,y,1)
  27. tpt.set_property('type',element,x,y)
  28. end
  29. end
  30. end
  31. --Draw a rectangle in an element
  32. function ftgl_hollowrect(element,xwidth,ywidth,firstx,firsty,secondx,secondy)
  33. for x=firstx,secondx do
  34. for y=firsty,secondy do
  35. tpt.create(x,y,1)
  36. tpt.set_property('type',element,x,y)
  37. end
  38. end
  39. for x=firstx+xwidth,secondx-xwidth do
  40. for y=firsty+ywidth,secondy-ywidth do
  41. tpt.set_property('type',0,x,y)
  42. end
  43. end
  44. end
  45. --Draw a solid rectangle in a property
  46. function ftgl_proprect(property,value,firstx,firsty,secondx,secondy)
  47. for x=firstx,secondx do
  48. for y=firsty,secondy do
  49. tpt.set_property(property,value,x,y)
  50. end
  51. end
  52. end
  53. --Draw a rectangle in a property
  54. function ftgl_hollowproprect(property,value,xwidth,ywidth,firstx,firsty,secondx,secondy)
  55. for x=firstx,secondx do
  56. for y=firsty,firsty+ywidth do
  57. tpt.set_property(property,value,x,y)
  58. end
  59. for y=secondy,secondy-ywidth do
  60. tpt.set_property(property,value,x,y)
  61. end
  62. for y=firsty,secondy do
  63. for x=firstx,firstx+xwidth do
  64. tpt.set_property(property,value,x,y)
  65. end
  66. for x=secondx,secondx-xwidth do
  67. tpt.set_property(property,value,x,y)
  68. end
  69. end
  70. end
  71. end
  72. --Draws a line from x1,y1 to x2,y2 in a certain element
  73. function ftgl_line(element,x1,y1,x2,y2)
  74. x=x1
  75. y=y1
  76. for x=x1,x2 do
  77. tpt.create(x,y,element)
  78. y=y+(y2-y1)/(x2-x1)
  79. end
  80. for y=y1,y2 do
  81. tpt.create(x,y,element)
  82. x=x+(x2-x1)/(y2-y1)
  83. end
  84. end
  85. --Draws a line from x1,y1 to x2,y2 in a certain property
  86. function ftgl_propline(property,value,x1,y1,x2,y2)
  87. x=x1
  88. y=y1
  89. for x=x1,x2 do
  90. tpt.set_property(property,value,x,y)
  91. y=y+(y2-y1)/(x2-x1)
  92. end
  93. for y=y1,y2 do
  94. tpt.set_property(property,value,x,y)
  95. x=x+(x2-x1)/(y2-y1)
  96. end
  97. end
  98. --Draws a line from x1,y1 to x2,y2 in color r,g,b
  99. function ftgl_colorline(element,x1,y1,x2,y2,r,g,b)
  100. x=x1
  101. y=y1
  102. for x=x1,x2 do
  103. tpt.create(x,y,element)
  104. tpt.set_property('dcolor',r*65536+g*256+b+16777216*255,value,x,y)
  105. y=y+(y2-y1)/(x2-x1)
  106. end
  107. for y=y1,y2 do
  108. tpt.create(x,y,element)
  109. tpt.set_property('dcolor',r*65536+g*256+b+16777216*255,value,x,y)
  110. x=x+(x2-x1)/(y2-y1)
  111. end
  112. end
  113. --------Stand-Alone Functions--------
  114. --Creates a script to recreate a save
  115. function savetoscript()
  116. scriptname=tpt.input("Script Name","This will be the name of the created script")
  117. local file = io.open(scriptname, "w")
  118. for x=5,607 do
  119. for y=5,375 do
  120.     elemtype=tpt.get_property('type',x,y)
  121.     if elemtype ~= 0 and elemtype ~= 'none' then
  122.     decocolor=tpt.get_property('dcolor',x,y)
  123.     lifeval=tpt.get_property('life',x,y)
  124.     tempval=tpt.get_property('temp',x,y)
  125.     tmpval=tpt.get_property('tmp',x,y)
  126.     tmptwoval=tpt.get_property('tmp2',x,y)
  127.     ctypeval=tpt.get_property('ctype',x,y)
  128.     file:write("tpt.create(",x,",",y,",",elemtype,")\n")
  129.     file:write("tpt.set_property('dcolor',",decocolor,",",x,",",y,")\n")
  130.     file:write("tpt.set_property('life',",lifeval,",",x,",",y,")\n")
  131.     file:write("tpt.set_property('temp',",tempval,",",x,",",y,")\n")
  132.     file:write("tpt.set_property('tmp',",tmpval,",",x,",",y,")\n")
  133.     file:write("tpt.set_property('tmp2',",tmptwoval,",",x,",",y,")\n")
  134.     file:write("tpt.set_property('ctype',",ctypeval,",",x,",",y,")\n")
  135. end
  136. end
  137. end
  138. end
  139. --Fake Deco (uses EMBR's ctype instead of deco to make color). I don't know if it works yet, but when it does it will make a nice way to display deco in the save preview.
  140. function fakedeco()
  141. for x=5,607 do
  142. for y=5,375 do
  143. if tpt.get_property('type',x,y) > 0 then
  144.     decocolor = 0
  145.     decocolor = tpt.get_property('dcolor',x,y)
  146.     elemtype = tpt.get_property('type',x,y)
  147. end
  148. if decocolor ~= 0 then
  149. tpt.set_property('type','embr',x,y)
  150. tpt.set_property('ctype',decocolor,x,y)
  151. end
  152. end
  153. end
  154. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement