POV-Ray : Newsgroups : povray.general : Re: Difference Small objects and Glass Cube : Re: Difference Small objects and Glass Cube Server Time
2 Aug 2024 16:26:49 EDT (-0400)
  Re: Difference Small objects and Glass Cube  
From: Tor Olav Kristensen
Date: 16 Sep 2004 02:57:26
Message: <41493956$1@news.povray.org>
Slime wrote:

>>  If the functions supported true recursion it would be rather easy:
>>
>>#declare MandIter =
>>  function(n, Re, Im, Zr, Zi)
>>  { select(n>50 | Zr*Zr+Zi*Zi > 2, 0,
>>           MandIter(n+1, Re, Im, Zr*Zr-Zi*Zi+Re, 2*Zr*Zi+Im), n/50)
>>  }
>>
>>#declare Mandel = function(Re, Im) { MandIter(0, Re, Im, Re, Im) }
>>
>>  (Now you could do for example "pigment { function { Mandel(x,y) }
> 
> ... }".)
> 
> And you can! Looks good. =)
...

Woaw ! That's nice. AFAIR from the pre-beta test period for v3.5,
it should not be possible for users to define recursive functions.

But obviously this has changed since then. (Unintentionally ?)


#version 3.6;

#include "colors.inc"

#declare IterFn =
   function(N, Re, Im, Zr, Zi) {
     select(
       N > 50 | Zr*Zr + Zi*Zi > 4,
       0,
       IterFn(N + 1, Re, Im, Zr*Zr - Zi*Zi + Re, 2*Zr*Zi + Im),
       N/50
     )
   }

#declare MandelFn = function(Re, Im) { IterFn(0, Re, Im, Re, Im) }

plane {
   -z, -2.5
   pigment {
     function { MandelFn(x, y) }
     color_map {
       [ 0.1 color Black   ]
       [ 0.3 color Cyan    ]
       [ 0.5 color Magenta ]
       [ 0.7 color Yellow  ]
       [ 0.9 color White   ]
     }
   }
   finish { ambient color White }
   translate 0.7*x
}

-- 
Tor Olav
http://subcube.net
http://subcube.com


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.