Advertisement
rsidwell

rds_nestedcircles.ulb

Feb 20th, 2025
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. class RDS_TrapShapeNestedCircles(common.ulb:TrapShape) {
  2. public:
  3. import "common.ulb"
  4.  
  5. func RDS_TrapShapeNestedCircles(Generic pparent)
  6. TrapShape.TrapShape(pparent)
  7. endfunc
  8.  
  9. float func Iterate(complex pz)
  10. TrapShape.Iterate(pz)
  11. pz = pz * (0,1) ^ 0.5
  12. float d = cabs(pz) - @p_radius;
  13. if (d > 0)
  14. return d
  15. else
  16. d = -d
  17. endif
  18.  
  19. complex bottomleft = -@p_radius / sqrt(2.0) + flip(-@p_radius / sqrt(2.0))
  20. int n = 2
  21. float cur_radius = @p_radius / 2.0
  22. int level = 1
  23. while (level < @p_levels)
  24. float delta = cur_radius * sqrt(2.0)
  25. complex circle_pos = bottomleft - (cur_radius / sqrt(2.0) + flip(cur_radius / sqrt(2.0)))
  26. complex newp = (pz - circle_pos) / delta
  27. complex newf = newp - trunc(newp)
  28.  
  29. ; End if point is outside all circles at this level
  30. if (real(newp) < 0 || real(newp) > n+1 || imag(newp) < 0 || imag(newp) > n+1)
  31. return d
  32. endif
  33.  
  34. ; Check bottom left circle
  35. if (real(newp) > 1 && imag(newp) > 1)
  36. float newd = abs(delta * cabs(newf) - cur_radius)
  37. if (newd < d)
  38. d = newd
  39. endif
  40. endif
  41.  
  42. ; check bottom right circle
  43. if (real(newp) < n && imag(newp) > 1)
  44. float newd = abs(delta * cabs(newf - (1,0)) - cur_radius)
  45. if (newd < d)
  46. d = newd
  47. endif
  48. endif
  49.  
  50. ; check top left circle
  51. if (real(newp) > 1 && imag(newp) < n)
  52. float newd = abs(delta * cabs(newf - (0,1)) - cur_radius)
  53. if (newd < d)
  54. d = newd
  55. endif
  56. endif
  57.  
  58. ; check top right circle
  59. if (real(newp) < n && imag(newp) < n)
  60. float newd = abs(delta * cabs(newf - (1,1)) - cur_radius)
  61. if (newd < d)
  62. d = newd
  63. endif
  64. endif
  65.  
  66. n = n * 2
  67. cur_radius = cur_radius / 2.0
  68. level = level + 1
  69. endwhile
  70.  
  71. return d
  72. endfunc
  73.  
  74. default:
  75. title = "Nested Circles"
  76.  
  77. int param v_rds_trapshapenestedcircles
  78. caption = "Version (RDS_TrapShapeNestedCircles)"
  79. default = 100
  80. hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used."
  81. visible = @v_rds_trapshapenestedcircles < 100
  82. endparam
  83.  
  84. float param p_radius
  85. caption = "Radius"
  86. default = 1.0
  87. min = 0.1
  88. hint = "Radius of outer circle"
  89. endparam
  90.  
  91. int param p_levels
  92. caption = "Levels"
  93. default = 6
  94. min = 1
  95. max = 10
  96. hint = "How many levels of nesting to use."
  97. endparam
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement