當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


C語言 setlinestyle()用法及代碼示例


頭文件graphics.h包含setlinestyle()函數,該函數設置由line,lineto,矩形,drawpoly等繪製的所有線條的樣式。

用法:

void setlinestyle(int linestyle, unsigned upattern,
                                   int thickness);

例子:


Input:x = 200, y = 100
Output:

x and y are initialized as (200, 100). 
For every line, value of y increments 
by 25 to change the position. 
The line style keep changing corresponding
to value of first parameter(c). 

說明:線型指定將在幾種樣式中的哪一種中繪製後續線條(例如實線,點線,居中,虛線)。

升級是16位模式,僅當線型為USERBIT_LINE(4)時適用。在這種情況下,每當模式字中的一位為1時,該行中的相應像素就會以當前繪製顏色進行繪製。必須始終提供“ upattern”的值。如果“ linestyle”不是USERBIT_LINE(4),則會被忽略。
厚度指定繪製的後續線條的寬度是正常還是粗線。

下麵是setlinestyle()函數的實現:

// C Implementation for setlinestyle() 
#include <graphics.h> 
  
// driver code 
int main() 
{ 
    // gm is Graphics mode which is 
    // a computer display mode that 
    // generates image using pixels. 
    // DETECT is a macro defined in 
    // "graphics.h" header file 
    int gd = DETECT, gm; 
  
    // variable to change the 
    // line styles 
    int c; 
  
    // initial coordinate to  
    // draw line 
    int x = 200, y = 100; 
  
    // initgraph initializes the 
    // graphics system by loading a 
    // graphics driver from disk 
    initgraph(&gd, &gm, ""); 
  
    // To keep track of lines 
    for ( c = 0 ; c < 5 ; c++ ) 
   { 
       // setlinestyle function 
       setlinestyle(c, 0, 1); 
  
       // Drawing line 
       line(x, y, x+200, y); 
       y = y + 25; 
   } 
  
    getch(); 
  
    // closegraph function closes the 
    // graphics mode and deallocates 
    // all memory allocated by 
    // graphics system . 
    closegraph(); 
  
    return 0; 
}

輸出:




相關用法


注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 setlinestyle() function in C。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。