如何绘制宽度变量的线?

时间:2012-10-08 20:49:53

标签: c++ variables line

#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

2 个答案:

答案 0 :(得分:2)

如何绘制较粗的线在很大程度上取决于图形库提供的内容。对于这个特定问题,看起来您正在使用教师提供的库,因此对Stack Overflow的特定帮助将是稀疏的。咨询您的教师,或查看课程材料随附的文档。

根据您的作业中水龙头管道的位置以及用于绘制它的命令,看起来drawLine最终参数是宽度:

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

如果您没有库提供的绘制较粗线的方法,您可以始终使用强力方式,只需绘制多个相邻线。对于你的任务,你应该绘制四个像素厚的圆柱体壁,因此绘制四条线,每条线的 x 坐标比前一个更多。

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

答案 1 :(得分:0)

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