当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。