Skip to main content
Replaced blacklisted 'hexagon' tag with 'hexagonal-grid'
Source Link

I'm setting up a hex grid. The column/row system I use puts 0, 0 as the top left corner, and increasing columns (x) moves to the right but also vertically upwards. So columns run straight up and down, but rows run to the right but slanted upwards a bit.

This code...

for (j = 0; j < bd*2-1; j += 1) // bd is "board dimension", in my case 9
{
  for (i = 0; i < bd*2-1 and i < j+bd; i += 1)
  {
    if (i <= j-bd)
      continue;

    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs); // bxo and byo are arbitrary board x/y origins where the first cell is drawn, hs, hh, and vs are the gaps between cells in horizontal and vertical directions.
  }
}

produced this:

enter image description here

which is exactly what iI want, a large hexagon with 9 smaller hexagons on each side.

So iI thought iI would be sophisticated and move that continue condition into the for loop. I wrote this...

for (j = 0; j < bd*2-1; j += 1)
{
  for (i = 0; i < bd*2-1 and i < j+bd and i > j-bd; i += 1) // added "i > j-bd", basically migrated the condition into this inner loop
  {
    //if (i <= j-bd)
      //continue;
    
    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs);
  }
}

and it produced this:

enter image description here

What went wrong here? I thought they were logically equivalent (except negating the condition, cuzbecause the continue code was like a do until, but the for condition is like a do while).

I'm setting up a hex grid. The column/row system I use puts 0, 0 as the top left corner, and increasing columns (x) moves to the right but also vertically upwards. So columns run straight up and down, but rows run to the right but slanted upwards a bit.

This code...

for (j = 0; j < bd*2-1; j += 1) // bd is "board dimension", in my case 9
{
  for (i = 0; i < bd*2-1 and i < j+bd; i += 1)
  {
    if (i <= j-bd)
      continue;

    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs); // bxo and byo are arbitrary board x/y origins where the first cell is drawn, hs, hh, and vs are the gaps between cells in horizontal and vertical directions.
  }
}

produced this:

enter image description here

which is exactly what i want, a large hexagon with 9 smaller hexagons on each side.

So i thought i would be sophisticated and move that continue condition into the for loop. I wrote this...

for (j = 0; j < bd*2-1; j += 1)
{
  for (i = 0; i < bd*2-1 and i < j+bd and i > j-bd; i += 1) // added "i > j-bd", basically migrated the condition into this inner loop
  {
    //if (i <= j-bd)
      //continue;
    
    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs);
  }
}

and it produced this:

enter image description here

What went wrong here? I thought they were logically equivalent (except negating the condition, cuz the continue code was like a do until but the for condition is like a do while).

I'm setting up a hex grid. The column/row system I use puts 0, 0 as the top left corner, and increasing columns (x) moves to the right but also vertically upwards. So columns run straight up and down, but rows run to the right but slanted upwards a bit.

This code...

for (j = 0; j < bd*2-1; j += 1) // bd is "board dimension", in my case 9
{
  for (i = 0; i < bd*2-1 and i < j+bd; i += 1)
  {
    if (i <= j-bd)
      continue;

    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs); // bxo and byo are arbitrary board x/y origins where the first cell is drawn, hs, hh, and vs are the gaps between cells in horizontal and vertical directions.
  }
}

produced this:

enter image description here

which is exactly what I want, a large hexagon with 9 smaller hexagons on each side.

So I thought I would be sophisticated and move that continue condition into the for loop. I wrote this...

for (j = 0; j < bd*2-1; j += 1)
{
  for (i = 0; i < bd*2-1 and i < j+bd and i > j-bd; i += 1) // added "i > j-bd", basically migrated the condition into this inner loop
  {
    //if (i <= j-bd)
      //continue;
    
    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs);
  }
}

and it produced this:

enter image description here

What went wrong here? I thought they were logically equivalent (except negating the condition, because the continue code was like a do until, but the for condition is like a do while).

removed the part about the "loop" tag
Source Link

