Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg81747] Re: converting function from RasterArray to Raster
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Wed, 3 Oct 2007 02:19:05 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <fdt2j7$rc5$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de

Hi,

a) your randomWalkers[] function is wrong, because you have mixed up the 
letter "l" (ell) and the number 1 (one)
b)

m = Max[First[results]];
Show[GraphicsRow[(Graphics[
       Raster[Map[If[#1 === 0, 1, #1[[2]]/m] &, #1, {2}],
        ColorFunction -> GrayLevel],
       AspectRatio -> Automatic] &) /@ {First[results],
     Last[results]}]]

should do the job.

Regards
   Jens

Ricardo Pietrobon wrote:
> 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], 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 :> {RND, ++k,
>        Floor[g + RandomReal[]], RandomInteger[{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, a};
>    walk[{2, a___}, _, 0, _, _, _, _, _, _, _, {4, ___}, _, _] := {RND,
>       a}; walk[{2, a___}, _, 0, _, _, _, _, _, _, _, _, _, _] := 0;
>    walk[{3, a___}, _, _, 0, _, _, {4, ___}, _, _, _, _, _, _] := {RND,
>       a}; walk[{3, a___}, _, _,
>      0, _, _, _, {2, ___}, _, _, _, _, _] := {RND, a};
>    walk[{3, a___}, _, _, 0, _, _, _, _, _, _, _, {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, 0}, {0, -1}, {-1,
>         0}, {0, 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: Re: Equivalent functionality to colorbar in Mathematica?
  • Next by Date: Interpolating Functions
  • Previous by thread: converting function from RasterArray to Raster
  • Next by thread: Re: converting function from RasterArray to Raster