MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: color assignment in an Mathematica IFS


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


  • Prev by Date: Workbench 1.0 -> 1.1 upgrade issues
  • Next by Date: Re: Re: Help with Root function
  • Previous by thread: Re: color assignment in an Mathematica IFS
  • Next by thread: ConversionRules documentation problem