- UID
- 22171
- 帖子
- 418
- 精华
- 1
- 积分
- 1185
|
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
} |
|