0
#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;
}

这是一个截图供参考: 截屏

4

2 回答 2

2

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

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

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

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

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

于 2012-10-08T21:02:08.170 回答
0

所以, 当你调用 drawline 函数时,你有可变的高度,插入这个变量。

于 2012-10-08T20:59:15.140 回答