Re: Fractal Plane Filling Curves
- To: mathgroup at smc.vnet.net
- Subject: [mg9669] Re: Fractal Plane Filling Curves
- From: "Xah" <xah at best.com>
- Date: Fri, 21 Nov 1997 01:31:07 -0500
- Organization: smtp.best.com
- Sender: owner-wri-mathgroup at wolfram.com
In article <64qp3n$jbq at smc.vnet.net>, Kushner <maxnco at asan.com> wrote: >I want to experiment with fractals using Mathematica. I am researching >plane filling curves (motions actually)... >. What is difficult is >finding out how I can give an initiator and a generator and have >Mathematica carry out a couple steps to give me an idea of what it >looks like... As I've said in other messages, there are lots of program written on L-systems in Mathematica. In particular, Robert Dickau has them on his web site, together with codes. http://forum.swarthmore.edu/advanced/robertd/index.html If all you want is generating L-system graphics given its strings, you may find specific programs better suited. If you are on a Windows system, try FractInt. If you are on a Mac, try Paul Brouke's mac program. Their URL can be found at my web page http://www.best.com/~xah/PageTwo_dir/MathPrograms_dir/mathPrograms.html Now if you want to use Mathematica for some reason, here's one of my own code that does fractal curves. It is not based on string replacement or turtle graphics, but instead on graphics primitive directively. i.e. you specify how a line segment is transformed in terms of itself. To generate a fractal, you just apply the transformation recurvisely. If you are using Mathematica v.2.x, you need to replace all "\[Alpha]" by "alpha". LineTransform Clear[LineTransform]; LineTransform::"usage"= "LineTransform[graphics1,replacementList] is an L-system like graphical \ function. graphics1 is a list of Line or an Graphics object. replacementList \ is a List of Line or graphic directives and primitives. Each Line in \ graphics1 is replaced by the relation Line[{{0,0},{1,0}}]->replacementList. \ LineTransform[graphics1,replacementList,Line[{p1,p2}]] will use the relation \ Line[{p1,p2}]->replacementList. Example: \ LineTransform[Line[{{0,0},{1,0},{1,-1}}],{Line[{{0,0},{1/2,1/2},{1,0}}]}]"; LineTransform[initialImage_, replacement_]:=( N at initialImage/.line1:Line[{_,_,__}]:> Map[Line,Partition[First at line1,2,1]])/.Line[{p1_,p2_}]:> Block[{v,\[Alpha],scale},v=(p2-p1);\[Alpha]=ArcTan@@v;scale=N at Sqrt[v.v]; N at replacement/.{ line2_Line:> Map[{{Cos[\[Alpha]],-Sin[\[Alpha]]},{Sin[\[Alpha]], Cos[\[Alpha]]}}.#*scale+p1&,line2,{2}], Point[pt_]:> Point[({{Cos[\[Alpha]],-Sin[\[Alpha]]},{Sin[\[Alpha]], Cos[\[Alpha]]}}.pt*scale+p1)]}]; LineTransform[initialImage_,replacement_, Line[{p3_,p4_}]]:=( N at initialImage/.line1:Line[{_,_,__}]:> Map[Line,Partition[First at line1,2,1]])/.Line[{p1_,p2_}]:> Block[{v,v2,\[Alpha],scale},v=N@(p2-p1);v2=N@(p4-p3); \[Alpha]=N@(ArcTan@@v-ArcTan@@v2);scale=N@(Sqrt[v.v]/Sqrt[v2.v2]); N at replacement/.{ line2_Line:> Map[{{Cos[\[Alpha]],-Sin[\[Alpha]]},{Sin[\[Alpha]], Cos[\[Alpha]]}}.(#-p3)*scale+p1&,line2,{2}], Point[pt_]:> Point[({{Cos[\[Alpha]],-Sin[\[Alpha]]},{Sin[\[Alpha]], Cos[\[Alpha]]}}.(pt-p3)*scale+p1)]}]; (*LineTransform code explained: With two arguments: LineTransform[initialImage_, replacement_]. First we make sure that all line segments stand alone in the form of Line[{p1,p2}]. This is done by (N at initialImage/.line1:Line[{_,_,__}]:>Map[Line,Partition[First at line1,2,1]])