當前位置:首頁 » 編程語言 » c語言扇形畫法
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言扇形畫法

發布時間: 2022-05-04 22:53:01

⑴ 用C或者C++實現圖形方法。

這個要調用到圖形庫頭文件#include<graphic.h>,,但是要先安裝EasyX插件,因為VC沒有這個庫,TC有,下載那個之後然後網上有很多教你用c語言畫圖的,比如:
OLORREF getpixel(int x, int y); // 獲取點的顏色
void putpixel(int x, int y, COLORREF color); // 畫點

void moveto(int x, int y); // 移動當前點(絕對坐標)
void moverel(int dx, int dy); // 移動當前點(相對坐標)

void line(int x1, int y1, int x2, int y2); // 畫線
void linerel(int dx, int dy); // 畫線(至相對坐標)
void lineto(int x, int y); // 畫線(至絕對坐標)

void rectangle(int left, int top, int right, int bottom); // 畫矩形

void getarccoords(int *px, int *py, int *pxstart, int *pystart, int *pxend, int *pyend); // 獲取圓弧坐標信息
void arc(int x, int y, int stangle, int endangle, int radius); // 畫圓弧
void circle(int x, int y, int radius); // 畫圓
void pieslice(int x, int y, int stangle, int endangle, int radius); // 畫填充圓扇形
void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius);// 畫橢圓弧線
void fillellipse(int x, int y, int xradius, int yradius); // 畫填充橢圓
void sector(int x, int y, int stangle, int endangle, int xradius, int yradius); // 畫填充橢圓扇形

void bar(int left, int top, int right, int bottom); // 畫無邊框填充矩形
void bar3d(int left, int top, int right, int bottom, int depth, bool topflag); // 畫有邊框三維填充矩形

void drawpoly(int numpoints, const int *polypoints); // 畫多邊形
void fillpoly(int numpoints, const int *polypoints); // 畫填充的多邊形
void floodfill(int x, int y, int border); // 填充區域

⑵ TC2.0中用C語言語句畫圖應該用什麼函數

要#include<graphic.h>
// 繪圖函數

COLORREF getpixel(int x, int y); // 獲取點的顏色
void putpixel(int x, int y, COLORREF color); // 畫點

void moveto(int x, int y); // 移動當前點(絕對坐標)
void moverel(int dx, int dy); // 移動當前點(相對坐標)

void line(int x1, int y1, int x2, int y2); // 畫線
void linerel(int dx, int dy); // 畫線(至相對坐標)
void lineto(int x, int y); // 畫線(至絕對坐標)

void rectangle(int left, int top, int right, int bottom); // 畫矩形

void getarccoords(int *px, int *py, int *pxstart, int *pystart, int *pxend, int *pyend); // 獲取圓弧坐標信息
void arc(int x, int y, int stangle, int endangle, int radius); // 畫圓弧
void circle(int x, int y, int radius); // 畫圓
void pieslice(int x, int y, int stangle, int endangle, int radius); // 畫填充圓扇形
void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius);// 畫橢圓弧線
void fillellipse(int x, int y, int xradius, int yradius); // 畫填充橢圓
void sector(int x, int y, int stangle, int endangle, int xradius, int yradius); // 畫填充橢圓扇形

void bar(int left, int top, int right, int bottom); // 畫無邊框填充矩形
void bar3d(int left, int top, int right, int bottom, int depth, bool topflag); // 畫有邊框三維填充矩形

void drawpoly(int numpoints, const int *polypoints); // 畫多邊形
void fillpoly(int numpoints, const int *polypoints); // 畫填充的多邊形
void floodfill(int x, int y, int border); // 填充區域

⑶ 如何利用c語言程序設計繪制一個形狀(圓,橢圓,矩形都可以),用線條動態地填充其內部

