Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我必须通过在彼此的顶部绘制三个单像素正方形来递归地绘制一个谢尔宾斯基三角形以形成一个三角形。他告诉我们,我假设这将是我的递归基本情况,“绘图算法将以屏幕正方形区域的坐标作为输入。如果该正方形是单个 pizel 的大小,它应该调用 drawRect( ) 在传递给 paintComponent 的对象上,在屏幕某处绘制一个 1 像素的正方形。”
如何确定屏幕的正方形区域是否为单个像素的大小?当我调用该方法并执行 width^2. 如果面积为 1,这是否意味着它的 1 个像素?
如果出现以下情况,正方形(或者可能是Rectangle)的大小为 1 个像素:
Rectangle
java.awt.Rectangle rect; // .... boolean isOnePixel = (rect.width == 1 && rect.height == 1);
为了简化事情,我们假设 witdh 和 height 不能为负数。 尽管 Java 矩形类允许这样做。