textures.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. -- Node texture tests
  2. local S = minetest.get_translator("testnodes")
  3. minetest.register_node("testnodes:6sides", {
  4. description = S("Six Textures Test Node"),
  5. tiles = {
  6. "testnodes_normal1.png",
  7. "testnodes_normal2.png",
  8. "testnodes_normal3.png",
  9. "testnodes_normal4.png",
  10. "testnodes_normal5.png",
  11. "testnodes_normal6.png",
  12. },
  13. groups = { dig_immediate = 2 },
  14. })
  15. minetest.register_node("testnodes:anim", {
  16. description = S("Animated Test Node"),
  17. tiles = {
  18. { name = "testnodes_anim.png",
  19. animation = {
  20. type = "vertical_frames",
  21. aspect_w = 16,
  22. aspect_h = 16,
  23. length = 4.0,
  24. }, },
  25. },
  26. groups = { dig_immediate = 2 },
  27. })
  28. -- Node texture transparency test
  29. local alphas = { 64, 128, 191 }
  30. for a=1,#alphas do
  31. local alpha = alphas[a]
  32. -- Transparency taken from texture
  33. minetest.register_node("testnodes:alpha_texture_"..alpha, {
  34. description = S("Texture Alpha Test Node (@1)", alpha),
  35. drawtype = "glasslike",
  36. paramtype = "light",
  37. tiles = {
  38. "testnodes_alpha"..alpha..".png",
  39. },
  40. use_texture_alpha = "blend",
  41. groups = { dig_immediate = 3 },
  42. })
  43. -- Transparency set via texture modifier
  44. minetest.register_node("testnodes:alpha_"..alpha, {
  45. description = S("Alpha Test Node (@1)", alpha),
  46. drawtype = "glasslike",
  47. paramtype = "light",
  48. tiles = {
  49. "testnodes_alpha.png^[opacity:" .. alpha,
  50. },
  51. use_texture_alpha = "blend",
  52. groups = { dig_immediate = 3 },
  53. })
  54. end
  55. -- Generate PNG textures
  56. local function mandelbrot(w, h, iterations)
  57. local r = {}
  58. for y=0, h-1 do
  59. for x=0, w-1 do
  60. local re = (x - w/2) * 4/w
  61. local im = (y - h/2) * 4/h
  62. -- zoom in on a nice view
  63. re = re / 128 - 0.23
  64. im = im / 128 - 0.82
  65. local px, py = 0, 0
  66. local i = 0
  67. while px*px + py*py <= 4 and i < iterations do
  68. px, py = px*px - py*py + re, 2 * px * py + im
  69. i = i + 1
  70. end
  71. r[w*y+x+1] = i / iterations
  72. end
  73. end
  74. return r
  75. end
  76. local function gen_checkers(w, h, tile)
  77. local r = {}
  78. for y=0, h-1 do
  79. for x=0, w-1 do
  80. local hori = math.floor(x / tile) % 2 == 0
  81. local vert = math.floor(y / tile) % 2 == 0
  82. r[w*y+x+1] = hori ~= vert and 1 or 0
  83. end
  84. end
  85. return r
  86. end
  87. local fractal = mandelbrot(512, 512, 128)
  88. local checker = gen_checkers(512, 512, 32)
  89. local floor = math.floor
  90. local abs = math.abs
  91. local data_mb = {}
  92. local data_ck = {}
  93. for i=1, #fractal do
  94. data_mb[i] = {
  95. r = floor(fractal[i] * 255),
  96. g = floor(abs(fractal[i] * 2 - 1) * 255),
  97. b = floor(abs(1 - fractal[i]) * 255),
  98. a = 255,
  99. }
  100. data_ck[i] = checker[i] > 0 and "#F80" or "#000"
  101. end
  102. local textures_path = minetest.get_modpath( minetest.get_current_modname() ) .. "/textures/"
  103. minetest.safe_file_write(
  104. textures_path .. "testnodes_generated_mb.png",
  105. minetest.encode_png(512,512,data_mb)
  106. )
  107. minetest.safe_file_write(
  108. textures_path .. "testnodes_generated_ck.png",
  109. minetest.encode_png(512,512,data_ck)
  110. )
  111. minetest.register_node("testnodes:generated_png_mb", {
  112. description = S("Generated Mandelbrot PNG Test Node"),
  113. tiles = { "testnodes_generated_mb.png" },
  114. groups = { dig_immediate = 2 },
  115. })
  116. minetest.register_node("testnodes:generated_png_ck", {
  117. description = S("Generated Checker PNG Test Node"),
  118. tiles = { "testnodes_generated_ck.png" },
  119. groups = { dig_immediate = 2 },
  120. })