[OpenSCAD] Barnsley Fern recursive

Colin Smart colin at tweedside.co.uk
Tue Sep 11 16:59:21 EDT 2018


If you are just drawing, consider using a different tool, such as processing.org

It avoids the extra effort of maintaining an ‘object’.

If you want an object, then I would generally look to do the numerical
processing elsewhere and import the shapes for rendering.

Others may have better ideas.

Colin

---------------------------------
Colin Smart (07968 049660)


> On 11 Sep 2018, at 21:06, Eric Buijs <ebuijs at mac.com> wrote:
>
> It's probably a crazy idea but I've created a simple script for the Barnsley
> Fern fractal. The script works but it brings my PC, an 2011 iMac, to it's
> knees (OpenSCAD takes over 10Gb of memory with the script below and I want
> to increase the number of objects even further). I was wondering if someone
> has any suggestions to improve/optimize the script and make it less memory
> hungry. Or is OpenSCAD not suitable for this kind of work. Thanks.
>
> m1 = [[0,0],[0,0.16]];
>
> c1 = [0,0];
>
> m2 = [[0.85,0.04],[-0.04,0.85]];
>
> c2 = [0, 0.16];
>
> m3 = [[0.2,-0.26],[0.23,0.22]];
>
> c3 = [0,1.6];
>
> m4 = [[-0.15,0.28],[0.26,0.24]];
>
> c4 = [0,0.44];
>
> function f1(p) = m1 * p + c1;
>
> function f2(p) = m2 * p + c2;
>
> function f3(p) = m3 * p + c3;
>
> function f4(p) = m4 * p + c4;
>
> module plotCircle(p) {
>    translate(100 * p) circle(r=0.5,$fn=50);
> }
>
> module BarnsleyFern(p,index) {
>    r = rands(0,1,1)[0];
>    plotCircle(p);
>    if (r <= 0.01) {
>        BarnsleyFern(f1(p), index-1);
>    }
>    else if (r > 0.01 && r <=0.86) {
>        BarnsleyFern(f2(p),index-1);
>    }
>    else if (r > 0.86 && r <=0.94) {
>        BarnsleyFern(f3(p),index-1);
>    }
>    else if (r > 0.94 && r < 0.99) {
>    BarnsleyFern(f4(p),index-1);
>    }
> }
>
>
> p = [0,0];
> BarnsleyFern(p,20000);
>
>
>
>
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss at lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



More information about the Discuss mailing list