Discuss Scratch

lightning3105
Scratcher
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!
turkey3
Scratcher
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
Scratcher
100+ posts

Hexagonal Grid

Sample Project
Sample for you
dracae
Scratcher
1000+ posts

Hexagonal Grid

Here!
http://scratch.mit.edu/projects/11034107/
See inside to understand how it works!
Hope it helps!

Last edited by dracae (June 23, 2013 13:39:19)

bloxxer
Scratcher
100+ posts

Hexagonal Grid

dracae wrote:

Here!
http://scratch.mit.edu/projects/11034107/
See inside to understand how it works!
Hope it helps!
hey thats epic if he runs out scripts at the same time he has a stamped hexagon field!

Last edited by bloxxer (June 23, 2013 13:50:36)

ProdigyZeta7
Scratcher
1000+ posts

Hexagonal Grid

Hexagonal Grid, you say? Hmm…
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;
}
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.

Last edited by ProdigyZeta7 (June 23, 2013 17:55:02)

drmcw
Scratcher
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.
lightning3105
Scratcher
5 posts

Hexagonal Grid

Thank you all very much!
dracae
Scratcher
1000+ posts

Hexagonal Grid

Glad we could help!
-Jie-
Scratcher
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/
E________________
New Scratcher
2 posts

Hexagonal Grid

this was really helpful
deck26
Scratcher
1000+ posts

Hexagonal Grid

E________________ wrote:

this was really helpful
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.

Powered by DjangoBB