2012-10-08 60 views
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; 
} 

这里是参考截图: screenshot如何绘制宽度变量的线?

回答

0

所以,你必须可变高度 当你调用DrawLine的功能,插上这个变量。

2

如何绘制粗线很大程度上取决于图形库提供的内容。在这个特定问题的情况下,看起来您正在使用由您的教师提供的库,所以对Stack Overflow的具体帮助将很少。询问您的教练,或查看随课程资料一起提供的文档。

根据您指定的水龙头管道和用于绘制它的命令的位置,它看起来像的drawLine最后一个参数是宽度:

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

如果没有库 - 提供绘制较粗线条的方式,您可以随时使用蛮力的方式和简单的绘制多条相邻的线条。对于你的任务,你应该绘制四个像素厚的圆柱体壁,所以绘制四条线,每条线与一个x坐标比前一个更多。

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

相关问题