[英]How can I draw a line with a variable of width?
#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;
}
這是一個參考屏幕截圖:
如何繪制較粗的線在很大程度上取決於圖形庫提供的內容。 對於這個特定問題,看起來您正在使用教師提供的庫,因此對Stack Overflow的特定幫助將是稀疏的。 咨詢您的教師,或查看課程材料隨附的文檔。
根據您的賦值中的水龍頭管道的位置和用於繪制它的命令,它看起來像drawLine
的最后一個參數是寬度:
obj_num = drawLine(50,50,150,50,5);
如果沒有庫提供的繪制較粗線的方法,則可以始終使用強力方式並簡單地繪制多個相鄰線 。 對於你的任務,你應該繪制四個像素厚的圓柱體壁,因此繪制四條線,每條線的x坐標比前一個更多。
繪制粗線的另一種方法是改為繪制所需厚度的矩形 。 定義一個四像素寬的矩形,然后繪制它。
因此,當您調用drawline函數時,您可以調整高度 ,插入此變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.