返回列表 回复 发帖

复分形难题再度征解

搞了好几遍,尝试了各种情形,仍不能得出结果:
Carr1965 {
; Updated for UF2 by Erik Reckase, March 2000
           ; Modified Sylvie Gallet frm.
init:
  z=c=pixel
  int compt=0, int limit=round(real(p1)), float bailout=4
loop:
  IF (compt>=limit)
    c = (-.743380900000982,.131850030300002)
  ELSE
    c = z + c/2.125
  ENDIF
  z=z*z+c
  compt=compt+1
bailout:
  |real(z)|<=bailout
default:
  title = "Carr 1965"
  periodicity = 0
  maxiter = 500
  magn = .9
  center = (0,0)
  method = multipass
  param p1
    caption = "Iter Limit"
    default = (100,0)
    hint = "The real part of this parameter signals a change \
            in the value of c. The imaginary part is not used."
  endparam
}
UF中效果图如下:
Fractal2.jpg
昨天干了五六遍,失败,今天干了一上午,失败了三次,终于我已经找到解决方案了,正在扫描。
未命名2.jpg
改变P1的横坐标为2,得:
未命名1.jpg
这个代码读起来,太费脑细胞了,UF中有几个分形代码,要么太过漫长,要么逻辑判断太多,作起来太费劲,只好望洋兴叹了。
这个代码,我可读不懂了。榕兄作得不错。
8# 榕坚
谢谢。佩服老兄的钻研精神与思维的敏捷。UF中,每当我看到这种代码,就如珠峰挡在前面。对这种逻辑判断太多的分形,我是望而生畏。榕兄有空时,能否制成视频,详细反映出制作过程。注意有空时。另还有一个分形,是谢尔宾斯基三角形,代码也十分漫长,一时忘了在何处,我找着后发在这里。
位于gnd.ufm中,
gnd-slope-sierpinski2 {
; Based on a formula by Ramiro Perez
; Slope version by Gilles Nadeau, 2007
init:
  z1 = #pixel
  z2 = #pixel + @offset
  z3 = #pixel + flip(@offset)
  int done = 2
  float modz = 0.0
  float e1 = 0.0         ; potentials
  float e2 = 0.0
  float e3 = 0.0
  float vx = 0.0         ; normal vector
  float vy = 0.0
  float vz = 0.0
  float vd = 0.0
  float iterexp1 = 0.0
  float iterexp2 = 0.0
  float iterexp3 = 0.0

loop:

  IF ((imag(z1)>=.575*real(z1)) && (-.575*real(z1)<=imag(z1)))
    z1 = 2*z1-1i
  ELSEIF (real(z1)<=0)
    z1 = 2*z1+(.8660254, 0.5)
  ELSEIF (real(z1)>0)
    z1 = 2*z1+(-.8660254, 0.5)
  ELSE
    z1 = 2*z1
  ENDIF

  IF ((imag(z2)>=.575*real(z2)) && (-.575*real(z2)<=imag(z2)))
    z2 = 2*z2-1i
  ELSEIF (real(z2)<=0)
    z2 = 2*z2+(.8660254, 0.5)
  ELSEIF (real(z2)>0)
    z2 = 2*z2+(-.8660254, 0.5)
  ELSE
    z2 = 2*z2
  ENDIF

  IF ((imag(z3)>=.575*real(z3)) && (-.575*real(z3)<=imag(z3)))
    z3 = 2*z3-1i
  ELSEIF (real(z3)<=0)
    z3 = 2*z3+(.8660254, 0.5)
  ELSEIF (real(z3)>0)
    z3 = 2*z3+(-.8660254, 0.5)
  ELSE
    z3 = 2*z3
  ENDIF
  
  modz = |z1|
  
  iterexp1 = iterexp1 + exp(-cabs(z1))
  iterexp2 = iterexp2 + exp(-cabs(z2))
  iterexp3 = iterexp3 + exp(-cabs(z3))
  done = done + 1         ; increment iteration counter

  IF (modz > @bailout ||       \
      @everyiter ||            \
      done == #maxit + 2)      ; done, or every iteration, or last
    ; determine continuous iteration (height) for each point
      e1 = iterexp1 * @zscale
      e2 = iterexp2 * @zscale
      e3 = iterexp3 * @zscale

    ; apply transfer function
    ; a function is not used because these are floats
    ; and not all functions apply to floats
    IF (@xfer == 1)             ; log
      e1 = log(e1)
      e2 = log(e2)
      e3 = log(e3)
    ELSEIF (@xfer == 2)         ; sqrt
      e1 = sqrt(e1)
      e2 = sqrt(e2)
      e3 = sqrt(e3)
    ELSEIF (@xfer == 3)         ; cuberoot
      e1 = (e1)^(1/3)
      e2 = (e2)^(1/3)
      e3 = (e3)^(1/3)
    ELSEIF (@xfer == 4)         ; exp
      e1 = exp(e1)
      e2 = exp(e2)
      e3 = exp(e3)
    ELSEIF (@xfer == 5)         ; sqr
      e1 = sqr(e1)
      e2 = sqr(e2)
      e3 = sqr(e3)
    ELSEIF (@xfer == 6)         ; cube
      e1 = (e1)^3
      e2 = (e2)^3
      e3 = (e3)^3
    ELSEIF (@xfer == 7)         ; sin
      e1 = sin(e1)
      e2 = sin(e2)
      e3 = sin(e3)
    ELSEIF (@xfer == 8)         ; cos
      e1 = cos(e1)
      e2 = cos(e2)
      e3 = cos(e3)
    ELSEIF (@xfer == 9)         ; tan
      e1 = tan(e1)
      e2 = tan(e2)
      e3 = tan(e3)
    ENDIF

    ; apply post-scale
    e1 = e1 * @zscale2
    e2 = e2 * @zscale2
    e3 = e3 * @zscale2

      vx = e2-e1
      vy = e3-e1
      vz = -@offset
      ; normalize vector
      vd = 1/sqrt(sqr(vx)+sqr(vy)+sqr(vz))
      vx = vx*vd
      vy = vy*vd
      vz = vz*vd
      z = vx + flip(vy)         ; fudge z from vector
  ELSE               ; didn't compute z this time
    z = z1            ; use primary iteration value to keep
                      ; periodicity working
  ENDIF
  IF (modz > @bailout)         ; we're done
    done = 0
  ENDIF

bailout:
  (done > 0)
default:
  title = "Slope Sierpinski Triangle II"
  center = (0.0, 0.0)
  magn = 1.1538
  maxiter = 149
  method = multipass
  periodicity = 0

  float param version
    default = 1.1
    visible = false
  endparam

  param bailout
    caption = "Bailout value"
    default = 127
    min = 1
  endparam

  param offset
    caption = "Orbit Separation"
    default = 0.01
    hint = "Defines how far apart the simultaneous orbits are.  Smaller \
            distances will produce more accurate results."
  endparam
  param xfer
    caption = "Height Transfer"
    default = 0
    enum = "linear" "log" "sqrt" "cuberoot" "exp" "sqr" "cube" \
    "sin" "cos" "tan"
    hint = "This function will be applied to the height value \
            before a slope is calculated."
  endparam
  param zscale
    caption = "Height Pre-Scale"
    default = 1.0
    hint = "Specifies the ratio between height and distance.  Higher \
            values will exaggerate differences between high and low. \
       In general, you will want to use smaller numbers here."
  endparam
  param zscale2
    caption = "Height Post-Scale"
    default = 0.025
    hint = "Specifies the ratio between height and distance; like \
            Height Pre-Scale, except that this value is applied after \
       the transfer function."
  endparam
  param everyiter
    caption = "Every Iteration"
    default = false
    hint = "If set, the surface normal will be computed at every \
            iteration.  If you are using a coloring algorithm which \
       processes every iteration, you will need this."
  endparam
}
Fractal2.jpg
我从面板上看了,好象那些函数开关项,一点作用都不起,榕兄再看看,是不是这样。
11# 榕坚
这个代码还容易解读,确实需要时间与足够的耐心才成。我先帖在这儿,我也觉得有点麻烦,先干到其它的,等时间合适,再来尝试尝试。我看到此图不错,萌发了制造出来的欲念。
14# 榕坚
榕兄速度真快,做得十分漂亮,佩服。我明天做做看,不懂再请教,这代码长,一看有些胆怯。
IF (modz > @bailout ||       \
      @everyiter ||            \
中的@everyiter是什么意思,你是如何处理的呢?问好。
init:
  z1 = #pixel
  z2 = #pixel + @offset
  z3 = #pixel + flip(@offset)

IF ((imag(z1)>=.575*real(z1)) && (-.575*real(z1)<=imag(z1)))
    z1 = 2*z1-1i
  ELSEIF (real(z1)<=0)
    z1 = 2*z1+(.8660254, 0.5)
  ELSEIF (real(z1)>0)
    z1 = 2*z1+(-.8660254, 0.5)
  ELSE
    z1 = 2*z1
  ENDIF
我用画板造此分形时,我在理解这段代码时,卡住了!这段代码的意思是:满足不同的条件时,Z1的算法不同,由红色部分的 Z1,判断当((imag(z1)>=.575*real(z1)) && (-.575*real(z1)<=imag(z1)))成立时,按前面红色部分的z1计算 z1 = 2*z1-1i。当此条件不成立,而按红色部分的z1判断real(z1)<=0成立时,由红色部分的z1按算式z1 = 2*z1+(.8660254, 0.5)算出z1;当这二个条件均不成立,但real(z1)>0成立,则按 z1 = 2*z1+(-.8660254, 0.5)仍由红色的z1代入此式算z1.
这样问题出现了,ELSE下的算式,意思是上面三种情况均不满足,按z1 = 2*z1算z1,但当同时否定上面三种情况时,似又出现三种情况之一,这矛盾,如何解决呢?或者是我理解有误?
18# 榕坚
谢过榕兄指点,我正在画板中准备各数据,这段:
IF (modz > @bailout ||       \
      @everyiter ||            \
      done == #maxit + 2)      ; done, or every iteration, or last
    ; determine continuous iteration (height) for each point
      e1 = iterexp1 * @zscale
      e2 = iterexp2 * @zscale
      e3 = iterexp3 * @zscale
中的条件:modz > @bailout ||       \
      @everyiter ||            \
      done == #maxit + 2如何处理?之前的数据已经准备好了,到这里,又进行不下去了。
返回列表