图形化编程设计案例,c语言 图形编程

1,c语言 图形编程检查一下初始化语句是否正常,如下int graphdriver = DETECT, graphmode;initgraph(&graphdriver, &graphmode, "..\\bgi");【图形化编程设计案例,c语言 图形编程】
2,图形编程例子文件(File)-新建(New)-Win32应用程序(Win32 Application),记得写项目名称(Project name)-确定(OK)-空项目(An empty project)-完成(Finish)-确定(OK)-文件(File)-新建(New)-C++源代码文件(C++ Source File),填文件名-确定(OK)简单的hello world#include <windows.h>int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow )MessageBox ( NULL, "Hello World!", "Hello World APP", MB_OK );return 1;}MFC编程文件(File)-新建(New)-MFC应用程序向导(MFCAppWizard[exe]) , 写项目名称(Project name)-确定(OK)-单文档(Single document)-完成(Finish)-确定(OK)希望对你有用
3,计算机C语言图形编程#include "stdio.h"void main()int i;for(i = 0; i < 6; i++)for(j = 0; j < i; j++) for(j = 0; j <6; j++)printf("\n");}#include "stdio.h"void main()int i,j;for(i = 0; i < 6; i++) for(j = 0; j < i; j++)printf(" "); } for(j = 0; j <6; j++)printf("%d",(j+i)%6+1); } printf("\n");}}#include <stdio.h>void main()int i = 1, j = 0, k;for(i; i < 7; i++)for(j,k = i; j < 6; j++,k++)if(k > 6) k = 1; printf("%d",k);}}
4,c语言计算机图形编程的程序求各种实例并说明一下啊谢谢谢1》DDA法画直线的例子:void CMyView::OnDdaline()CDC* pDC=GetDC();//获得设备指针int xa=100, ya=300, xb=300, yb=200,c=RGB(0,255,0);//定义直线的两端点,直线颜色int x,y;float dx, dy, k;dx=(float)(xb-xa), dy=(float)(yb-ya);k=dy/dx, y=ya;if(abs(k)<1)for (x=xa;x<=xb;x++)y=y+k;}}if(abs(k)>=1)for (y=ya;y<=yb;y++)x=x+1/k;}}ReleaseDC(pDC);}void CMyView::OnBresenhamline() CDC* pDC=GetDC();int x,y,i,e,dx,dy,t;int x1=100,y1=200,x2=350,y2=100,c=RGB(0,0,255);dx=abs(x2-x1),dy=abs(y2-y1),e=2*dy-dx;x=x1,y=y2;if(dx>dy)for(i=0;i<=dx;i++)pDC->SetPixel(x,y,c);x++;if(e>=0)e=e+2*dy-2*dx;}else e=e+dy;} } elset=dx;dx=dy;dy=t;for(i=0;i<=dx;i++)pDC->SetPixel(x,y,c);x++;if(e>=0)e=e+2*dy-2*dx;}else e=e+dy;} }}2》中心画圆法 做园 void CMyView::OnMidpointcircle()int xc=100,int yc=200,float R=50,float alpha=1;int i;float sinalpha,cosalpha,xi,yi,xii,yii,steps;sinalpha=sin(pi*alpha);cosalpha=cos(pi*alpha);xi=xc+R;yi=yc;steps=360;for(i=0;i{ xii=xc+(xi-xc)*cosalpha-(yi-yc)*sinalpha;//确定第一点xii,yii.其与圆心的连线和 xi,yi与圆心的连线夹角45° yii=yc+(xi-xc)*sinalpha+(yi-yc)*cosalpha; pDC->MoveTo(xi,yi); pDC->LineTo(xii,yii); xi=xii; yi=yii; } }3》 bresenham法画圆void CMyView::OnBresenhamcircle() { // TODO: Add your command handler code here CDC* pDC=GetDC(); int xc=300, yc=300, r=40, c=RGB(0,0,255); int x,y,p; x=0,y=r,p=3-2*r; while(x { pDC->SetPixel(xc+x, yc+y, c); pDC->SetPixel(xc-x, yc+y, c); pDC->SetPixel(xc+x, yc-y, c); pDC->SetPixel(xc-x, yc-y, c); pDC->SetPixel(xc+y, yc+x, c); pDC->SetPixel(xc-y, yc+x, c); pDC->SetPixel(xc+y, yc-x, c); pDC->SetPixel(xc-y, yc-x, c); if (p<0) p=p+4*x+6; else { p=p+4*(x-y)+10; y-=1; } x+=1; } if(x==y) pDC->SetPixel(xc+x, yc+y, c); pDC->SetPixel(xc-x, yc+y, c); pDC->SetPixel(xc+x, yc-y, c); pDC->SetPixel(xc-x, yc-y, c); pDC->SetPixel(xc+y, yc+x, c); pDC->SetPixel(xc-y, yc+x, c); pDC->SetPixel(xc+y, yc-x, c); pDC->SetPixel(xc-y, yc-x, c); ReleaseDC(pDC); }与图形相关的还有很多很多,扫描线填充法,种子填充法 等等想要真正了解的话 推荐一本书!《计算机图形学》以上程序只能说明引用方法,毕竟很对关于以上程序的东西 都在自己做的头文件里 。1》dda法画直线的例子:void cmyview::onddaline()cdc* pdc=getdc();//获得设备指针int xa=100, ya=300, xb=300, yb=200,c=rgb(0,255,0);//定义直线的两端点,直线颜色int x,y;float dx, dy, k;dx=(float)(xb-xa), dy=(float)(yb-ya);k=dy/dx, y=ya;if(abs(k)<1)for (x=xa;x<=xb;x++)y=y+k;}}if(abs(k)>=1)for (y=ya;y<=yb;y++)x=x+1/k;}}releasedc(pdc);}void cmyview::onbresenhamline() cdc* pdc=getdc();int x,y,i,e,dx,dy,t;int x1=100,y1=200,x2=350,y2=100,c=rgb(0,0,255);dx=abs(x2-x1),dy=abs(y2-y1),e=2*dy-dx;x=x1,y=y2;if(dx>dy) for(i=0;i<=dx;i++) pdc->setpixel(x,y,c); x++; if(e>=0) e=e+2*dy-2*dx;}else e=e+dy; } } else t=dx; dx=dy; dy=t; for(i=0;i<=dx;i++) pdc->setpixel(x,y,c); x++; if(e>=0) e=e+2*dy-2*dx;}else e=e+dy; } }}2》中心画圆法 做园void cmyview::onmidpointcircle()cdc* pdc=getdc(); int xc=100,int yc=200,float r=50,float alpha=1;int i;float sinalpha,cosalpha,xi,yi,xii,yii,steps;sinalpha=sin(pi*alpha);cosalpha=cos(pi*alpha);xi=xc+r;yi=yc;steps=360;for(i=0;i<steps;i++)//每隔45°确定一个园上的点 。xii=xc+(xi-xc)*cosalpha-(yi-yc)*sinalpha;//确定第一点xii,yii.其与圆心的连线和 xi,yi与圆心的连线夹角45° yii=yc+(xi-xc)*sinalpha+(yi-yc)*cosalpha; pdc->moveto(xi,yi); pdc->lineto(xii,yii); xi=xii; yi=yii;}}3》 bresenham法画圆void cmyview::onbresenhamcircle()// todo: add your command handler code herecdc* pdc=getdc(); int xc=300, yc=300, r=40, c=rgb(0,0,255);int x,y,p;x=0,y=r,p=3-2*r;while(x<y)pdc->setpixel(xc+x, yc+y, c);pdc->setpixel(xc-x, yc+y, c);pdc->setpixel(xc+x, yc-y, c);pdc->setpixel(xc-x, yc-y, c);pdc->setpixel(xc+y, yc+x, c);pdc->setpixel(xc-y, yc+x, c);pdc->setpixel(xc+y, yc-x, c);pdc->setpixel(xc-y, yc-x, c);if (p<0)p=p+4*x+6;elsep=p+4*(x-y)+10;y-=1;} x+=1;}if(x==y)pdc->setpixel(xc+x, yc+y, c);pdc->setpixel(xc-x, yc+y, c);pdc->setpixel(xc+x, yc-y, c);pdc->setpixel(xc-x, yc-y, c);pdc->setpixel(xc+y, yc+x, c);pdc->setpixel(xc-y, yc+x, c);pdc->setpixel(xc+y, yc-x, c);pdc->setpixel(xc-y, yc-x, c);releasedc(pdc);}与图形相关的还有很多很多,扫描线填充法,种子填充法 等等想要真正了解的话 推荐一本书!《计算机图形学》以上程序只能说明引用方法 , 毕竟很对关于以上程序的东西 都在自己做的头文件里 。

    推荐阅读