NB. Create fractal mountains using
NB. successive interpolation and random additions
NB. Various Hurst exponents give rise to different
NB. images. By Cliff Reiter, May 2002
NB. Requires povkit+.ijs
NB. render the resulting pov files with povray
NB. see www.povray.org
load 'fvj2\povkit+'
NB. creates a list of 4 veritces from 2 by 2 array of vertices
quad=:0 1 3 2&{@(,/)
NB. range of data
range=:(>./-<./)@,
NB. create color map: gray for steep, brown and green for flatter
]fmc=.0.3 0.2 0.02,0 0.2 0,0.1 0.4 0,0.2 0.2 0.2,:0.6 0.6 0.6
$FMC=:interp^:4 fmc
NB. format numbers with leading zeros
nfmt=: 3&$: : ({&'0123456789'@:(([#10"_)#:]))
NB. need special sz for m0
sz=: %@-:@<:@#@] ^ [
NB. create pov file with given fileprefix and hurst exponent
NB. fileprefix mk_fm_pov hurst_exp
mk_fm_pov=:3 : 0
'\r\fm2\fm' mk_fm_pov y.
:
(9!:1) 7^5
$z=.y. m0 fm 6 NB. set number of levels of refinement here
$x=.y=._4+8*(i.%<:)#z
$xyz=.(x([,])"0/y),"1 0 z
$polys=.,/,/2 2 quad ;._3 xyz
$rangez=. 2 2 range;._3 {:"1 xyz
$colors=. ,/FMC{~65 cile rangez
pfn=.x.,(nfmt 100*y.),'.pov'
view_pars_fm fwrite pfn
(colors fmtquad polys) fappends pfn
)
NB. '\r\fm2\fm' mk_fm_pov 0.6 NB. creates \r\fm2\fm060.pov