1
0

Displacement Map Flip.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. local sprite = app.editor.sprite
  2. local cel = app.cel
  3. if sprite.selection.isEmpty then
  4. print("You need to select something sorry")
  5. return
  6. end
  7. local diag = Dialog{
  8. title = "Flip Displacement Map"
  9. }
  10. diag:check{
  11. id = "horizontal",
  12. label = "flip horizontal?"
  13. }
  14. diag:check{
  15. id = "vertical",
  16. label = "flip vertical?"
  17. }
  18. diag:button{
  19. text = "ok",
  20. focus = true,
  21. onclick = function(ev)
  22. local horizontal = diag.data["horizontal"]
  23. local vertical = diag.data["vertical"]
  24. local selection = sprite.selection
  25. local image = cel.image:clone()
  26. for x = 0, selection.bounds.width do
  27. for y = 0, selection.bounds.height do
  28. local xSel = x + selection.origin.x
  29. local ySel = y + selection.origin.y
  30. local xImg = xSel - cel.position.x
  31. local yImg = ySel - cel.position.y
  32. if xImg < 0 or xImg >= image.width or yImg < 0 or yImg >= image.height then
  33. goto continue
  34. end
  35. local imgValue = image:getPixel(xImg, yImg)
  36. local color = Color(imgValue)
  37. if horizontal then
  38. color.red = 128 + -(color.red - 128)
  39. end
  40. if vertical then
  41. color.green = 128 + -(color.green - 128)
  42. end
  43. image:drawPixel(
  44. xImg,
  45. yImg,
  46. app.pixelColor.rgba(color.red, color.green, color.blue, color.alpha))
  47. ::continue::
  48. end
  49. end
  50. cel.image = image
  51. diag:close()
  52. end
  53. }
  54. diag:button{
  55. text = "cancel",
  56. onclick = function(ev)
  57. diag:close()
  58. end
  59. }
  60. diag:show()