gpt4 book ai didi

c++ - 如何画一条宽度可变的线?

转载 作者:行者123 更新时间:2023-11-28 03:30:12 25 4
gpt4 key购买 nike

#include <iostream>
#include <cmath>
#include "graph1.h"

using namespace std;

int main()
{
int diameter = 0;
int height = 0;
double rate = 0;
char repeat = 'y';
int obj_num = 0;

displayGraphics();

obj_num = drawRect(0,0,50,400);
setColor(obj_num,200,200,200);

obj_num = drawRect(0,400,640,79);
setColor(obj_num,71,35,35);

obj_num = drawLine(50,50,150,50,5);
setColor(obj_num,80,80,80);

displayBMP("faucet.bmp",150,12);

do
{
do
{
cout << "Enter the diamater of the cylinder <in inches > 0 but <= 300: ";
cin >> diameter;
if((diameter<0) || (diameter>300))
{
cout << "Incorrect diamater entered; value must be between 1 and 300" << endl;

}
}while((diameter<0) || (diameter>300));

do
{
cout << "Enter the height of the cylinder <in inches > 0 but <= 325: ";
cin >> height;
if((height<0) || (height>325))
{
cout << "Incorrect height entered; value must be between 1 and 325" << endl;
}

}while((height<0) || (height>325));

do
{
cout << "Enter the facet water's rate: <gallons/minute> ";
cin >> rate;
if((rate<0) || (rate>100))
{
cout << "Incorrect rate entered; value must be between 1 and 100" << endl;

}
}while((rate<0) || (rate>100));


//I need to draw the lines here. The graphics window has a faucet that is supposed to fill
//up a cylinder made out of 3 lines. I don't know how to make the lines vary from the users
//input since lines are hard coded with points and all i am receiving is the width for the
//bottom line and the height for the left and right lines.

cout << "Repeat program? (y/n): ";
cin >> repeat;

clearGraphics();

}while ( (repeat == 'y') || (repeat == 'Y') );
return 0;
}

这里有截图供引用: screenshot

最佳答案

如何绘制更粗的线很大程度上取决于您的图形库提供的内容。在这个特定问题的情况下,看起来您正在使用您的讲师提供的库,因此 Stack Overflow 上的具体帮助很少。询问您的讲师,或查看随类(class) Material 提供的文档。

根据任务中水龙头管道的位置和用于绘制它的命令,看起来 drawLine最终参数是宽度:

obj_num = drawLine(50,50,150,50,5);

如果您没有库提供的绘制粗线的方法,您始终可以使用蛮力方法并简单地绘制多条相邻线。对于您的作业,您应该绘制四个像素厚的圆柱壁,因此绘制四条线,每条线的 x 坐标比前一条多一条。

绘制粗线的另一种方法是绘制矩形,这是您想要的粗细。定义一个四像素宽的矩形,然后绘制它。

关于c++ - 如何画一条宽度可变的线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12789258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com