你的c 編譯器需帶 繪圖函數庫 才行。
c++ API 程序 可以繪圖。只要得到窗口句柄,就可在該窗畫圖。畫直線,多邊形,圓,橢圓,扇形 等 都是基本函數。
下面程序在桌面窗口畫線:
#include <Afxwin.h>
#include <Windows.h>
#pragma comment (lib, "User32.lib")
int main(void){
HWND hWnd = ::GetDesktopWindow();
HDC hdc = ::GetDC(hWnd);
// HDC hdc = ::GetDC(NULL);
RECT rect;
::GetWindowRect(hWnd, &rect);
::MoveToEx(hdc, 0, 0, NULL);
::LineTo(hdc, rect.right, rect.bottom);
::MoveToEx(hdc, rect.right, 0, NULL);
::LineTo(hdc, 0, rect.bottom);
::ReleaseDC(hWnd, hdc);
system("PAUSE");
return 0;
}
===
用「刷子」畫填充的封閉圖形 (參數是 花紋,顏色)
HBRUSH Brush[5];
case WM_PAINT:
Brush[0] = CreateHatchBrush(HS_BDIAGONAL, RGB(0, 0, 255));
Brush[1] = CreateHatchBrush(HS_CROSS, RGB(200, 0, 0));
Brush[2] = CreateHatchBrush(HS_DIAGCROSS, RGB(0, 128, 0));
Brush[3] = CreateHatchBrush(HS_FDIAGONAL, RGB(0, 128, 192));
Brush[4] = CreateHatchBrush(HS_DIAGCROSS, RGB(255, 128, 0));
----
編譯器 MS VC++ 6.0.
API 程序羅嗦,這里就不列出來了。

⑷ C語言:通過輸入扇形半徑和圓心角度數求扇形面積和弧長

#include <stdio.h>
int main(){
float s,l,a,r;
printf("請輸入扇形半徑r和圓心角a(r,a):");
scanf("%f,%f",&r,&a);
s=0.5*a*r*r;
l=a*r;
printf("s=%.2f,l=%.2f\n",s,l);
return 0;
}

⑸ 懸賞100大洋,我全部身價,求C語言畫圖

TC中才有C語言的圖形庫VC中沒有。。
要#include<graphic.h>
// 繪圖函數

COLORREF getpixel(int x, int y); // 獲取點的顏色
void putpixel(int x, int y, COLORREF color); // 畫點

void moveto(int x, int y); // 移動當前點(絕對坐標)
void moverel(int dx, int dy); // 移動當前點(相對坐標)

void line(int x1, int y1, int x2, int y2); // 畫線
void linerel(int dx, int dy); // 畫線(至相對坐標)
void lineto(int x, int y); // 畫線(至絕對坐標)

void rectangle(int left, int top, int right, int bottom); // 畫矩形

void getarccoords(int *px, int *py, int *pxstart, int *pystart, int *pxend, int *pyend); // 獲取圓弧坐標信息
void arc(int x, int y, int stangle, int endangle, int radius); // 畫圓弧
void circle(int x, int y, int radius); // 畫圓
void pieslice(int x, int y, int stangle, int endangle, int radius); // 畫填充圓扇形
void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius);// 畫橢圓弧線
void fillellipse(int x, int y, int xradius, int yradius); // 畫填充橢圓
void sector(int x, int y, int stangle, int endangle, int xradius, int yradius); // 畫填充橢圓扇形

void bar(int left, int top, int right, int bottom); // 畫無邊框填充矩形
void bar3d(int left, int top, int right, int bottom, int depth, bool topflag); // 畫有邊框三維填充矩形

void drawpoly(int numpoints, const int *polypoints); // 畫多邊形
void fillpoly(int numpoints, const int *polypoints); // 畫填充的多邊形
void floodfill(int x, int y, int border); // 填充區域

⑹ c語言 繪制餅圖

#include <math.h>
#include <graphics.h>
#define PI 3.141593
main ()
{
char s[30];
float values[4]={19,26,33,22};
char *categories[10]={"1","2","3","4","5","6","7","8","9","10"};
char *name[4]={"IBM","HP","COMPAQ","DELL"};
double x,y,bega,enda,midangle;
float total;
int radius,begangle,endangle;
int i,graphdriver,graphmode;
graphdriver=DETECT;
initgraph(&graphdriver,&graphmode,"");
cleardevice();
setviewport(10,10,639,479,1);
setcolor(GREEN);
rectangle(20,20,600,460);
total=0;
for(i=0;i<=3;i++) total+=values[i];
begangle=0;
radius=140;
rectangle(530,40,590,115);
for(i=0;i<=3;i++)
{
endangle=360*values[i]/total+begangle;
bega=begangle*PI/180;
enda=endangle*PI/180;
midangle=(bega+enda)/2;
x=300+cos(midangle)*radius*1.5;
y=240-sin(midangle)*radius*1.2;
sprintf(s,"%3.2f",values[i]/total*100);
setcolor(WHITE);
setfillstyle(1,i+2);
pieslice(300,240,begangle,endangle+2,radius);
outtextxy(x,y,s);
outtextxy(x,y-20,name[i]);
rectangle(540,55+12*i,560,60+12*i);
floodfill(550,57+12*i,WHITE);
outtextxy(565,57+12*i,categories[i]);
begangle=endangle;
}
getch();
closegraph();
}

