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


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


頭文件graphics.h包含getarccoords()函數,該函數用於獲取最近繪製的弧的坐標。 arccoordstype是預定義的結構,定義如下:

用法:

struct arccoordstype
{
   // center point of arc
   int x, y; 

   // start position                
   int xstart, ystart;

   // end position        
   int xend, yend;    
};

注意:類型為arccoordstype的結構變量的地址傳遞給函數getarccoords。


用法:

void getarccoords(struct arccoordstype *var);

例:

Input:x = 250, y = 200, s_angle = 0 ,
        e_angle = 90, radius = 100
Output:

下麵是getarccoords()函數的實現

// C Implementation for getarccoords() 
#include <graphics.h> 
#include <stdio.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; 
  
    // p is structure variable 
    // of type arccoordstype 
    struct arccoordstype p; 
    char arr[100]; 
  
    // initgraph initializes the 
    // graphics system by loading a 
    // graphics driver from disk 
    initgraph(&gd, &gm, ""); 
  
    // arc function is used to draw an  
    // arc the first 2 arguments are  
    // center of arc  3rd and 4th  
    // arguments are starting and   
    // ending angles. Last argument  
    // is the radius. 
    arc(250, 200, 0, 90, 100); 
  
    // getarccoords function which takes 
    // address of a structure variable of 
    // type arccoordstype as an argument. 
    getarccoords(&p); 
  
    // sprintf stands for “String print”. 
    // Instead of printing on console, it 
    // store output on char buffer which 
    // are specified in sprintf 
    sprintf(arr, "(%d, %d)", p.xstart,  
                             p.ystart); 
  
    // outtext function displays text 
    // at current position. 
    outtextxy(360, 195, arr); 
  
    sprintf(arr, "(%d, %d)", p.xend,  
                            p.yend); 
  
    outtextxy(245, 85, arr); 
  
    getch(); 
  
    // closegraph function closes the 
    // graphics mode and deallocates 
    // all memory allocated by 
    // graphics system . 
    closegraph(); 
  
    return 0; 
}

輸出:




相關用法


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