需要帮助修复绘制六边形的功能

时间:2019-07-17 20:15:30

标签: java

我有一个程序,可以使用加载到其中的图像来绘制六角形的瓷砖。它使用称为inHex()的函数通过用透明像素替换六边形之外的任何像素来创建这些平铺图像。这行得通。

现在,我想在六边形的内边缘上创建一个边框。因此,我修改了inHex()的副本,将&& s更改为|| s,并为平坦边缘添加了两行。问题在于仅绘制了上边界。

我尝试更改语句的顺序,并用单独的if语句替换所有ors,没有骰子。我知道在循环中使用System.out.print行时,hexEdge()不应返回true,除了上面的行。

    public boolean hexEdge(int x, int y)
    {
        /**
         * returns true if the coordinates are inside the hexagon bounded by the width and height of the tile
         */
        double slope = (tileHeight/2.0)/(tileWidth);
        boolean inside=false;
        //check in acordance to sides
        if (x<(tileWidth/2 +1) )
        {
            inside= 
                    ( y == (int)(0.25*tileHeight-slope*x) ) ||//this works
                    ( y == (int)(0.75*tileHeight+slope*x) ) ||
                    (x==0 && y>(int)(0.25*tileHeight) && y<=(int)(0.25*tileHeight) );
        }else {
            int x2=x-tileWidth/2;
            inside =
                    (y == (int)(0+slope*x2) )||//this works
                    (y == (int)(tileHeight -slope*x2 ) )||
                    (x==tileWidth-1 && y>(int)(0.25*tileHeight) && y<=(int)(0.25*tileHeight) );
        }
        return inside;
    }

0 个答案:

没有答案
相关问题