⑺ 高分求c語言課設 圖形旋轉問題

#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>

#define PI 3.1415926
int s_x1=150,s_y1=150,s_x2=150,s_y2=250,s_x3=250,s_y3=250,s_x4=250,s_y4=150;
int s_centerx=200,s_centery=200;

int t_x1=200,t_y1=150,t_x2=245,t_y2=245,t_x3=155,t_y3=245;
int t_centerx=200,t_centery=210;

int f_centerx=150,f_centery=250,f_sa=60,f_ea=120,radius=50;
int f_x1=125,f_y1=207,f_x2=175,f_y2=207;
void drawSquare()
{
line(s_x1,s_y1,s_x2,s_y2);
line(s_x2,s_y2,s_x3,s_y3);
line(s_x3,s_y3,s_x4,s_y4);
line(s_x4,s_y4,s_x1,s_y1);
}
void drawTriangle()
{
line(t_x1,t_y1,t_x2,t_y2);
line(t_x2,t_y2,t_x3,t_y3);
line(t_x3,t_y3,t_x1,t_y1);
}
void drawFan()
{
arc(f_centerx,f_centery,f_sa,f_ea,radius);
line(f_x1,f_y1,f_centerx,f_centery);
line(f_x2,f_y2,f_centerx,f_centery);
}
void convert(int *x,int *y,int xc,int yc,double _angle)
{
int xt=*x,yt=*y;
*x=(int)(xc+(xt-xc)*cos(_angle)-(yt-yc)*sin(_angle));
*y=(int)(yc+(yt-yc)*cos(_angle)+(xt-xc)*sin(_angle));
}
void rotate(int angle,int choice)
{
double _angle=angle*PI/180;
if(choice==1)
{
convert(&s_x1,&s_y1,s_centerx,s_centery,_angle);
convert(&s_x2,&s_y2,s_centerx,s_centery,_angle);
convert(&s_x3,&s_y3,s_centerx,s_centery,_angle);
convert(&s_x4,&s_y4,s_centerx,s_centery,_angle);
}
else
{
if (choice==2)
{
convert(&t_x1,&t_y1,t_centerx,t_centery,_angle);
convert(&t_x2,&t_y2,t_centerx,t_centery,_angle);
convert(&t_x3,&t_y3,t_centerx,t_centery,_angle);
}
else
{
convert(&f_x1,&f_y1,f_centerx,f_centery,_angle);
convert(&f_x2,&f_y2,f_centerx,f_centery,_angle);
f_sa-=angle,f_ea-=angle;
}
}
}
int main()
{
int graphdriver = DETECT, graphmode;
int choice,angle;
initgraph(&graphdriver, &graphmode, "..\\bgi");

printf("*******************\n");
printf("1 draw square\n");
printf("2 draw triangle\n");
printf("3 draw fan\n");
printf("4 exit\n");
printf("*******************\n");
printf("please input a number to select your operation\n");
scanf("%d",&choice);
switch (choice)
{
case 1:drawSquare();break;
case 2:drawTriangle();break;
case 3:drawFan();break;
default: {closegraph();return 0;}
}
printf("please input a number(between 0 and 360) to rotate\n");
scanf("%d",&angle);
rotate(angle,choice);
switch (choice)
{
case 1:drawSquare();break;
case 2:drawTriangle();break;
case 3:drawFan();break;
}
getch();
return 0;
}
程序如上,我已經運行過了,可以運行,有問題我可以傳給你源文件,和上面的也是一樣。

⑻ c語言程序設計

難啊

⑼ 程序設計 圖形動畫設計 最好是C語言編程的(vb也行)

用VB很容易。無非就是按下個按鈕就在後台執行一段簡單的繪圖代碼。

碰壁那個的話,也不難,注意下圓自身的半徑,還有注意判斷邊界條件即可。