我正在为大学做一个项目,我必须使用gdImage绘制多个项目,我没有以前的编码经验。如果我要绘制一条线并希望多条其他线也以圆形形状进行圆周运动,那么从这一条线使用该代码的有效方法是什么呢?对不起,如果这是非常明显的,谢谢你的帮助
gdImageLine ( gdImage, 50, 0, 250, 250, PocketGreen);
gdImageLine ( gdImage, 100, 0, 250, 250, PocketGreen);
gdImageLine ( gdImage, 150, 0, 250, 250, PocketGreen);
gdImageLine ( gdImage, 200, 0, 250, 250, PocketGreen);
gdImageLine ( gdImage, 250, 0, 250, 250, PocketGreen);
gdImageLine ( gdImage, 300, 0, 250, 250, PocketGreen);
gdImageLine ( gdImage, 350, 0, 250, 250, PocketGreen);
gdImageLine ( gdImage, 400, 0, 250, 250, PocketGreen);
gdImageLine ( gdImage, 450, 0, 250, 250, PocketGreen);
gdImageLine ( gdImage, 500, 0, 250, 250, PocketGreen);
答案 0 :(得分:0)
您是否意味着要将其压缩为更少的代码行?如果是这样,您可以使用for循环作为每行代码之间变化的唯一值是gdImageLine的第二个参数,每行增加50。这应该可以解决问题。
int j = 50; /* For increasing the second parameter of gdImageLine. */
int numberOfIterations = 10;
for (int i = 0; i < numberOfIterations; i++)
{
gdImageLine( gdImage, j, 0, 250, 250, PocketGreen);
j += 50; /* Increase j by 50 each iteration. */
}