Archive for October, 2004

17
Oct
04

Artificial Terrain

Here is some Mathematica code to plot the Perlin Noise as an artificial terrain (you must run the code from Perlin Noise before you can run this code):
(* runtime: 10 seconds *)
Gradient2[x_, grad_] := Module[{i = 1, n = Length[grad]}, While[i <= n && grad[[i, 1]] < x, i++]; RGBColor @@ If[1 < i <= n, Module[{x1 = grad[[i - 1, 1]], x2 = grad[[i, 1]]}, ((x2 - x) grad[[i - 1, 2]] + (x - x1)grad[[i, 2]])/(x2 - x1)], grad[[Min[i, n], 2]]]];
EarthTones = {{0, {0, 0.1, 0.24}}, {0.1, {0, 0.6, 0.6}}, {0.1, {0.9, 0.8, 0.6}}, {0.2, {0.5, 0.4, 0.3}}, {0.5, {0.2, 0.3, 0.1}}, {0.8, {0.7, 0.6, 0.4}}, {0.8, {1, 1, 1}}, {1, {1, 1, 1}}};
Show[SurfaceGraphics[Map[Max[#, 1] &, image, {2}], Mesh -> False, Boxed -> False, BoxRatios -> {1, 1, 1/12}, ColorFunction -> (Gradient2[1.3#, EarthTones] &), Background -> RGBColor[0, 0, 0]]];

See also my Terragen terrain.

17
Oct
04

3D Mandelbrot Set

This Mandelbrot fractal was interpolated using Bill Rood’s formula for continuous escape time (cet) as described in the book “The Colours of Infinity”:
cet = n + log2ln(R) – log2ln|z|
(* runtime: 3 seconds *)
R = 6;
image = ParametricPlot3D[Module[{z = 0.0, i = 0}, While[i < 100 && Abs[z] < R^2, z = z^2 + xc + I yc; i++]; cet = If[i != 100, i + (Log[Log[R]] - Log[Log[Abs[z]]])/Log[2], 0]; {xc, yc, 0.5Min[0.1cet, 1], {EdgeForm[], SurfaceColor[Hue[1 - 0.1cet]]}}], {xc, -2.0, 1.0}, {yc, -1.5, 1.5}, PlotPoints -> 64, Boxed -> False, Axes -> False, DisplayFunction -> Identity];
<< MathGL3d`OpenGLViewer`;
MVShow3D[image, MVNewScene -> True];

17
Oct
04

Tree Fractal

Tree Fractal – adapted from from Renan Cabrera’s Mathematica code. This is an example of a bracketed Lindenmayer System (L-System). You can also use this technique to make lightning bolts.
(* runtime: 1 second *)
Polar[{x_, y_}, theta_, r_] := {x + r Cos[theta], y + r Sin[theta]};
branch[x_] := x; branch[tree_List] := branch /@ tree;
branch[Line[{p1_, p2_}]] := Module[{r = Sqrt[(p2[[1]] - p1[[1]])^2 + (p2[[2]] - p1[[2]])^2], theta = ArcTan[p2[[1]] - p1[[1]], p2[[2]] - p1[[2]]]}, {Thickness[0.05r], RGBColor[0.5r, 1 - 0.75r, 0], Line[{p2, Polar[p2, theta - Pi/6, 0.8r]}], Line[{p2, Polar[p2, theta + Pi/4, 0.7r]}]}];
Show[Graphics[{Thickness[0.07], RGBColor[0.5, 0.25, 0], NestList[branch, Line[{{0, 0}, {0, 1}}], 12]}], AspectRatio -> 1, Background -> RGBColor[0, 0, 0], PlotRange -> {{-3, 3}, {0, 6}}];

Links

16
Oct
04

Barnsley’s Fern

Barnsley’s Fern: This is an example of a Directed Graph Iterated Function System (Digraph IFS). The image is generated by randomly selecting transformations which jump to different points on the fern.
(* runtime: 7 seconds *)
n = 275; p = {0, 0}; image = Table[0, {n}, {n}];
Do[x = Random[Integer, 99]; p = Which[x < 3, {{0, 0}, {0, 0.16}}.p,x < 76, {{0.85, 0.04}, {-0.04, 0.85}}.p + {0, 1.6}, x <89, {{0.2, -0.26}, {0.23, 0.22}}.p + {0, 1.6}, True, {{-0.15, 0.28}, {0.26, 0.24}}.p + {0, 0.44}]; image[[Floor[n(p[[1]]/10 + 0.5)] + 1, Floor[n p[[2]]/10] + 1]]++, {100000}];
Show[Graphics[RasterArray[Map[RGBColor[0, 1 - Exp[-0.1#], 0] &, image, {2}]], AspectRatio -> 1]];

Links




Welcome !

You will find here some of my favorite hobbies and interests, especially science and art.

I hope you enjoy it!

Subscribe to the RSS feed to stay informed when I publish something new here.

I would love to hear from you! Please feel free to send me an email : bugman123-at-gmail-dot-com

Archives

Blog Stats

  • 395,427 hits

Follow

Get every new post delivered to your Inbox.