Hexフィールド
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) ;
}
}
}
Author And Source
この問題について(Hexフィールド), 我々は、より多くの情報をここで見つけました https://qiita.com/HanageBatake/items/5699dd20e56aeb8a8310著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .