Results 1 to 5 of 5

Thread: Honeycomb Algorithm

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    21

    Honeycomb Algorithm

    Since this pertains to both VB and maths, I'll post it here too, I might even get a better response :P



    Here's three screenshots from a program I'm making, n=1, n=2 and n=3. You can see where it's going. With n=1 only one tile is selected, n=2 all the surrounding tiles, n=3 all the surround tiles of those tiles.

    At the moment it's I just typed in a big mofo 'If' statement for the purposes of showing what it's supposed to do. What I need to do is work out some kind of algorithm that can do this automatically.

    If anybody can help me out with this I'd greatly appreciate it.

    VB source code can be found at http://bloody-cherry.com/math.zip

  2. #2
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    OK, this is not a full algorithm, but at least a good start.

    when n=0, don't do anything, when n=1, then fill in the tile.

    when n=2 then:
    origTile = tile that was previously filled in
    also fill in:
    origTile+9 'one below
    origTile-9 'one above
    origTile-5 'top left
    origTile-4 'top right
    origTile-5 'bottom left
    origTile-4 'bottom right
    obviously check those tiles exist first.

    when n=3, insert all the previous tiles (from when n=2) into the same function. This is actually quite innefficient though as lots of points are being filled in lots of times. also you'll have to see that the colouring in of the tiles doesn't go from one side to other, eg if h=13 and n=2 then 8 and 26 shouldn't be filled in. Not quite sure how to do that.
    Have I helped you? Please Rate my posts.

  3. #3
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860
    Does this picture make it clearer? Select the 2 next columns in the the rows above and below, and the same column in the rows 2 above and 2 below.
    Attached Images Attached Images  
    Don't pay attention to this signature, it's contradictory.

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    or a simpler way generate the tile numbers on the fly...

    VB Code:
    1. 'this array generated as per width of grid
    2. Dim directions(5) As Integer = {LEFTUP, LEFTDOWN, DOWN, RIGHTDOWN, RIGHTUP, UP}
    3. 'this array deals with the spiralling effect
    4. dim modifier(5) as integer = {-1, 0, 0, 0, 0, 0)
    5.  
    6. 'this sub assumes that each tile object has a flag marking it as either lit up or not.
    7. Sub FlagTiles(ByVal h As Integer)
    8.     Dim k, i, j, count As Integer
    9.  
    10.     count = h + UP
    11.     highlight(count)    'always move 1 square up to start with and then continue spiral
    12.     For k = 0 To n  'how big your group of tiles will be
    13.         For i = 0 To 5     'the 6 sides of the hexagon group
    14.             For j = 1 To (k + modifier(i))      'how many tiles on a particular side
    15.                 count += directions(i)           'jump to next square
    16.                 tile(count).litUp = True             'light it up!
    17.             Next j
    18.         Next i
    19.     Next k
    20.  
    21. End Sub

    It should work when h is in the middle of the board but not at the edge. You'll have to modify it to detect the edge of the board.

    I haven't tested this code but it should set you off in the right direction. It seems pretty close to me.

    Please let me know how you get on.
    Last edited by wossname; May 5th, 2004 at 10:26 AM.
    I don't live here any more.

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Any luck yet?
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width