返回列表 回复 发帖
谢谢柳老师,找到了。我更具Mathcad中的方法改写了一下,基本上保持了原来的结构,但只用了2个陷阱,产生了8个圆.
UF代码
8Circles {
init:
  int iter = 0
  float rangemun = 0
  float num = 4
  float Xabs = 0
  float Yabs = 0
  float Dsgd0 = 0
  float Dsgd1 = 0
  float Circle = 0
  float ZtoPsqd = 0
  float Rc = @r
  float Phi = #pi * 0.125
  float Rm = Rc * sin(Phi)
  float RcSqd = Rm^2
  bool Trapped = false
loop:
  iter = iter + 1
  if iter > @skip && !Trapped
    Xabs = abs(real(#z))
    Yabs = abs(imag(#z))
    Dsgd0 = (Xabs-Rc*sin(phi))^2 + (Yabs - Rc*cos(phi))^2
    Dsgd1 = (Xabs-Rc*sin(3*phi))^2 + (Yabs - Rc*cos(3*phi))^2
    if Dsgd0 < RcSqd
      Trapped = true
      ZtoPsqd= Dsgd0
        Circle = iter
    elseif Dsgd1 < RcSqd
      Trapped = true
      ZtoPsqd= Dsgd1
        Circle = iter
   endif
endif
final:
  if !trapped
    #solid = true
  else
    Circle = ((Circle + @off) % num)/(num-1)
    float Ratio = sqrt(ZtoPsqd/Rcsqd)
    float ColorIndex = 115 * Ratio + Circle * 140
    #index = (ColorIndex + 1) % 256 /256
  endif
default:
  title = "8 Circles"
  param r
    caption = "Circle radius"
    default = 0.4
  endparam
  param skip
    caption = "Iters to skip"
    default = 0
    hint = "Iterations to skip."
  endparam
  param off
    caption = "Hue cycle"
    default = 0
    min = 0
    max = 7
    hint = "This rotates the coloring order of the balls."
  endparam
}

UF效果
New.jpg
老兄改得秒,造这八切圆陷阱更加简单,长了见识,谢谢。
两个陷阱,仅限于这些球关于坐标轴对称情况下,减少成两个陷阱。但如何对各球进行编号,让八个球按编号赋于不同色呢?
可以仿照原来的弄。
8Circles2 {
init:
  int iter = 0
  float rangemun = 0
  float x = 0
  float y = 0
  float num = 8
  float Xabs = 0
  float Yabs = 0
  float Dsgd0 = 0
  float Dsgd1 = 0
  float Circle = 0
  float ZtoPsqd = 0
  float Rc = @r
  float Phi = #pi * 0.125
  float Rm = Rc * sin(Phi)
  float RcSqd = Rm^2
  bool Trapped = false
loop:
  iter = iter + 1
  x = real(#z)
  y = imag(#z)
  if iter > @skip && !Trapped
    Xabs = abs(real(#z))
    Yabs = abs(imag(#z))
    Dsgd0 = (Xabs-Rc*sin(phi))^2 + (Yabs - Rc*cos(phi))^2
    Dsgd1 = (Xabs-Rc*sin(3*phi))^2 + (Yabs - Rc*cos(3*phi))^2
   if Dsgd0 < RcSqd
      Trapped = true
      ZtoPsqd= Dsgd0
     if Y >  0&& x > 0
        Circle = 1
      elseif y < 0 && x > 0
        Circle = 0
      elseif y < 0 && x < 0
        Circle = 5
      else
        Circle = 4
      endif
   elseif Dsgd1 < RcSqd
      Trapped = true
      ZtoPsqd= Dsgd1
      if Y >  0&& x > 0
        Circle = 2
      elseif y < 0 && x > 0
        Circle = 3
      elseif y < 0 && x < 0
        Circle = 6
      else
        Circle = 7
      endif
   endif
endif
final:
  if !trapped
    #solid = true
  else
    Circle = ((Circle + @off) % num)/(num-1)
    float Ratio = sqrt(ZtoPsqd/Rcsqd)
    float ColorIndex = 120 * Ratio + Circle * 100
    #index = (ColorIndex + 1) % 256 /256
  endif
default:
  title = "8 Circles2"
  param r
    caption = "Circle radius"
    default = 0.4
  endparam
  param skip
    caption = "Iters to skip"
    default = 0
    hint = "Iterations to skip."
  endparam
  param off
    caption = "Hue cycle"
    default = 0
    min = 0
    max = 7
    hint = "This rotates the coloring order of the balls."
  endparam
}

New.jpg
将上文件稍作修改,可以得到:

代码:
8Circles2 {
init:
  int iter = 0
  float rangemun = 0
  float x = 0
  float y = 0
  float num = 10
  float Xabs = 0
  float Yabs = 0
  float Dsgd0 = 0
  float Dsgd1 = 0
  float Dsgd2 = 0
  float Ratio = 0
  float Circle = 0
  float ZtoPsqd = 0
  float Rc = @r
  float Phi = #pi /12
  float Rm = Rc * sin(Phi)
  float RcSqd = Rm^2
  bool Trapped = false
loop:
  iter = iter + 1
  x = real(#z)
  y = imag(#z)
  if iter > @skip && !Trapped
    Xabs = abs(real(#z))
    Yabs = abs(imag(#z))
    Dsgd0 = (Xabs-Rc*sin(phi))^2 + (Yabs - Rc*cos(phi))^2
    Dsgd1 = (Xabs-Rc*sin(5*phi))^2 + (Yabs - Rc*cos(5*phi))^2
    Dsgd2 = abs(abs(x)-abs(y))
   if Dsgd0 < RcSqd
      Trapped = true
      ZtoPsqd= Dsgd0
     if Y >  0&& x > 0
        Circle = 1
      elseif y < 0 && x > 0
        Circle = 0
      elseif y < 0 && x < 0
        Circle = 5
      else
        Circle = 4
      endif
      Ratio = sqrt(ZtoPsqd/Rcsqd)
   elseif Dsgd1 < RcSqd
      Trapped = true
      ZtoPsqd= Dsgd1
      if Y >  0&& x > 0
        Circle = 2
      elseif y < 0 && x > 0
        Circle = 3
      elseif y < 0 && x < 0
        Circle = 6
      else
        Circle = 7
         endif
         Ratio = sqrt(ZtoPsqd/Rcsqd)
   elseif Dsgd2 < 4*RcSqd
      trapped = true
      ZtoPsqd = 4*Dsgd2
      if x > 0
        Circle = 9
      else
        Circle = 8
     endif
     Ratio = sqrt(0.15*ZtoPsqd/Rcsqd)
   endif
endif
final:
  if !trapped
    #solid = true
  else
    Circle = ((Circle + @off) % num)/(num-0)
    float ColorIndex = 120 * Ratio + Circle * 100
    #index = (ColorIndex + 1) % 256 /256
  endif
default:
  title = "8 Circles2"
  param r
    caption = "Circle radius"
    default = 0.4
  endparam
  param skip
    caption = "Iters to skip"
    default = 0
    hint = "Iterations to skip."
  endparam
  param off
    caption = "Hue cycle"
    default = 0
    min = 0
    max = 7
    hint = "This rotates the coloring order of the balls."
  endparam
}

RE: 巧用对称性,一个陷阱四个球

[local]1[/local]
捕获uf3.jpg
就是我不会着色,没有蓝色和绿色,不太好看
New.jpg
New.jpg
返回列表