Advertisement
Guest User

smokestack.lua

a guest
Apr 27th, 2021
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. ----- parameters -----
  2.  
  3. base = 12:: int_slider("Bottom", 3, 48)
  4. top = 8:: int_slider("Top", 3, 48)
  5. height = 50:: int_slider("Height", 1, 500)
  6. block_w = 3:: float_slider("Block Width", 0.2, 10, 0.2)
  7. block_d = 1:: float_slider("Block Depth", 0.2, 10, 0.2)
  8. block_h = 1:: float_slider("Block Height", 0.2, 10, 0.2)
  9.  
  10. rotate = 0 :: float_slider("Rotate", 0, 360, 10)
  11. offset_frac = 0.5 :: float_slider("Offset", 0, 1, 0.1)
  12.  
  13. tighten = false:: toggle("Tighten")
  14.  
  15. ----------------------
  16.  
  17. c = col()
  18. c.dim = vec(block_w,block_h,block_d)
  19.  
  20. function subtends(_c, _r)
  21.  return (2*math.atan((_c.dim.x/2)/(_r - _c.dim.z/2)))
  22. end
  23.  
  24. function radius_to(_c, _n)
  25.  return (_c.dim.z/2 + c.dim.x/2/math.tan(2*math.pi/_n/2))
  26. end
  27.  
  28. function circle(_c, _angle, _r, _y)
  29.  local blocks = math.floor(2*math.pi/subtends(_c, _r))
  30.  local alpha = 2*math.pi/blocks
  31.  
  32.  for i=1,blocks do
  33.   local t = _angle + (i-1.5)*alpha
  34.  
  35.   if tighten then
  36.    _r = radius_to(_c, blocks)
  37.   end
  38.  
  39.   local x = _r*math.cos(t)
  40.   local z = _r*math.sin(t)
  41.  
  42.   local b = brk(_c)
  43.   b.pos = vec(x, _y, z)
  44.   b.rot.y = -math.deg(t) + 90
  45.  end
  46. end
  47.  
  48. r_base = radius_to(c, base)
  49. r_top = radius_to(c, top)
  50. offset = 0
  51.  
  52. function scale_by(_i, _imin, _imax, _min, _max)
  53.  if _imin == _imax then
  54.   return _min
  55.  end
  56.  return _min + (_i - _imin)/(_imax - _imin)*(_max - _min)
  57. end
  58.  
  59. for i=1,height do
  60.  local y = c.dim.y*(i-0.5)
  61.  local r = scale_by(i,1,height, r_base, r_top)
  62.  
  63.  offset = offset + math.rad(rotate) + offset_frac*subtends(c, r)
  64.  circle(c, offset, r, y)
  65. end
  66.  
  67. randomize_colors()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement