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

MathGroup Archive 2007

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

Search the Archive

converting function from RasterArray to Raster

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81690] converting function from RasterArray to Raster
  • From: "Ricardo Pietrobon" <pietr007 at gmail.com>
  • Date: Tue, 2 Oct 2007 05:21:38 -0400 (EDT)

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: Simplifying Log[a] + Log[expr_] - Log[2 expr_]: Brute force necessary?
  • Next by Date: Re: Other bug in ContourPlot
  • Previous by thread: Re: Re: Re: Any Mathematica 6 book yet?
  • Next by thread: Re: converting function from RasterArray to Raster