1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Hexフィールド

Posted at

20140928-110138-097.png
20140928-120540-381.png
20140928-110111-397.png
20140928-110146-063.png

Siv3DApp.cpp
# include <Siv3D.hpp>

void Main()
{
  unsigned int mapwidth, mapheight ;
  double cellsize ;
  double cellint ;
  double padding ;

  GUI gui(GUISkin::Default()) ;
  gui.addSlider(L"Height", { 1, 100, 10}) ;

  while (System::Update()) {
    mapheight = gui.slider(L"Height").value ;
    cellsize  = Window::Height() / (0.5 + 1.5 * mapheight) ;
    cellint   = cellsize * sqrt(3) ;
    mapwidth  = (Window::Width() - 0.5 * cellint) / cellint ;
    padding   = (Window::Width() - (cellint * (0.5 + mapwidth + 0.5 * (mapheight == 1)))) / 2 ;

    Polygon hexcell = Geometry::CreateNgon(6, cellsize, 0, {0, 0}) ;
    Vec2 hexpos ;

    for (unsigned int y = 0; y < mapheight; ++y) for (unsigned int x = 0; x < mapwidth; ++x) {
      hexpos = {cellint * (x + 0.5 * (y%2 == 0) + 0.5) + padding, cellsize * (1.5 * y + 1)} ;
      (hexcell + hexpos).draw(Palette::Orange) ;
      (hexcell + hexpos).drawFrame(2.0, Palette::Red) ;
    }
  }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?