返回列表 回复 发帖
位于sam.ufm系列中的科赫雪花曲线,我看了,扫描法出来的图形,美。我正在造第一个开关项,觉得这开关项可能简单点,单就这开关项的程序还没完全懂,我感觉到此分形能用几何画板做。
KochCurve {
; By Samuel Monnier, 2.1.00
init:
  z = #pixel
  zz = 0
  ; Twist
  z = 1/sqrt(@r)*real(z) + 1i*sqrt(@r)*imag(z)
  x = real(z)
  y = imag(z)
  sq3 = sqrt(3)
  bool bail2 = false
  bool bail = false
  i = 0
loop:
  i = i + 1
  ;----------------
  ; First Iteration
  ;----------------
  if i == 2
   
   
   
    ; Calculate the argument of z
    arg = atan2(z)
  
    ; Inside approximation
    if @region == 0 || @region == 2
  
      ; Draw the Star of David
      if (y + 1/sq3 > 0) && (sq3*x - y + 2/sq3 > 0) \
         && (sq3*x + y - 2/sq3 < 0)
        bail = true
      endif
      if (-y + 1/sq3 > 0) && (sq3*x + y + 2/sq3 > 0) \
         && (sq3*x - y - 2/sq3 < 0)
        bail = true
      endif
   
      ; Deal the case where z needs a rotation
      if (arg > 5/6*pi) || (arg < -pi/2)
        z = z*exp(1i*4/3*pi)
      endif
      if (arg < pi/6) && (arg > -pi/2)
        z = z*exp(1i*2/3*pi)
      endif
      z = z - 1i*1/sq3
      if @region == 2
        zz = z
        z = #pixel
      endif
    endif
  
    ; Outside approximation
    if @region == 1 || @region == 2
  
      ; Draw the hexagon
      if |x| > 1 || x/sq3 + y - 2*sq3/3 > 0 \
         || x/sq3 + y + 2*sq3/3 < 0 || x/sq3 \
         - y + 2*sq3/3 < 0 || x/sq3 - y - \
         2*sq3/3 > 0
        bail = true
      endif
   
      ; Deal the case where z needs a rotation
      if (abs(arg) < pi/6)
        z = z*exp(-1i*pi/2)
      elseif (arg > pi/6) && (arg < pi/2)
        z = z*exp(-1i*5*pi/6)
      elseif (arg > pi/2) && (arg < 5*pi/6)
        z = z*exp(1i*5*pi/6)
      elseif (abs(arg) > 5*pi/6)
        z = z*exp(1i*pi/2)
      elseif (arg < -pi/6) && (arg > -pi/2)
        z = z*exp(-1i*pi/6)
      elseif (arg < -pi/2) && (arg > -5*pi/6)
        z = z*exp(1i*pi/6)
      endif
      z = z + 1i
      z = sq3*z
      
    endif
  
  ;----------------
  ;Other Iterations
  ;----------------
  elseif i > 2
    ; "Undo" the offset parameter's
    ; action
    z = z + @offset
    z = 1/sqrt(@r)*real(z) + 1i*sqrt(@r)*imag(z)
    if @region == 2
      oldz = z
      z = zz
      zz = oldz
    endif
    ; Magnify z so that a simple formula
    ; allows to compute...
    z = 3*z
    x = real(z)
    y = imag(z)
    ; ...the new triangle on the segment   
    if (y > 0) && (sq3*x - y + sq3 > 0) \
       && (sq3*x + y - sq3 < 0)
      bail2 = true
    endif
    ; Restore the original value of z
    z = z/3
  
    x = real(z)
    y = imag(z)
    ; Transforms the left segment
    if x < -1/3
      z = 3*z + 2
    ; Transforms the right segment
    elseif x > 1/3
      z = 3*z - 2
    else
      ; Transforms the middle-left segment
      if x < 0
        z = z + 1/3
        z = z*exp(-1i*pi/3)
        z = 3*z - 1
      ; Transforms the middle-right segment
      else
        z = z - 1/3
        z = z*exp(1i*pi/3)
        z = 3*z + 1
      endif
    endif
  
  endif
  
  ; A parameter to fool some coloring
  ; algorythms like final decomposition...
  if i >= 2
    z = z - @offset
  endif
  
bailout:
  bail == false && bail2 == false
  
default:
  title = "Koch Curve"
  helpfile = "sam-help/kochcurves.htm"
  helptopic = "kcurve"
  magn = 1.5
  center = (0.0002,0)
  maxiter = 50
  param region
    caption = "Trapped Region"
    default = 0
    enum = "Inside" "Outside" "Both"
  endparam
  param offset
    caption = "Offset"
    default = (0,0)
  endparam
  param r
    caption = "Twist Parameter"
    default = (1,0)
  endparam  
}
Fractal1.jpg
42# 榕坚
判断是有点多,我看到代码有点长,判断又多,吓了一跳。看了几遍,感觉只造第一个开关项,可除去代码中的好几段,也许能成,我算了一部分数据了,晚上再看看,能否整个样子,不过,实在没把握。
太困难了,已决定放弃了。
返回列表