Advertisement
Doob

[OpenComputers] elka (holo)

Dec 9th, 2015
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 0 0
  1. local component = require("component")
  2. local hologram = component.hologram
  3. local c = 23
  4.  
  5. -- создаем модель елки
  6. local tSpruce = {3, 2, 2, 2, 2, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 4, 6, 8, 7, 6, 5, 4, 3, 6, 5, 4, 3, 2, 3, 2, 1}
  7.  
  8. -- создаем таблицу с падающими снежинками
  9. local tSnow = {}
  10.  
  11. -- создаем палитру цветов
  12. hologram.setPaletteColor(1, 0xFFFFFF) -- снег
  13. hologram.setPaletteColor(2, 0x221100) -- ствол
  14. hologram.setPaletteColor(3, 0x005522) -- хвоя
  15.  
  16. local function cricle(x0, y, z0, R, i) -- задействуем алгоритм Брезенхэма для рисования кругов
  17.   local x = R
  18.   local z = 0
  19.   local err = -R
  20.   while z <= x do
  21.     hologram.set(x + x0, y, z + z0, i)
  22.     hologram.set(z + x0, y, x + z0, i)
  23.     hologram.set(-x + x0, y, z + z0, i)
  24.     hologram.set(-z + x0, y, x + z0, i)
  25.     hologram.set(-x + x0, y, -z + z0, i)
  26.     hologram.set(-z + x0, y, -x + z0, i)
  27.     hologram.set(x + x0, y, -z + z0, i)
  28.     hologram.set(z + x0, y, -x + z0, i)
  29.     z = z + 1
  30.     if err <= 0 then
  31.       err = err + (2 * z + 1)
  32.     else
  33.       x = x - 1
  34.       err = err + (2 * (z - x) + 1)
  35.     end
  36.   end
  37. end
  38.  
  39. local function spruce() -- рисуем ель
  40.   for i = 1, 5 do
  41.     cricle(c, i, c, tSpruce[i], 2) -- отрисовываем основание ствола
  42.     cricle(c, i, c, tSpruce[i]-1, 2)
  43.   end
  44.   for j = 5, #tSpruce do
  45.     cricle(c, j, c, tSpruce[j]-1, 3) -- отрисовываем хвою
  46.     cricle(c, j, c, tSpruce[j]-2, 3)
  47.   end
  48. end
  49.  
  50. local function gen_snow() -- генерируем снежинку
  51.   local x, y, z = math.random(1, 46), 32, math.random(1, 46)
  52.   table.insert(tSnow,{x=x,y=y,z=z})
  53.   hologram.set(x, y, z, 1)
  54. end
  55.  
  56. local function falling_snow() -- сдвигаем снежинки вниз
  57.   local i=1
  58.   while i<=#tSnow do
  59.     if tSnow[i].y>1 then
  60.     local x,y,z=tSnow[i].x+math.random(-1, 1), tSnow[i].y-1, tSnow[i].z+math.random(-1, 1)
  61.     if x<1 then x=1 end
  62.     if x>46 then x=46 end
  63.     if z<1 then z=1 end
  64.     if z>46 then z=46 end
  65.     c=hologram.get(x, y, z)
  66.     if c==0 or c==1 then
  67.           hologram.set(tSnow[i].x, tSnow[i].y, tSnow[i].z, 0)
  68.       tSnow[i].x, tSnow[i].y, tSnow[i].z=x,y,z
  69.           hologram.set(x, y, z, 1)
  70.           i=i+1
  71.         else
  72.       table.remove(tSnow,i)
  73.         end  
  74.      else
  75.     table.remove(tSnow,i)
  76.      end
  77.      os.sleep(0)
  78.   end
  79. end
  80.  
  81. hologram.clear()
  82. spruce()
  83. while 1 do
  84.   gen_snow()
  85.   falling_snow()
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement