Re: Re: color assignment in an Mathematica IFS
- To: mathgroup at smc.vnet.net
- Subject: [mg79507] Re: [mg79455] Re: color assignment in an Mathematica IFS
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Sat, 28 Jul 2007 05:30:29 -0400 (EDT)
- References: <200707241012.GAA26515@smc.vnet.net> <f86pua$nk9$1@smc.vnet.net> <200707270949.FAA02785@smc.vnet.net>
Roger Bagula wrote:
> Daniel Lichtblau wrote:
>
>
>>The primary bottleneck is in the iterative flattening of a growing list,
>>inside the loop. This in effect makes it a nested loo, taking complexity
>
>>from O(n) to O(n^2). The code below is probably equivalent and should be
>
>>reasonably fast.
>> [...]
>
>
> Daniel Lichtblau
> Wolfram Research
>
> Thanks.
> This works very fast here:
>
> Clear[f, dlst, pt, cr, ptlst]
> dlst = Table[ Random[Integer, {1, 4}], {n, 10000}];
> f[j_, {x_, y_}] := 0.5*{x, y} + 0.5*Reverse[IntegerDigits[j - 1, 2, 2]]
>
> pt = {0.5, 0.5};
>
> cr[n_] = If[n - 1 == 0, RGBColor[0, 0, 1], If[n - 2 ==
> 0, RGBColor[0, 1, 0], If[n - 3 == 0, RGBColor[1, 0, 0], RGBColor[0, 0,
> 0]]]]
> ptlst = Table[{cr[dlst[[j]]], Point[pt = f[dlst[[j]], Sequence[pt]]]},
> {j, Length[dlst]}];
>
> Show[Graphics[ptlst], AspectRatio -> Automatic, PlotRange -> All]
>
> I think you are going to save me a lot of time.
> Roger Bagula
Hre is a corrected form as compared to what I sent earlier. It is also
slightly faster.
cr[1] = RGBColor[0, 0, 1];
cr[2] = RGBColor[0, 1, 0];
cr[3] = RGBColor[1, 0, 0];
cr[4] = RGBColor[0, 0, 0];
dlst = RandomInteger[{1, 4}, {10^4}];
f[j_, x_, y_] :=
0.5*{x, y} + 0.5*Reverse[IntegerDigits[j - 1, 2, 2]];
pt = {0.5, 0.5};
ptlst = Table[{cr[dlst[[j]]],
Point[pt = f[dlst[[j]], Apply[Sequence, pt]]]},
{j,Length[dlst]}];]
Daniel Lichtblau
Wolfram Research
- References:
- color assignment in an Mathematica IFS
- From: Roger Bagula <rlbagula@sbcglobal.net>
- Re: color assignment in an Mathematica IFS
- From: Roger Bagula <rlbagula@sbcglobal.net>
- color assignment in an Mathematica IFS