I'm setting up a hex grid. The column/row system I use puts 0, 0 as the top left corner, and increasing columns (x) moves to the right but also vertically upwards. So columns run straight up and down, but rows run to the right but slanted upwards a bit.

This code...

for (j = 0; j < bd*2-1; j += 1) // bd is "board dimension", in my case 9
{
  for (i = 0; i < bd*2-1 and i < j+bd; i += 1)
  {
    if (i <= j-bd)
      continue;

    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs); // bxo and byo are arbitrary board x/y origins where the first cell is drawn, hs, hh, and vs are the gaps between cells in horizontal and vertical directions.
  }
}

produced this:

enter image description here

which is exactly what i want, a large hexagon with 9 smaller hexagons on each side.

So i thought i would be sophisticated and move that continue condition into the for loop. I wrote this...

for (j = 0; j < bd*2-1; j += 1)
{
  for (i = 0; i < bd*2-1 and i < j+bd and i > j-bd; i += 1) // added "i > j-bd", basically migrated the condition into this inner loop
  {
    //if (i <= j-bd)
      //continue;
    
    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs);
  }
}

and it produced this:

enter image description here

What went wrong here? I thought they were logically equivalent (except negating the condition, cuz the continue code was like a do until but the for condition is like a do while).

P.S. Can someone add a "loop" tag? I don't have the rep for it.

I'm setting up a hex grid. The column/row system I use puts 0, 0 as the top left corner, and increasing columns (x) moves to the right but also vertically upwards. So columns run straight up and down, but rows run to the right but slanted upwards a bit.

This code...

for (j = 0; j < bd*2-1; j += 1) // bd is "board dimension", in my case 9
{
  for (i = 0; i < bd*2-1 and i < j+bd; i += 1)
  {
    if (i <= j-bd)
      continue;

    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs); // bxo and byo are arbitrary board x/y origins where the first cell is drawn, hs, hh, and vs are the gaps between cells in horizontal and vertical directions.
  }
}

produced this:

enter image description here

which is exactly what i want, a large hexagon with 9 smaller hexagons on each side.

So i thought i would be sophisticated and move that continue condition into the for loop. I wrote this...

for (j = 0; j < bd*2-1; j += 1)
{
  for (i = 0; i < bd*2-1 and i < j+bd and i > j-bd; i += 1) // added "i > j-bd", basically migrated the condition into this inner loop
  {
    //if (i <= j-bd)
      //continue;
    
    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs);
  }
}

and it produced this:

enter image description here

What went wrong here? I thought they were logically equivalent (except negating the condition, cuz the continue code was like a do until but the for condition is like a do while).

P.S. Can someone add a "loop" tag? I don't have the rep for it.

I'm setting up a hex grid. The column/row system I use puts 0, 0 as the top left corner, and increasing columns (x) moves to the right but also vertically upwards. So columns run straight up and down, but rows run to the right but slanted upwards a bit.

This code...

for (j = 0; j < bd*2-1; j += 1) // bd is "board dimension", in my case 9
{
  for (i = 0; i < bd*2-1 and i < j+bd; i += 1)
  {
    if (i <= j-bd)
      continue;

    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs); // bxo and byo are arbitrary board x/y origins where the first cell is drawn, hs, hh, and vs are the gaps between cells in horizontal and vertical directions.
  }
}

produced this:

enter image description here

which is exactly what i want, a large hexagon with 9 smaller hexagons on each side.

So i thought i would be sophisticated and move that continue condition into the for loop. I wrote this...

for (j = 0; j < bd*2-1; j += 1)
{
  for (i = 0; i < bd*2-1 and i < j+bd and i > j-bd; i += 1) // added "i > j-bd", basically migrated the condition into this inner loop
  {
    //if (i <= j-bd)
      //continue;
    
    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs);
  }
}

and it produced this:

enter image description here

What went wrong here? I thought they were logically equivalent (except negating the condition, cuz the continue code was like a do until but the for condition is like a do while).

added 75 characters in body
Source Link
DrZ214
  • 348
  • 2
  • 14

