[Date Index]
[Thread Index]
[Author Index]
Re: translating code from True Basic to Mathematica
*To*: mathgroup at smc.vnet.net
*Subject*: [mg69420] Re: translating code from True Basic to Mathematica
*From*: Paul Abbott <paul at physics.uwa.edu.au>
*Date*: Tue, 12 Sep 2006 06:52:25 -0400 (EDT)
*Organization*: The University of Western Australia
*References*: <ee0sfs$b1g$1@smc.vnet.net>
In article <ee0sfs$b1g$1 at smc.vnet.net>,
Roger Bagula <rlbagula at sbcglobal.net> wrote:
> I did some IFS based on {r,theta} variable iteration
> several years back.
> One seems to have become a favorite.
> Arg[] and ArcTan[] in Mathematica aren't exactly the same function as
> Angle() in True Basic!
>
> A delicate lace like fractal that I did several years back is at:
> http://local.wasp.uwa.edu.au/~pbourke/fractals/lace/lace.basic
>
> C code is at:
> http://local.wasp.uwa.edu.au/~pbourke/fractals/lace/lace.c
>
> My best effort so far at a Mathematica translation is:
> Clear[ifs, f1, f2, f3, f4, f]
> f1[{x_, y_}] = N[{ -Cos[Arg[x + 1/2 + I*(y + Sqrt[3]/2)]]*
> Sqrt[x^2 +
> y^2] - 1/
> 2, -Sin[
> Arg[x + 1/2 + I*(y +
> Sqrt[3]/2)]]*Sqrt[x^2 + y^2] - Sqrt[3]/2}]/2;
> f2[{x_, y_}] = N[{ -Cos[Arg[x + 1/2 +
> I*(y - Sqrt[3]/2)]]*Sqrt[x^2 + y^2] -
> 1/2, -Sin[Arg[x + 1/2 + I*(y -
> Sqrt[3]/2)]]*Sqrt[x^2 +
> y^2] + Sqrt[3]/2}]/2;
> f3[{x_, y_}] = N[{ -Cos[Arg[x - 1 +
> I*(y)]]*Sqrt[x^2 + y^2] + 1, -Sin[Arg[x -
> 1 + I*(y)]]*Sqrt[x^2 + y^2]}]/2;
> f4[{x_, y_}] = N[{ -Cos[Arg[x + I*(y)]]*Sqrt[x^2 + y^2], -Sin[Arg[x +
> I*(y)]]*
> Sqrt[x^2 + y^2]}]/2;
> f[x_] := Which[(r = Random[]) <= 1/4, f1[x],
> r <= 1/2, f2[x],
> r <= 3/4, f3[x],
> r <= 1.00, f4[x]]
> ifs[n_] := Show[Graphics[{PointSize[.001],
> Map[Point, NestList[f, {0, 0.001}, n]]}], AspectRatio -> Automatic]
> ifs[10000]
Since Mathematica supports complex algebra, you can re-write this more
succintly as
g[1][z_] = E^( I Pi/3) + Abs[z] E^(I Arg[z + E^( I Pi/3)]);
g[2][z_] = E^(-I Pi/3) + Abs[z] E^(I Arg[z + E^(-I Pi/3)]);
g[3][z_] = Abs[z] E^(I Arg[z - 1]) - 1;
g[4][z_] = z;
f[z_]:= -1/2 g[Random[Integer, {1, 4}]][z]
ifs[n_] := Show[Graphics[{PointSize[0.001],
NestList[f, 0.001 I, n] /. Complex[a_, b_] :> Point[{a, b}]}],
AspectRatio -> Automatic]
In this way it is much easier to see the effect of each of the randomly
selected transformation functions.
Cheers,
Paul
_______________________________________________________________________
Paul Abbott Phone: 61 8 6488 2734
School of Physics, M013 Fax: +61 8 6488 1014
The University of Western Australia (CRICOS Provider No 00126G)
AUSTRALIA http://physics.uwa.edu.au/~paul
Prev by Date:
**Re: Re: Color names and the 10 elementary colors?**
Next by Date:
**Animation crash**
Previous by thread:
**translating code from True Basic to Mathematica**
Next by thread:
**Re: translating code from True Basic to Mathematica**
| |