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

MathGroup Archive 2012

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

Search the Archive

Re: coloring individual hexagons in a grid...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg127889] Re: coloring individual hexagons in a grid...
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Thu, 30 Aug 2012 04:08:46 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <20120828085302.9525568C1@smc.vnet.net>

Hexagon[x_] :=
 Line[x + # & /@
   (Through[{Cos, Sin}[Pi #/3]] & /@
     Range[0, 6])]

HexagonalGrid[nbrRows_, nbrColumns_,
  colorFunction_: Null] :=
 Module[{i, j},
  Table[{
    If[colorFunction === Null,
     Black,
     colorFunction[i, j]],
    Hexagon[
     {3/2 j, Sqrt[3] i + Mod[j, 2] Sqrt[3]/2}]}, {i, nbrRows}, {j,
    nbrColumns}]]

With[{k = 3},
 Show[Graphics[
   HexagonalGrid[k, k]],
  AspectRatio -> Automatic]]

With[{k = 3},
 Show[Graphics[
   HexagonalGrid[k, k, Hue[
      Rescale[#1 + #2, {2, 2 k}]] &],
   AspectRatio -> Automatic]]]


Bob Hanlon


On Tue, Aug 28, 2012 at 4:53 AM, Richard Palmer <rhpalmer at gmail.com> wrote:
>
> I am using the code shown below to draw square hexagonal grids.
>
> Hexagon[x_]:=Line[x+#&/@(Through[{Cos,Sin}[Pi #/3]]&/@Range[0,6])]
>
> HexagonalGrid[x_,y_]:=Module[{i,j},
> Table[Hexagon[{3/2i,Sqrt[3]j+Mod[i,2]Sqrt[3]/2}],{i,x},{j,y}]
> ]
>
> k;
> Show[Graphics[HexagonalGrid[k,k]],
> AspectRatio->Automatic]
>
> How does one assign a color to individual cells in the hex grid?
> --
> Richard Palmer
>
> Home                            941 412 8828
> Cell                               508 982-7266
>
>



  • Prev by Date: Re: Problems obtaining a free c compiler...
  • Next by Date: Re: Landau letter, Re: Mathematica as a New Approach...
  • Previous by thread: coloring individual hexagons in a grid...
  • Next by thread: Re: coloring individual hexagons in a grid...