Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Hexagonal Grid
- lightning3105
-
5 posts
Hexagonal Grid
Hello All!
I am trying to create a turn based game were the ‘board’ is made up of hexagons, similar to the board game settlers of Catan or one of the civilisation games. I am using stamps to stamp out different colored hexagons on the board. Unfortunately, I soon remembered that creating a grid of hexagons is quite hard and needs a lot of math. That is what I am stuck on.
I need help creation the logic for a hexagon stamper sprite that creates a grid of hexagons, like this:

Thank you!
I am trying to create a turn based game were the ‘board’ is made up of hexagons, similar to the board game settlers of Catan or one of the civilisation games. I am using stamps to stamp out different colored hexagons on the board. Unfortunately, I soon remembered that creating a grid of hexagons is quite hard and needs a lot of math. That is what I am stuck on.
I need help creation the logic for a hexagon stamper sprite that creates a grid of hexagons, like this:

Thank you!
- turkey3
-
1000+ posts
Hexagonal Grid
Well, judging by what I see, to stamp the hexagon grids start on the top-left, and just move down and stamp. Then, you move over a column, and stamp half way between the top-left hexagon. And those two columns' patterns repeat.

- bloxxer
-
100+ posts
Hexagonal Grid
hey thats epic if he runs out scripts at the same time he has a stamped hexagon field! Here!
http://scratch.mit.edu/projects/11034107/
See inside to understand how it works!
Hope it helps!
Last edited by bloxxer (June 23, 2013 13:50:36)
- ProdigyZeta7
-
1000+ posts
Hexagonal Grid
Hexagonal Grid, you say? Hmm…
I think this pseudocode works… If not, I failed. lol
EDIT: I did fail. But this time I fixed it.
EDIT2: If this is too advanced for you, then you may use this.
function DrawHexGrid(HexSize);
size = HexSize;
var hex_length = 1.5 * size;
var hex_height = size * (sqrt 3);
var y = size * (height_of_grid/-2);
for (var count1 = 1; count1 < height_of_grid; count1++)
{
var x = size * (length_of_grid/-2);
for (var count2 = 1; count2 < length_of_grid+1; count2++)
{
for (var Φ = -30; Φ != 330; Φ+=60)
{
go to x: x + (size * sin (Φ)) y: y + (size * cos (Φ)) - (hex_height * (count1-1 mod 2));
pen down;
}
pen up;
x = x + hex_length;
}
y = y + hex_height;
}
EDIT: I did fail. But this time I fixed it.

EDIT2: If this is too advanced for you, then you may use this.

Last edited by ProdigyZeta7 (June 23, 2013 17:55:02)
- drmcw
-
1000+ posts
Hexagonal Grid
These are nice projects. I think I'd go the pen route but put the code in a custom block and turn off screen refresh and you should get instant screen updates.
- -Jie-
-
13 posts
Hexagonal Grid
I know this is quite old, but I'm working on a simulator thing and I've shared a project with different tools for hexagonal grids:
http://scratch.mit.edu/projects/24148560/
http://scratch.mit.edu/projects/24148560/
- deck26
-
1000+ posts
Hexagonal Grid
No need to necropost to say that though. You've just moved a very old topic back to the top of the forum and knocked someone needing help off the top page. this was really helpful
- Discussion Forums
- » Help with Scripts
-
» Hexagonal Grid