Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Simple fractal

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121807] Re: Simple fractal
  • From: Ulrich Arndt <ulrich.arndt at data2knowledge.de>
  • Date: Mon, 3 Oct 2011 04:22:27 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201110020636.CAA28033@smc.vnet.net>

Hi,

might be not the most elegant solution but will produce some nice pictures.

Clear[fPoint, fGraph]
maxit = 10;
fPoint[{x_?NumericQ, y_?NumericQ}, sides_Integer, scale_,
   level_?IntegerQ] :=
  Table[{x, y} +
    scale^level*{Cos[i*360/sides*Degree],
      Sin[i*360/sides*Degree]}, {i, 1, sides + 1}];
fGraph[sides_, scale_, n_, m_] := Module[{result},
   result = ConstantArray[0, m];
   For[c = 1, c <= n, c++,
    Which[c == 1,
     result[[c]] = {fPoint[{0, 0}, sides, scale, (c - 1)]};,
     True,
     result[[c]] =
       fPoint[#, sides, scale, (c - 1)] & /@
        Union[Flatten[result[[c - 1]], 1]];
     ]
    ];
   Show[Graphics[Line[#]] & /@ result[[1 ;; n]]]
   ];

Manipulate[
 fGraph[sides, scale, n, maxit],
 {{n, 5}, 1, maxit, 1}, {{scale, 1/2}, 0.1, 0.9}, {{sides, 3}, 3, 10,
  1}]

Ulrich

Am 02.10.2011 um 08:36 schrieb Tom De Vries:

> I am trying to create a very simple fractal, but I am not having any success.
>
> I'd like to learn how to do this recursively, and hoping someone can
> give me a bit of a push in the right direction.
>
> It's a simple triangle with triangles at each corner, with triangles
> at each corner, etc.
>
> Below,  a simple "level 1" graphic.
>
> scale = 0.5;
>
> list1 = Table[{0, 0} + {Cos[i*120*Degree], Sin[i*120*Degree]}, {i, 1,
> sides + 1}];
>
> list2 = (Table[#1 + scale*{Cos[i*120*Degree], Sin[i*120*Degree]}, {i,
> 1, sides + 1}] & ) /@  list1;
>
> Graphics[{Line[list1], Line[list2]}]
>
>
> Ideally I'd like to have a Manipulate with a slider for the level of
> the fractal,  the scale applied to each level, and the distance each
> corner triangle is from the centre triangle.
>
> Sorry,  I know this is simple programming,  but I don't have any ideas
> how to start.
>
> Tom De Vries
>

--
Ulrich Arndt
Mobile: +49 172 287 6630
ulrich.arndt at data2knowledge.de
www.data2knowledge.de

data2knowledge GmbH
Fahrenheitstr. 1
D-28359 Bremen

Gesch=E4ftsf=FChrung: Ulrich Arndt
Sitz der Gesellschaft: Bremen, Amtsgericht Bremen, HRB 26480 HB





  • References:
  • Prev by Date: Re: A fast way to compare two vectors
  • Next by Date: Re: DynamicModule Pure Function
  • Previous by thread: Simple fractal
  • Next by thread: Re: Simple fractal