MathGroup Archive 2007

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

Search the Archive

Re: converting function from RasterArray to Raster

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81876] Re: converting function from RasterArray to Raster
  • From: Jun-Sok Huhh <anarinsk at gmail.com>
  • Date: Fri, 5 Oct 2007 04:57:27 -0400 (EDT)

I've just tested randomWalker. It worked fine with MATHEMATICA 6. RasterArray is automatically translated to Raster. 

Actually, there is one error in your uploaded code. 

randomWalkers[n_, p_, g_, m_, s_, r_, t _] :=

"t _" has made non-functionality for me. "t_" worked fine. 


> Hi,
> 
> I am new to mathematica and trying to convert a call
> to RasterArray to
> Raster in Mathematica 6.0.  The old function, which
> used to work with
> RasterArray was:
> 
> m = Max[First[results]];
> Show[GraphicsRow[(Graphics[
>       RasterArray[Map[
> If[#1 === 0, GrayLevel[1],
> evel[1], GrayLevel[#1[[2]]/m]] &, #1, {2}]],
> AspectRatio -> Automatic] &) /@
> ] &) /@ {First[results],
>     Last[results]}]]
> 
> 
> Simply substituting RasterArray by Raster won't do
> the trick, but the
> debugger doesn't catch a syntatic problem.  Any
> thoughts on how to get
> the function to work with Raster would be
> appreciated.
> 
> Ricardo
> Duke University
> PS - By the way, the full code (which actually came
> from the
> Simulating Society book by Gaylord) is below:
> 
> 
> randomWalkers[n_, p_, g_, m_, s_, r_, t _] :=
> Module[{society, RND, k, walk, GN}, RND :=
> := RandomInteger[{1, 4}];
>    k = 0; society =
> Table[Floor[p + RandomReal[]], {n}, {n}] /.1 :>
> 1 :> {RND, ++k,
> Floor[g + RandomReal[]], RandomInteger[{1, m},
> {1, m}, s],
>        RandomInteger[{0, r}]};
> walk[{l, a___}, 0, _, _, _, {4, ___}, _, _, _, _,
> _, _, _, _] := {RND,
>       a}; walk[{l, a___},
> 0, _, _, _, _, _, _, {2, ___}, _, _, _, _] :=
> _] := {RND, a};
> walk[{l, a___}, 0, _, _, _, _, _, _, _, {3, ___},
> _}, _, _, _] := {RND,
> a}; walk[{l, a___}, 0, _, _, _, _, _, _, _, _,
> _, _, _, _, _] := 0;
> walk[{2, a___}, _, 0, _, _, {3, ___}, _, _, _, _,
> _, _, _, _] := {RND,
>       a}; walk[{2, a___}, _,
> 0, _, _, _, {1 ___}, _, _, _, _, _, _] := {RND,
> {RND, a};
> walk[{2, a___}, _, 0, _, _, _, _, _, _, _, {4,
> {4, ___}, _, _] := {RND,
> a}; walk[{2, a___}, _, 0, _, _, _, _, _, _, _,
> _, _, _, _, _] := 0;
> walk[{3, a___}, _, _, 0, _, _, {4, ___}, _, _, _,
> _, _, _, _] := {RND,
>       a}; walk[{3, a___}, _, _,
> 0, _, _, _, {2, ___}, _, _, _, _, _] := {RND,
> {RND, a};
> walk[{3, a___}, _, _, 0, _, _, _, _, _, _, _, {1,
> {1, ___}, _] := {RND,
> a}; walk[{3, a___}, _, _, 0, _, _, _, _, _, _,
> _, _, _, _, _] := 0;
> walk[{4, a___}, _, _, _, 0, _, _, {1, ___}, _, _,
> _, _, _, _] := {RND,
>       a}; walk[{4, a___}, _, _, _,
>      0, _, _, _, {3, ___}, _, _, _, _] := {RND, a};
> walk[{4, a___}, _, _, _, 0, _, _, _, _, _, _, _,
> _, {2, ___}] := {RND,
> a}; walk[{4, a___}, _, _, _, 0, _, _, _, _, _,
> _, _, _, _, _] := 0;
> walk[{_, a___}, _, _, _, _, _, _, _, _, _, _, _,
> _, _] := {RND, a};
> walk[0, {3, ___}, {4, ___}, _, _, _, _, _, _, _,
> _, _, _, _] := 0;
> walk[0, {3, ___}, _, {1, ___}, _, _, _, _, _, _,
> _, _, _, _] := 0;
> walk[0, {3, ___}, _, _, {2, ___}, _, _, _, _, _,
> _, _, _, _] := 0;
> walk[0, _, {4, ___}, {1, ___}, _, _, _, _, _, _,
> _, _, _, _] := 0;
> walk[0, _, {4, ___}, _, {2, ___}, _, _, _, _, _,
> _, _, _, _] := 0;
> walk[0, _, _, {1, ___}, {2, ___}, _, _, _, _, _,
> _, _, _, _] := 0;
> walk[0, {3, a___}, _, _, _, _, _, _, _, _, _, _,
> _, _] := {RND, a};
> walk[0, _, {4, a___}, _, _, _, _, _, _, _, _, _,
> _, _] := {RND, a};
> walk[0, _, _, {1, a___}, _, _, _, _, _, _, _, _,
> _, _] := {RND, a};
> walk[0, _, _, _. {2, a___}, _, _, _, _, _, _, _,
> _, _] := {RND, a};
>    walk[0, _, _, _, _, _, _, _, _, _, _, _, _] := 0;
>    GN[func_, lat_] :=
>     MapThread[
> func, (RotateRight[lat, #1] &) /@ {{0, 0}, {1,
> , {1, 0}, {0, -1}, {-1,
> 0}, {0, 1}, {1, -1}, {-1, -1}, {-1, 1}, {1,
> 1}, {1, 1}, {2,
>         0}, {0, -2}, {-2, 0}, {0, 2}}, 2];
>    NestList[GN[walk, #1] &, society, t]];
> 
> SeedRandom[2];
> results = randomWalkers[100, 0.65, 1, 1, 1, 1,
> 10000];
>


  • Prev by Date: What is the purpose of the Defer Command?
  • Next by Date: Re: problem with contourplot
  • Previous by thread: Re: converting function from RasterArray to Raster
  • Next by thread: Re: Re: converting function from RasterArray to Raster