I'm setting up a hex grid. The column/row system I use puts 0, 0 as the top left corner, and increasing columns (x) moves to the right but also vertically upwards. So columns run straight up and down, but rows run to the right but slanted upwards a bit.

This code...

for (j = 0; j < bd*2-1; j += 1) // bd is "board dimension", in my case 9
{
  for (i = 0; i < bd*2-1 and i < j+bd; i += 1)
  {
    if (i <= j-bd)
      continue;

    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs); // bxo and byo are arbitrary board x/y origins where the first cell is drawn, hs, hh, and vs are the gaps between cells in horizontal and vertical directions.
  }
}

produced this:

enter image description here

which is exactly what i want, a large hexagon with 9 smaller hexagons on each side.

So i thought i would be sophisticated and move that continue condition into the for loop. I wrote this...

for (j = 0; j < bd*2-1; j += 1)
{
  for (i = 0; i < bd*2-1 and i < j+bd and i > j-bd; i += 1) // added "i > j-bd", basically migrated the condition into this inner loop
  {
    //if (i <= j-bd)
      //continue;
    
    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs);
  }
}

and it produced this:

enter image description here

What went wrong here? I thought they were logically equivalent (except negating the condition, cuz the continue code was like a do until but the for condition is like a do while).

P.S. Can someone add a "loop" tag? I don't have the rep for it.

I'm setting up a hex grid. The column/row system I use puts 0, 0 as the top left corner, and increasing columns (x) moves to the right but also vertically upwards. So columns run straight up and down, but rows run to the right but slanted upwards a bit.

This code...

for (j = 0; j < bd*2-1; j += 1) // bd is "board dimension", in my case 9
{
  for (i = 0; i < bd*2-1 and i < j+bd; i += 1)
  {
    if (i <= j-bd)
      continue;

    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs); // bxo and byo are arbitrary board x/y origins where the first cell is drawn, hs, hh, and vs are the gaps between cells in horizontal and vertical directions.
  }
}

produced this:

enter image description here

which is exactly what i want, a large hexagon with 9 smaller hexagons on each side.

So i thought i would be sophisticated and move that continue condition into the for loop. I wrote this...

for (j = 0; j < bd*2-1; j += 1)
{
  for (i = 0; i < bd*2-1 and i < j+bd and i > j-bd; i += 1)
  {
    //if (i <= j-bd)
      //continue;
    
    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs);
  }
}

and it produced this:

enter image description here

What went wrong here? I thought they were logically equivalent (except negating the condition, cuz the continue code was like a do until but the for condition is like a do while).

P.S. Can someone add a "loop" tag? I don't have the rep for it.

I'm setting up a hex grid. The column/row system I use puts 0, 0 as the top left corner, and increasing columns (x) moves to the right but also vertically upwards. So columns run straight up and down, but rows run to the right but slanted upwards a bit.

This code...

for (j = 0; j < bd*2-1; j += 1) // bd is "board dimension", in my case 9
{
  for (i = 0; i < bd*2-1 and i < j+bd; i += 1)
  {
    if (i <= j-bd)
      continue;

    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs); // bxo and byo are arbitrary board x/y origins where the first cell is drawn, hs, hh, and vs are the gaps between cells in horizontal and vertical directions.
  }
}

produced this:

enter image description here

which is exactly what i want, a large hexagon with 9 smaller hexagons on each side.

So i thought i would be sophisticated and move that continue condition into the for loop. I wrote this...

for (j = 0; j < bd*2-1; j += 1)
{
  for (i = 0; i < bd*2-1 and i < j+bd and i > j-bd; i += 1) // added "i > j-bd", basically migrated the condition into this inner loop
  {
    //if (i <= j-bd)
      //continue;
    
    scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs);
  }
}

and it produced this:

enter image description here

What went wrong here? I thought they were logically equivalent (except negating the condition, cuz the continue code was like a do until but the for condition is like a do while).

P.S. Can someone add a "loop" tag? I don't have the rep for it.

Source Link
DrZ214
  • 348
  • 2
  • 14
Loading