返回列表 回复 发帖
New.jpg
UF中的一个陷阱,Mathcad实现了
UF代码
HypocycloidTrap {
  ; Paul Carlson
  ; Coloring Method extraced from "HNspirJ2".
  ; By Ken Childress July 1999.  
init:
  bool trapped = FALSE
  float range_num = 0
  float num_ranges = real(@RangesColors)
  float colors_in_range = imag(@RangesColors)
  float index_factor = (colors_in_range - 1) / @width
  float color_index = 0
  int iter = 0
  complex i = (0,1)
  complex k = 0
  complex angle = 0
  complex ka = 0
  complex rz = 0
  complex iz = 0
  complex v = 0
  float dist = 0

loop:
  IF !trapped && (iter >= @skip)
    angle = atan(imag(#z) / real(#z))
    k = 1.2 - @hfactor
    ka = k * angle / @hfactor
    rz = k * cos(angle) + @hfactor * cos(ka)
    iz = k * sin(angle) + @hfactor * sin(ka)
    v = rz + i * iz
    dist = abs(|#z| - |v|)
   
    IF (dist < @width && iter >= @skip)
      trapped = TRUE
      range_num = iter % num_ranges
      color_index = index_factor * dist +  range_num * colors_in_range
    ENDIF
   
  ENDIF

  iter = iter + 1

final:
  IF trapped
    #index = ((real(color_index)+1) % 256) / 256 + @randomness * real(#random)
  ELSE
    IF @solid
      #solid = TRUE
    ELSE
      #index = @back_color / 256
    ENDIF
  ENDIF
   
default:
  title = "Hypocycloid Trap"

  param width
    caption = "Stalk Width Factor"
    default = 0.03
    hint = "Controls stalk width."
  endparam

  param hfactor
    caption = "Hypocycloid Factor"
    default = 0.4
    hint = "Hypocycloid Factor."
  endparam
   
  param skip
    caption = "Iterations to skip"
    default = 0
    hint = "Iterations to skip."
  endparam

  param RangesColors
    caption = "Ranges and Colors"
    default = (2, 125)
    hint = "Number of Color Ranges and Number of Colors in each Range."
  endparam

  param back_color
    caption = "Background Color"
    hint = "This is the color used for orbits that aren't trapped. It has \
           no effect if the background is solid."
    default = 254
    min = 0
    max = 255
  endparam

  param solid
    caption = "Solid Background"
    hint = "If this is enabled orbits that aren't trapped become solid."
    default = false
  endparam
  
  param randomness
    caption = "Random Texture"
    default = 0.0
    hint = "This adds a random texture to the coloring."
  endparam
}
New.jpg
52# lnszdzg


点陷阱,用了HLS颜色
New.jpg
New.jpg
UF代码

Rings_Coloring {
  ; Paul W. Carlson
  ; Variant #1 extracted from "RsNewtMset1".
  ; Variant #2 extracted from "R4Julia".
  ; By Ken Childress June 1999.
init:
  bool first = TRUE
  bool trapped = FALSE
  int iter = 0
  float HalfT = 0.5 * @T
  float Phi = #pi * 0.125
  float Ro = @Rm + HalfT
  float Py = @Rm * sin(Phi)
  float Px = @Rm * cos(Phi)
  float Dsqd = @Rm * @Rm + Ro * Ro - 2 * Ro * Px
  float color_index = 252
  float index_factor = @colors_in_range - 1
   
  ; Initialization for Variant #1
  complex k = (0.5, 0.5)
  float index_factor1 = (@colors_in_range - 1) / @Rm

loop:
  IF @Variant == 0
  
    IF (!trapped && (abs(cabs(#z) - @Rm) < HalfT) && \
      first == FALSE && iter >= @skip)
      
      trapped = TRUE
      float X = real(#z)
      float Y = imag(#z)
      float Xabs = abs(X)
      float Yabs = abs(Y)
      IF (Xabs >= Yabs)
        float WtoPsqd = (Xabs-Px)*(Xabs-Px) + (Yabs-Py)*(Yabs-Py)
      ELSE
        WtoPsqd = (Xabs-Py)*(Xabs-Py) + (Yabs-Px)*(Yabs-Px)
      ENDIF
      IF (X >= 0 && Y >= 0)
        IF (Xabs >= Yabs)
          float Segment = 0
        ELSE
          Segment = 1
        ENDIF
      ELSEIF (X < 0 && Y >= 0)
        IF (Xabs < Yabs)
          Segment = 2
        ELSE
          Segment = 3
        ENDIF
      ELSEIF (X < 0 && Y < 0)
        IF (Xabs >= Yabs)
          Segment = 4
        ELSE
          Segment = 5
        ENDIF
      ELSE
        IF (Xabs < Yabs)
          Segment = 6
        ELSE
          Segment = 7
        ENDIF
      ENDIF
      float Ratio = sqrt(WtoPsqd/Dsqd)
      ; Modulate Segment for less than eight ranges.
      float range_num = Segment % @num_ranges
      color_index = index_factor * Ratio + range_num * @colors_in_range
    ENDIF
    first = FALSE
   
  ELSEIF @Variant == 1
  
    IF !trapped && iter >= @skip
      float dist = abs(|#z - k| - 0.01)
      IF dist < @Rm
        trapped = TRUE
        float range_num = iter % @num_ranges
        color_index = index_factor1 * dist + range_num * @colors_in_range
      ENDIF
    ENDIF

  ENDIF
  
  iter = iter + 1

final:
  if trapped
    ; Adjust color index to gradient range.
    #index = (color_index + 1) % 256 / 256 + @randomness * real(#random)
  else
    if @solid
      #solid = true
    else
    ; For the purists we don't have to be solid.
      #index = @back_color / 256
    endif
  endif

default:
  title = "Ring Coloring"
  
  param Variant
    caption = "Ring Variant"
    enum = "Variant #1" "Variant #2"
    default = 0
    hint = "The Ring variant to use."
  endparam

  param Rm
    caption = "Ring radius"
    default = 1.0
    hint = "The radius to the midline of the ring."
  endparam

  param T
    caption = "Ring thickness"
    default = 0.2
    hint = "The thickness of the ring. This is not used for Variant #2."
  endparam
  
  param skip
    caption = "Iterations to Skip"
    default = 0
    hint = "The number of iterations to skip.  This is not used for Normal."
  endparam

  param num_ranges
    Caption = "Color ranges"
    hint = "This is the number of separate color ranges."
    default = 8
  endparam

  param colors_in_range
    Caption = "Colors in range"
    hint = "This is the number of colors in each color range."
    default = 30
  endparam

  param back_color
    caption = "Background Color"
    hint = "This is the color used for orbits that aren't trapped. It has \
           no effect if the background is solid."
    default = 254
  endparam

  param solid
    caption = "Solid Background"
    hint = "If this is enabled orbits that aren't trapped become solid."
    default = false
  endparam
  
  param randomness
    caption = "Random Texture"
    default = 0.0
    hint = "This adds a random texture to the coloring."
  endparam
}
New.jpg

一园一环陷阱
New.jpg

同臂同色
New.jpg
New.jpg
New.jpg
New.jpg
New.jpg
New.jpg
返回列表