用C语言实现画图程序
C语言如何实现画图教程
![C语言如何实现画图教程](https://img.taocdn.com/s3/m/14ecada5cd22bcd126fff705cc17552707225e61.png)
C语言如何实现画图教程C语言如何实现画图教程C语言有丰富的数据结构和运算符。
包含了各种数据结构,如整型、数组类型、指针类型和联合类型等,用来实现各种数据结构的运算。
以下是店铺为大家搜索整理的C语言如何实现画图教程,希望能给大家带来帮助!程序中定义了几个特殊键:"V”:画笔提起"W”:开始画图"R”:开始擦图"S”:当前图形存入文件"E”:调出已有文件"C”:画圆程序一运行,屏幕上出现一个黄色的`边框来设定画图的区域,区域中间出现提起的画笔符号,当按下”W“键时,画笔符号变为,此时可移动方向键(上、下、左、右、左上、左下、右上、右下)来画图;当按下”R“键时,画笔符号变为,此时可移动方向键来擦图;在画图过程中,按下“C”键,可画出一个半径为20个象素点的圆;当结束画图时,按下“S”键,将画好的图形存盘;按下“E”键可调出已有的图形进行编辑。
3.源程序清单# include "graphics.h"# include "stdio.h"# include "fcntl.h"# include "stdlib.h"main()void save(),load();void *wg,*rg,*vg,*fy;int driver,mode;int c=RED;int x=320,y=225;int x1,y1,x2,y2;int k,k1,k2;/* initialize grapher */ detectgraph(&driver,&mode); initgraph(&driver,&mode,"c:\tc");/* write the pen */bar(200,10,206,16);line(203,7,200,10);line(203,7,206,10);line(243,7,240,16);line(243,7,246,16);line(283,7,280,10);line(283,7,286,10);line(283,7,283,16);/* save the pen */wg=malloc(imagesize(200,7,206,16)); rg=malloc(imagesize(240,7,246,16)); vg=malloc(imagesize(280,7,286,16)); fy=malloc(imagesize(200,7,206,16)); getimage(200,7,206,16,wg); getimage(240,7,246,16,rg); getimage(280,7,286,16,vg); cleardevice();/* write the box */setcolor(YELLOW);rectangle(4,19,637,447);x1=x-3;y1=y+1;y2=y+10;getimage(x1,y1,x2,y2,fy);putimage(x1,y1,vg,XOR_PUT);/* receive the command */for (;;)while (bioskey(1)==0);k=bioskey(0);putimage(x1,y1,fy,AND_PUT);if (((k&0x00ff)|0x00)==0)k1=k&0xff?0:k>>8; /* k1 is the specialkey value */ elsek2=k&0x00ff; /* k2 is the non-specialkey value */ if (((k&0x00ff)|0x00)==0) /* Special key */ switch(k1)case 45:restorecrtmode();exit(0);case 72:if (y>20)y=y-1;break;case 75:if (x>5)x=x-1;break;case 77:if (x<636)x=x+1;break;if (y<446)y=y+1;break;case 71:if ((x>5)&&(y>20))x=x-1;y=y-1;break;case 79:if ((x>5)&&(y<446))x=x-1;y=y+1;break;case 73:if ((x<636)&&(y>20))x=x+1;y=y-1;break;case 81:if ((x<636)&&(y<446)) x=x+1;y=y+1;break;x1=x-3;y1=y+1;x2=x+3;y2=y+10;getimage(x1,y1,x2,y2,fy); /* non-special key */case 118: /* 'v' */case 86: /* 'V' */putimage(x1,y1,vg,OR_PUT); break;case 119: /* 'w' */case 87: /* 'W' */putimage(x1,y1,wg,OR_PUT); putpixel(x,y,c);break;case 114: /* 'r' */case 82: /* 'R' */putimage(x1,y1,rg,OR_PUT); putpixel(x,y,BLACK);break;case 115: /* 's' */case 83: /* 'S' */save("pic.dat");break;case 101: /* 'e' */case 69: /* 'E' */load("pic.dat");break;case 99: /*'c'*/case 67: /*'C'*/setcolor(RED);circle(x,y,20);break;default:continue;/* function for screen picture save*/void save(char *fname)FILE *fp;int i;register long j;char far *ptr;fp=fopen(fname,"wb");for(i=0;i<4;i++)outportb(0x3CE,4);outportb(0x3CF,i);ptr=(char far *) 0xA0000000L;for (j=0;j<38400L;j++)putc(*ptr,fp);ptr++;fclose(fp);outportb(0x3CF,0);/* function for screen picture display */void load(char *fname)FILE *fp;register int i;int k4=1;register long j;char far *ptr;fp=fopen(fname,"rb");for (i=0;i<4;i++)outportb(0x3C4,2);outportb(0x3C5,k4);ptr=(char far *)0xA0000000L;for (j=0;j<38400L;j++)*ptr=getc(fp);ptr++;k4*=2;fclose(fp);outportb(0x3C5,0xF);4.结束语该程序在Turbo C 2.0环境下运行通过,使用效果良好。
绘图程序代码,用C#实现
![绘图程序代码,用C#实现](https://img.taocdn.com/s3/m/6986effb770bf78a652954a6.png)
一个很好的绘图程序代码,用C#实现。
using System;using System.IO;//用于文件存取using System.Data;//用于数据访问using System.Drawing;//提供画GDI+图形的基本功能using System.Drawing.Text;//提供画GDI+图形的高级功能using System.Drawing.Drawing2D;//提供画高级二维,矢量图形功能using System.Drawing.Imaging;//提供画GDI+图形的高级功能namespace Drawpicture{/// <summary>/// BarChart 的摘要说明。
/// </summary>public class BarChart{private int Pic_Width = 410;private int Pic_Height = 320;public static bool hasNeg = false;private const string FontWord = \"Arial\";private const int FontSize = 9;public int SIDE_WIDTH = 400;public int SIDE_HEIGHT = 400;private const int CHART_TOP = 60;private int CHART_HEIGHT = 300;private const int CHART_LEFT = 60;private const int CHART_WIDTH = 300;public void Render(string[] word,int[] data, out string fileName) {for(int i=0;i<data.Length;i++){if(data[i]<0){Pic_Height *=2;hasNeg = true;SIDE_HEIGHT = (int)(SIDE_HEIGHT*1.5);CHART_HEIGHT =(int)(CHART_HEIGHT*0.3);break;}}ChartUtil cu = new ChartUtil();PointF[] zuoBiaoStart;PointF[] zuoBiaoEnd;Graphics g; [Page]Bitmap bm;createCanvas(out bm, out g, out zuoBiaoEnd, out zuoBiaoStart,cu);//画坐标轴int chiDu = drawAxes(data, zuoBiaoStart, g, zuoBiaoEnd,cu);//画条形图float barWidth = CHART_WIDTH / (2 * 2);PointF barOrigin = new PointF(CHART_LEFT + (barWidth / 2),0);float barHeight = 2;for(int i=0;i<2;i++){barHeight = ((float)data[i]/chiDu) *(CHART_HEIGHT/5) ;if(barHeight<0){barOrigin.Y = CHART_TOP + CHART_HEIGHT;}else{barOrigin.Y = CHART_TOP + CHART_HEIGHT - barHeight;}g.FillRectangle(new SolidBrush(ChartUtil.GetChartItemColor(i)),barOrigin.X,barOrigin. Y,barWidth,Math.Abs(barHeight));barOrigin.X = barOrigin.X + (barWidth * 2);}//画右上角的说明图形drawInstruction(CHART_LEFT, CHART_HEIGHT, CHART_TOP, g, word, data);//输出图形fileName = cu.PicPath + Guid.NewGuid().ToString() + \".gif\";bm.Save(fileName, ImageFormat.Gif);//资源回收bm.Dispose();g.Dispose();}private int drawAxes(int[] data, PointF[] zuoBiaoStart, Graphics g, PointF[] zuoBiaoEnd,C hartUtil cu){int chiDu =1;int[] t = cu.getZuoBiaoValue(data,out chiDu); [Page]for(int i=0;i<zuoBiaoStart.Length;i++){PointF txtPos = new PointF();txtPos.X = zuoBiaoStart[i].X -50;txtPos.Y = zuoBiaoStart[i].Y - 5;g.DrawString(t[i].ToString(),new Font(FontWord,8),Brushes.Black,txtPos);g.DrawLine(Pens.Black,zuoBiaoStart[i],zuoBiaoEnd[i]);}return chiDu;}private void createCanvas(out Bitmap bm, out Graphics g, out PointF[] zuoBiaoEnd, ou t PointF[] zuoBiaoStart,ChartUtil cu){//建立一个Graphics对象实例bm = new Bitmap(Pic_Width,Pic_Height);g = Graphics.FromImage(bm);//设置条图图形和文字属性g.ScaleTransform((Convert.ToSingle(Pic_Width))/SIDE_WIDTH,(Convert.ToSingle(Pic_ Height))/SIDE_HEIGHT);g.SmoothingMode = SmoothingMode.Default;g.TextRenderingHint = TextRenderingHint.AntiAlias;//设定画布和边g.Clear(Color.White);g.DrawRectangle(Pens.Black,0,0,SIDE_WIDTH-1,SIDE_HEIGHT-1);//设置条形图的边g.DrawRectangle(new Pen(Color.Black,1),CHART_LEFT,CHART_TOP,CHART_WIDTH, C HART_HEIGHT);if(hasNeg){g.DrawRectangle(new Pen(Color.Black,1),CHART_LEFT,CHART_TOP+CHART_HEIGHT, CHART_WIDTH, CHART_HEIGHT);}zuoBiaoEnd = null;zuoBiaoStart = cu.getZuoBiaoPoint(new PointF(CHART_TOP,CHART_LEFT),CHART_HEI GHT,CHART_WIDTH,out zuoBiaoEnd,hasNeg);}private void drawInstruction(int CHART_LEFT, int CHART_HEIGHT, int CHART_TOP, Gr aphics g, string[] word, int[] data){PointF colsNamePoint = new PointF(CHART_LEFT + 55,CHART_HEIGHT + CHART_TO P + 2); [Page]if(hasNeg){colsNamePoint = new PointF(CHART_LEFT + 55,CHART_HEIGHT*2 + CHART_TOP + 2);}PointF boxOrigin = new PointF(Pic_Width*5/6-30,CHART_TOP*1/3);PointF textOrigin = new PointF(Pic_Width*4/5+8,CHART_TOP*1/3 -3 );for(int i=0;i<2;i++){g.FillRectangle(new SolidBrush(ChartUtil.GetChartItemColor(i)),boxOrigin.X,boxOrigin. Y,20,10);//g.DrawRectangle(Pens.Black,boxOrigin.X,boxOrigin.Y,20,10);g.DrawString(word[i],new Font(FontWord,FontSize),Brushes.DarkBlue,colsNamePoint);g.DrawString(data[i].ToString(),new Font(FontWord,FontSize),Brushes.Black,textOrigi n);colsNamePoint.X += 150;boxOrigin.Y += 15;textOrigin.Y += 15;}}}public class ChartUtil{public readonly string PicPath = System.AppDomain.CurrentDomain.BaseDirectory + \ "Temp/\";public PointF[] getZuoBiaoPoint(PointF orign,int height,int width,out PointF[] endPoint, bool hasNeg){int num = 6;if(hasNeg) num = 11;PointF[] startPoint = new PointF[num];endPoint = new PointF[num];for(int i =0;i<num;i++){PointF pfStart = new PointF();PointF pfEnd = new PointF();pfStart.X = orign.X;pfEnd.X = orign.X + width;pfStart.Y = orign.Y + i*height/5;pfEnd.Y = pfStart.Y; [Page]startPoint[i] = pfStart;endPoint[i] = pfEnd;}return startPoint;public int[] getZuoBiaoValue(int[] data,out int chidu){int[] result = new Int32[11];int Max = data[0];for(int i=0;i<data.Length;i++){if(Max < data[i])Max = data[i];}string strMax = Max + \"\";chidu =(int)((Convert.ToInt32(strMax.Substring(0,1)) +1)* Math.Pow(10,strMax.Lengt h-1))/5;for(int i=0;i<result.Length;i++){result[i] = chidu* (5-i) ;}return result;}#region get colorpublic static Color GetChartItemColor(int itemIndex){Color selectedColor;switch(itemIndex){case 0:selectedColor = Color.Blue;break;case 1:selectedColor = Color.Red;break;case 2:selectedColor = Color.Yellow;break;case 3:selectedColor = Color.Purple;break;default:selectedColor = Color.Green;break;}return selectedColor; [Page]#endregion }}。
c语言如何画图
![c语言如何画图](https://img.taocdn.com/s3/m/c4e0011655270722192ef7e2.png)
c语言如何画图2007-06-12 14:38图形和图像函数包含在graphics.h里面(一) 像素函数56. putpiel() 画像素点函数57. getpixel()返回像素色函数(二) 直线和线型函数58. line() 画线函数59. lineto() 画线函数60. linerel() 相对画线函数61. setlinestyle() 设置线型函数62. getlinesettings() 获取线型设置函数63. setwritemode() 设置画线模式函数(三)、多边形函数64. rectangle() 画矩形函数65. bar() 画条函数66. bar3d() 画条块函数67. drawpoly() 画多边形函数(四)、圆、弧和曲线函数68. getaspectratio()获取纵横比函数69. circle()画圆函数70. arc() 画圆弧函数71. ellipse()画椭圆弧函数72. fillellipse() 画椭圆区函数73. pieslice() 画扇区函数74. sector() 画椭圆扇区函数75. getarccoords()获取圆弧坐标函数(五)、填充函数76. setfillstyle() 设置填充图样和颜色函数77. setfillpattern() 设置用户图样函数78. floodfill() 填充闭域函数79. fillpoly() 填充多边形函数80. getfillsettings() 获取填充设置函数81. getfillpattern() 获取用户图样设置函数(六)、图像函数82. imagesize() 图像存储大小函数83. getimage() 保存图像函数84. putimage() 输出图像函数四、图形和图像函数对许多图形应用程序,直线和曲线是非常有用的。
但对有些图形只能靠操作单个像素才能画出。
当然如果没有画像素的功能,就无法操作直线和曲线的函数。
用C语言编程绘制函数的图像源程序
![用C语言编程绘制函数的图像源程序](https://img.taocdn.com/s3/m/02c76fcc0c22590102029dd2.png)
#include<stdio.h>#include<graphics.h>#include<conio.h>float a,b,c,xmin,xmax,max; /*定义全局变量*/void menu(){printf("\n************************************WELCOME************************ *************\n");printf("\n 1.输入参数");printf("\n 2.输入x的范围");printf("\n 3.画函数图像");printf("\n 4.退出");printf("\n*********************************************************************** *********\n");}fun1(){printf("输入a,b,c\n");scanf("%f,%f,%f",&a,&b,&c); /*输入系数a,b,c*/}fun2() /*输入x范围*/{printf("输入xmin,xmax\n");scanf("%f,%f",&xmin,&xmax);}funmax() /*求出x轴最大范围*/{float m,n;if(xmin<0)m=-xmin;elsem=xmin;if(xmax<0)n=-xmax;elsen=xmax;if(m>=n)max=m;elsemax=n;}float funx(float max_x) /*求出x轴对应系数*/{return(max_x/2/max);}float funy(float max_y) /*求出y轴对应系数*/{float d;d=max_y/2/(a*max*max+b*max+c);if(d>0.6)d=0.6;if(d<0.0026)d=0.0026;return(d);}fun3(){int max_x,max_y;int graphdriver=DETECT,graphmode;float x1,y1,x2,y2,x,coe_x,coe_y;initgraph(&graphdriver,&graphmode,""); /*图形初始化*/cleardevice(); /*清屏*/max_x=getmaxx(); /*求出屏幕最大横坐标*/max_y=getmaxy(); /*求出屏幕最大横坐标*/funmax();coe_x=funx(max_x);coe_y=funy(max_y);line(0,240,640,240); /*画直线*/line(320,0,320,480);line(640,240,635,235);line(640,240,635,245);line(320,0,315,5);line(320,0,325,5);outtextxy(320,240,"(0,0)"); /*在固定点输出字符串*/outtextxy(620,240,"x");outtextxy(320,10,"y");x1=max_x/2+xmin*coe_x,y1=max_y/2-(a*xmin*coe_x*xmin*coe_x+b*xmin*coe_x+c)*coe_y; moveto((int)x1,(int)y1);for(x=xmin*coe_x;x<=xmax*coe_x;x++){x2=max_x/2+x,y2=max_y/2-(a*x*x+b*x+c)*coe_y;lineto((int)x2,(int)y2);}getch();closegraph(); /*关闭图形函数*/}main(){int n;menu();while(1){scanf("%d",&n);switch(n){ case 1:fun1();break;case 2:fun2();break;case 3:fun3();break;case 4:exit(0);default:printf("\n error \n");}}}。
利用C语言编辑画图程序的实现方法(推荐)
![利用C语言编辑画图程序的实现方法(推荐)](https://img.taocdn.com/s3/m/3d21a5986429647d27284b73f242336c1eb9306d.png)
利⽤C语⾔编辑画图程序的实现⽅法(推荐)不知道⼤家在进⾏开发县级电⽹调度⾃动化系统的时候,是否都会遇到⼀个问题就是:要绘制⼀个电⼒系统⼀次接线图。
⼤家都应该知道其实电⼒系统的⼀次接线图是较为复杂的,如果想要使⽤⼀般的编程⽅法来进⾏绘制的话,基本上就是⾏不通的。
那么我们应该怎样才可以更加的⾼效直接呢?今天⼩编就会给⼤家介绍⼀个⽅法,那就是:利⽤C语⾔编辑画图程序的实现⽅法。
希望这篇教程对于⼤家有所帮助。
⼀、实现⽅法在教程开始之前,⼩编先为⼤家介绍⼀下在编程程序⾥⾯早已定义了⼏个特殊按钮。
为什么⼩编要为⼤家介绍这⼏个特殊按钮呢?那是因为这个⼏个特殊按钮可以帮助我们可以⾼效的完成程序开发。
具体的特殊按钮如下:特殊键\\"E":主要作⽤是⽤来调出已有⽂件;特殊键\\"S":将当前的图形存⼊到⽂件⾥⾯;特殊键\\"V":提起画笔;特殊键\\"C":绘制⼀个圆;特殊键\\"W":开始绘制⼀个图;特殊键\\"R":开始擦除⼀个图。
好了,这⼏个特殊键⼩编就已经介绍完毕了。
现在⼩编就为⼤家介绍⼀下具体的实现⽅法吧。
当程序⼀开始运⾏的时候,⼤家就可以在电脑的屏幕上看到⼀个黄⾊的边框,这个边框其实是⽤来设定画图的区域。
在画图的区域中间会出现⼀个提起的画笔符号,当⼤家单击按下特殊键"W"的时候,刚刚提起的画笔符号变为。
这个时候就可以使⽤移动⽅向键(左上、左下、右上、右下、上、下、左、右)来进⾏绘图;当⼤家单击按下特殊键"R"键的时候,画笔符号就会变为。
这个时候可以使⽤移动⽅向键来进⾏擦图;在绘图的过程中,当我们按下特殊键"C",就可以绘制出⼀个圆,这个圆的半径是为20个象素点。
当⼤家结束绘图的时候,只需要按下特殊键"S",就可以把画好的图形进⾏存盘了;按下特殊键"E"就可以调出已经有的图形来进⾏相对应的编辑了。
利用C语言实现简单计算机图形
![利用C语言实现简单计算机图形](https://img.taocdn.com/s3/m/285d08c3b8d528ea81c758f5f61fb7360b4c2b0f.png)
利用C语言实现简单计算机图形计算机图形在现代计算机应用中起着重要的作用,可以用来实现各种效果和交互。
C语言作为一种广泛应用的编程语言,可以用来编写各种计算机图形程序。
本文将介绍利用C语言实现简单计算机图形的方法和技巧。
一、图形库的选择在使用C语言实现计算机图形时,我们需要选择一个合适的图形库来帮助我们进行图形的绘制和显示。
常用的图形库包括OpenGL、SDL、SFML等。
在选择图形库时,我们需要考虑到自己的需求以及所运行的平台,选择一个功能强大、易于使用的图形库。
二、绘制基本图形在开始实现图形程序之前,我们需要了解基本的图形绘制原理。
在C语言中,我们可以使用图形库提供的函数来实现各种图形的绘制。
比如,要绘制一个直线,我们可以使用线段绘制函数;要绘制一个圆形,我们可以使用圆形绘制函数。
通过调用相应的函数,我们可以实现各种基本图形的绘制。
三、实现图形效果除了基本图形的绘制,我们还可以利用C语言的一些特性来实现各种图形效果。
比如,我们可以使用循环语句和条件语句来实现动画效果;我们还可以使用数组和矩阵来处理图形的变换和旋转。
通过合理地运用这些特性,我们可以实现更加生动和复杂的图形效果。
四、键盘和鼠标事件实现计算机图形时,通常需要用户的输入来进行交互。
在C语言中,我们可以通过监听键盘和鼠标事件来实现用户的交互操作。
比如,我们可以通过监听键盘事件来控制图形的移动和变换;我们还可以通过监听鼠标事件来实现图形的选择和拖拽。
通过处理这些事件,我们可以实现更加灵活和交互的图形程序。
五、图形算法在实现计算机图形时,我们还需要了解一些常用的图形算法。
比如,直线的绘制可以使用Bresenham算法来实现,圆的绘制可以使用中点画圆算法来实现。
了解这些算法可以帮助我们更好地理解图形的绘制原理,并且优化我们的图形程序。
六、实例演示下面是一个使用C语言实现简单计算机图形的例子:```c#include <stdio.h>#include <graphics.h>int main(){int gd = DETECT, gm;initgraph(&gd, &gm, "");// 绘制一个直线line(100, 100, 200, 200);// 绘制一个矩形rectangle(300, 300, 400, 400);// 绘制一个圆形circle(500, 500, 50);// 绘制一个椭圆ellipse(600, 600, 0, 360, 100, 50);getch();closegraph();return 0;}```以上代码使用了BGI图形库来实现图形的绘制和显示。
如何实现C语言实用画图教程
![如何实现C语言实用画图教程](https://img.taocdn.com/s3/m/dbce6eb0b52acfc789ebc9bf.png)
如何实现C语言画图教程C语言有丰富的数据结构和运算符。
包含了各种数据结构,如整型、数组类型、指针类型和联合类型等,用来实现各种数据结构的运算。
以下是小编为大家搜索整理的C语言如何实现画图教程,希望能给大家带来帮助!更多精彩内容请及时关注我们考试网!程序中定义了几个特殊键:V”:画笔提起W”:开始画图R”:开始擦图S”:当前图形存入文件E”:调出已有文件C”:画圆程序一运行,屏幕上出现一个黄色的边框来设定画图的区域,区域中间出现提起的画笔符号,当按下”W“键时,画笔符号变为,此时可移动方向键(上、下、左、右、左上、左下、右上、右下)来画图;当按下”R“键时,画笔符号变为,此时可移动方向键来擦图;在画图过程中,按下“C”键,可画出一个半径为20个象素点的圆;当结束画图时,按下“S”键,将画好的图形存盘;按下“E”键可调出已有的图形进行编辑。
3.源程序清单# include graphics.h# include stdio.h# include fcntl.h# include stdlib.hmain()void save(),load();void *wg,*rg,*vg,*fy;int driver,mode;int c=RED;int x=320,y=225;int x1,y1,x2,y2;int k,k1,k2;/* initialize grapher */ detectgraph(driver,mode); initgraph(driver,mode,c: c); /* write the pen */bar(200,10,206,16);line(203,7,200,10);line(203,7,206,10);line(243,7,240,16);line(243,7,246,16);line(283,7,280,10);line(283,7,286,10);line(283,7,283,16);/* save the pen */wg=malloc(imagesize(200,7,206,16)); rg=malloc(imagesize(240,7,246,16)); vg=malloc(imagesize(280,7,286,16)); fy=malloc(imagesize(200,7,206,16)); getimage(200,7,206,16,wg); getimage(240,7,246,16,rg); getimage(280,7,286,16,vg); cleardevice();/* write the box */setcolor(YELLOW);rectangle(4,19,637,447);x1=x-3;y1=y+1;x2=x+3;y2=y+10;getimage(x1,y1,x2,y2,fy); putimage(x1,y1,vg,XOR_PUT);/* receive the command */for (;;)while (bioskey(1)==0);k=bioskey(0);putimage(x1,y1,fy,AND_PUT);if (((k0x00ff)|0x00)==0)k1=k0xff?0:k8; /* k1 is the specialkey value */ elsek2=k0x00ff; /* k2 is the non-specialkey value */ if (((k0x00ff)|0x00)==0) /* Special key */ switch(k1)case 45:restorecrtmode();exit(0);case 72:if (y20)y=y-1;break;case 75:if (x5)x=x-1;break;case 77:if (x636)x=x+1;break;case 80:if (y446)y=y+1; break;case 71:if ((x5)(y20)) x=x-1;y=y-1; break;case 79:if ((x5)(y446)) x=x-1;y=y+1;。
C程序--画图举例
![C程序--画图举例](https://img.taocdn.com/s3/m/5da33bfef705cc1755270976.png)
while(1)
{ if(kbhit())
{ sign = getch();
if(sign == 0x1b)
{ free(buf);
break;
}
}
else
{
for(i = 0;i < a;i ++){
putimage((sign1[i] == 1 ? x[i] ++ : x[i] --),
(sign2[i] == 1 ? y[i] ++ : y[i] --),buf,COPY_PUT);
if(x[i] > getmaxx() - 21)
sign1[i] = 0;
四瓣花型图案
#include<math.h>
#include<graphics.h>
#define PI 3.14159
#define D 100
main()
{ float a,e,x1,y1,x2,y2;
int gdriver=VGA,gmode=VGAHI;
initgraph(&gdriver,&gmode,"d:\\tc");
x2=(m[0][0]*f[0]+m[1][0]*f[1]+m[2][0]*f[2])+x0;
y2=(m[0][1]*f[0]+m[1][1]*f[1]+m[2][1]*f[2])*DIST+y0;
if(n==1) {n=2;x1=x2;y1=y2;}
else
{
line(x1,y1,x2,y2);
画图软件C程序代码
![画图软件C程序代码](https://img.taocdn.com/s3/m/4bea73c10242a8956aece405.png)
#include <graphics.h>#include <stdlib.h>#include <conio.h>#include <stdio.h>#include <dos.h>#include <bios.h>#include <math.h>#include <alloc.h>/*定义常量*//*向上翻页移键*/#define PAGEUP 0x4900/*向下翻页移键*/#define PAGEDOWN 0x5100/*Escape键*/#define ESC 0x011b/*左移键*/#define LEFT 0x4b00/*右移键*/#define RIGHT 0x4d00/*下移键*/#define DOWN 0x5000/*上移键*/#define UP 0x4800/*空格键*/#define SPACE 0x3920#define NO_PRESSED 0#define LEFT_PRESSED 1#define RIGHT_PRESSED 2#define pi 3.1415926/*定义全局变量*/int Rx,Ry,R;int TOPx,TOPy,BOTTOMx,BOTTOMy;int Centx,Centy;int lineStartx,lineStarty,lineEndx,lineEndy;int linePoint_x[20],linePoint_y[20];/*这里的字模数组均由“点阵字模工具”生成,你可以用你自己需要的点阵信息来替换示例中的字模信息,注意字模大小要一致,否则显示会出问题。
*/char zhi16K[]={/* 以下是 '直' 的 16点阵楷体_GB2312 字模,32 byte */0x01,0x00,0x01,0x00,0x01,0xF0,0x1E,0x00,0x02,0x00,0x07,0xC0,0x08,0x40,0x0F,0x40,0x08,0x40,0x0F,0x40,0x08,0x40,0x0F,0x40,0x08,0x40,0x0F,0xFC,0x70,0x00,0x00,0x00,};char xian16K[]={/* 以下是 '线' 的 16点阵楷体_GB2312 字模,32 byte */ 0x00,0x80,0x00,0x90,0x08,0x88,0x10,0x80,0x24,0xF0,0x45,0x80,0x78,0xB0,0x11,0xC0,0x2C,0x88,0x70,0x50,0x04,0x60,0x18,0xA4,0x63,0x14,0x00,0x0C,0x00,0x04,0x00,0x00,};char ju16K[]={/* 以下是 '矩' 的 16点阵楷体_GB2312 字模,32 byte */ 0x00,0x00,0x08,0x00,0x08,0x78,0x10,0x80,0x1E,0x80,0x28,0xF8,0x48,0x88,0x0E,0x88,0xF8,0xF0,0x08,0x80,0x14,0x80,0x12,0x9E,0x20,0xE0,0x40,0x00,0x00,0x00,0x00,0x00,};char xing16K[]={/* 以下是 '形' 的 16点阵楷体_GB2312 字模,32 byte */ 0x00,0x00,0x07,0x88,0x3A,0x08,0x12,0x10,0x12,0x20,0x17,0x48,0xFA,0x10,0x12,0x20,0x12,0xC8,0x12,0x08,0x22,0x10,0x42,0x20,0x00,0x40,0x00,0x80,0x03,0x00,0x00,0x00,};char yuan16K[]={/* 以下是 '圆' 的 16点阵楷体_GB2312 字模,32 byte */ 0x00,0xF8,0x3F,0x08,0x23,0x88,0x24,0x88,0x27,0x08,0x21,0xC8,0x2E,0x48,0x29,0x48,0x29,0x48,0x22,0x88,0x24,0x48,0x28,0x08,0x3F,0xE8,0x00,0x10,0x00,0x00,0x00,0x00,};char qing16K[]={/* 以下是 '清' 的 16点阵楷体_GB2312 字模,32 byte */ 0x00,0x80,0x00,0xE0,0x33,0x80,0x10,0xE0,0x03,0x80,0x40,0xFC,0x2F,0x00,0x01,0xE0,0x12,0x20,0x13,0xA0,0x22,0x20,0x63,0xA0,0x42,0x20,0x02,0x60,0x00,0x20,0x00,0x00,};char ping16K[]={/* 以下是 '屏' 的 16点阵楷体_GB2312 字模,32 byte */ 0x00,0xF0,0x0F,0x30,0x08,0x60,0x0F,0x80,0x0A,0x20,0x09,0x40,0x08,0xF8,0x17,0x20,0x11,0x3E,0x2F,0xE0,0x21,0x20,0x42,0x20,0x82,0x20,0x04,0x20,0x08,0x20,0x00,0x00,};char bao16K[]={/* 以下是 '保' 的 16点阵楷体_GB2312 字模,32 byte */ 0x00,0x00,0x09,0xF0,0x0A,0x10,0x12,0x10,0x13,0xE0,0x30,0x80,0x50,0xFC,0x9F,0x80,0x11,0xC0,0x12,0xA0,0x14,0x98,0x18,0x8E,0x10,0x80,0x10,0x80,0x00,0x00,0x00,0x00,};char cun16K[]={/* 以下是 '存' 的 16点阵楷体_GB2312 字模,32 byte */0x01,0x00,0x01,0x00,0x01,0xF0,0x1E,0x00,0x02,0x70,0x05,0x90,0x08,0x20,0x08,0x40,0x18,0x7E,0x2B,0xA0,0xC8,0x20,0x08,0x20,0x08,0x20,0x08,0xA0,0x00,0x40,0x00,0x00,};char jia16K[]={/* 以下是 '加' 的 16点阵楷体_GB2312 字模,32 byte */0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x0F,0x00,0x79,0x3C,0x09,0x44,0x11,0x44,0x11,0x44,0x22,0x44,0x22,0x78,0x4A,0x00,0x84,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};char zai16K[]={/* 以下是 '载' 的 16点阵楷体_GB2312 字模,32 byte */0x00,0x80,0x08,0xA0,0x08,0x90,0x0E,0x80,0x38,0xF0,0x0F,0x80,0x78,0x50,0x0E,0x50,0x34,0x20,0x1E,0x20,0x34,0x50,0x0E,0x92,0x75,0x0A,0x04,0x06,0x04,0x02,0x00,0x00,};char bang16K[]={/* 以下是 '帮' 的 16点阵楷体_GB2312 字模,32 byte */0x04,0x00,0x07,0x38,0x1C,0x48,0x06,0x50,0x1C,0x50,0x07,0x48,0x78,0x58,0x11,0x40,0x21,0xF0,0x4F,0x10,0x09,0x10,0x09,0x50,0x09,0x20,0x01,0x00,0x01,0x00,0x00,0x00,};char zhu16K[]={/* 以下是 '助' 的 16点阵楷体_GB2312 字模,32 byte */0x00,0x00,0x00,0x20,0x0C,0x20,0x34,0x20,0x24,0x20,0x34,0x38,0x25,0xC8,0x34,0x48,0x24,0x48,0x26,0x88,0x38,0x88,0xE1,0x28,0x02,0x10,0x04,0x00,0x00,0x00,0x00,0x00,};/*自定义函数*/void outChinese(char *mat,int matsize,int x,int y,int color); void fill(int startx,int starty,int endx,int endy,int color); void showHelp();void save();void load();int mouseStatus(int* x,int* y);int setMousePos(int x, int y);void DrawMouse(float x,float y);void DrawLine();void DrawRectangle();void LineToCircle(int x0,int y0,int r);void DrawCircle();long factorial(int n);float berFunction(int i,int n,double t);void DrawBezier();/*根据点阵信息显示中文函数*/void outChinese(char *mat,int matsize,int x,int y,int color)/*依次:字模指针、点阵大小、起始坐标(x,y)、颜色*/{int i, j, k, n;n = (matsize - 1) / 8 + 1;for(j = 0; j < matsize; j++)for(i = 0; i < n; i++)for(k = 0;k < 8; k++)if(mat[j * n + i] & (0x80 >> k))/*测试为1的位则显示*/putpixel(x + i * 8 + k, y + j, color);}/*填充函数*/void fill(int startx,int starty,int endx,int endy,int color){int i,j;for(i=startx;i<=endx;i++)for(j=starty;j<=endy;j++)/*在指定位置以指定颜色画一像素*/putpixel(i,j,color);}/*显示用户帮助函数*/void showHelp(){setcolor(14);outtextxy(45,50,"Line:");setcolor(WHITE);outtextxy(45,50," 1 Press left button to start until to line end."); outtextxy(45,65," 2 Use UP,DOWN,LEFT,RIGHT keys to move it.");outtextxy(45,80," 3 Use PAGEUP key to enlarge it, and PAGEDOWN key to shrink it.");outtextxy(45,95," 4 Use SPACE key to rotate it.");setcolor(14);outtextxy(45,120,"Rectangle:");setcolor(WHITE);outtextxy(45,120," 1 Press left button to start until to right corner.");outtextxy(45,135," 2 Use UP,DOWN,LEFT,RIGHT keys to move it."); outtextxy(45,150," 3 Use PAGEUP key to enlarge it, and PAGEDOWN key to shrink it.");setcolor(14);outtextxy(45,170,"Circle:");setcolor(WHITE);outtextxy(45,170," 1 Press left button to start until to end.");outtextxy(45,185," 2 Use PAGEUP key to enlarge it, and PAGEDOWN key to shrink it.");setcolor(14);outtextxy(45,205,"Bezier:");setcolor(WHITE);outtextxy(45,205," Press left button to start, and right button to end.");outtextxy(45,230,"Press ESC key to stop the operation function.");outtextxy(45,245,"Press right button to end the drawing works.");outtextxy(45,260,"Press any key to continue......");getch();fill(40,40,625,270,0);}/*保存函数*/void save(){int i,j;FILE *fp;char fileName[20];fill(0,447,630,477,2);gotoxy(1,25);printf("\n\n\n\n Input the file name[.dat]:");scanf("%s",fileName);fill(0,447,630,477,2);/*以读写的方式打开文件*/if((fp=fopen(fileName,"w+"))==NULL){outtextxy(260,455,"Failed to open file!");exit(0);}outtextxy(280,455,"saving...");/*保存像素到文件*/for(i=5;i<630;i++)for(j=30;j<=445;j++)fputc(getpixel(i,j),fp);fclose(fp);fill(0,447,630,477,2);outtextxy(260,455,"save over!");}/*打开函数*/void load(){int i,j;char fileName[20];FILE *fp;fill(0,447,630,477,2);gotoxy(1,25);printf("\n\n\n\n Input the file name[.dat]:"); scanf("%s",fileName);/*打开指定的文件*/if((fp=fopen(fileName,"r+"))!=NULL){fill(0,447,630,477,2);outtextxy(280,455,"loading...");/*从文件中读出像素*/for(i=5;i<630;i++)for(j=30;j<=445;j++)putpixel(i,j,fgetc(fp));fill(0,447,630,477,2);outtextxy(280,455,"loading over !");}/*打开失败*/else{fill(0,447,630,477,2);outtextxy(260,455,"Failed to open file!");}fclose(fp);}/*获取鼠标状态函数*/int mouseStatus(int* x,int* y){/*定义两个寄存器变量,分别存储入口参数和出口参数*/ union REGS inregs,outregs;int status;status=NO_PRESSED;/*入口参数AH=3,读取鼠标位置及其按钮状态*/inregs.x.ax=3;int86(0x33,&inregs,&outregs);/*CX表示水平位置,DX表示垂直位置*/*x=outregs.x.cx;*y=outregs.x.dx;/*BX表示按键状态*/if(outregs.x.bx&1)status=LEFT_PRESSED;else if(outregs.x.bx&2)status=RIGHT_PRESSED;return (status);}/*设置鼠标指针位置函数*/int setMousePos(int x,int y){union REGS inregs,outregs;/*入口参数AH=4,设置鼠标指针位置*/inregs.x.ax=4;inregs.x.cx=x;inregs.x.dx=y;int86(0x33,&inregs,&outregs);}/*绘制鼠标函数*/void DrawMouse(float x,float y){line(x,y,x+5,y+15);line(x,y,x+15,y+5);line(x+5,y+15,x+15,y+5);line(x+11,y+9,x+21,y+19);line(x+9,y+11,x+19,y+21);line(x+22,y+19,x+20,y+21);}/*绘制直线函数*/void DrawLine(){int x0,y0,x1,y1;int last_x=0,last_y=0;int endFlag=0;int key;int temStartx,temStarty,temEndx,temEndy;int increment_x,increment_y,angle;DrawMouse(last_x,last_y);while(1){/*右键结束画直线*/while((mouseStatus(&x1,&y1)==RIGHT_PRESSED))endFlag=1;if(endFlag==1)break;/*鼠标移动,没有单击,仅仅画移动的鼠标*/while(mouseStatus(&x1,&y1) == NO_PRESSED){if(last_x!=x1||last_y!=y1){DrawMouse(last_x,last_y);DrawMouse(x1,y1);last_x=x1;last_y=y1;}}/*单击左键后,开始画直线*/if(mouseStatus(&x0,&y0)==LEFT_PRESSED){DrawMouse(last_x,last_y);line(x0,y0,x1,y1);last_x=x1;last_y=y1;/*拉动过程中,画直线和鼠标*/while(mouseStatus(&x1, &y1)==LEFT_PRESSED){if(last_x!=x1||last_y!=y1){line(x0,y0,last_x,last_y);line(x0,y0,x1,y1);last_x=x1;last_y=y1;}}/*松开左键后,画直线完成,记录直线的起始位置*/lineStartx=x0;lineStarty=y0;lineEndx=x1;lineEndy=y1;while(1){/*从键盘获取键值,开始操作(移动、放大、缩小、旋转)直线*/ key=bioskey(0);/*ESC键,退出操作*/if(key==ESC)break;/*旋转*/if(key==SPACE){/*计算旋转中心*//*如果直线示倾斜的*/if((lineStarty!=lineEndy)&& (lineStartx!=lineEndx)){Centx=(lineEndx-lineStartx)/2+lineStartx;Centy=(lineEndy-lineStarty)/2+lineStarty;}/*如果直线是竖直的*/if(lineStarty==lineEndy){Centx=(lineEndx-lineStartx)/2+lineStartx;Centy=lineStarty;}/*如果直线是水平的*/if(lineStartx==lineEndx){Centx=lineStartx;Centy=(lineEndy-lineStarty)/2+lineStarty;}temStartx=lineStartx;temStarty=lineStarty;temEndx=lineEndx;temEndy=lineEndy;/*旋转不能超过边界*/if(lineStartx>=10 && lineStarty>=40 && lineEndx <=620 && lineEndy <=445){/*清除原有的直线*/setwritemode(XOR_PUT);line(lineStartx,lineStarty,lineEndx,lineEndy);/*计算旋转30度后的起点坐标*/lineStartx=(temStartx-Centx)*cos(pi/6)-(temStarty-Centy)*sin(pi/6)+Centx; lineEndx=(temEndx-Centx)*cos(pi/6)-(temEndy-Centy)*sin(pi/6)+Centx;/*计算旋转30度后的终点坐标*/lineStarty=(temStartx-Centx)*sin(pi/6)+(temStarty-Centy)*cos(pi/6)+Centy;lineEndy=(temEndx-Centx)*sin(pi/6)+(temEndy-Centy)*cos(pi/6)+Centy;temStartx=lineStartx;temStarty=lineStarty;temEndx=lineEndx;temEndy=lineEndy;/*绘制旋转后的直线*/line(lineStartx,lineStarty,lineEndx,lineEndy);}}/*左移直线*/if(key==LEFT){if(lineStartx>=10 && lineStarty>=40 && lineEndx <=620 && lineEndy <=445){setwritemode(XOR_PUT);line(lineStartx,lineStarty,lineEndx,lineEndy);/*起始的横坐标减小*/lineStartx-=5;lineEndx-=5;line(lineStartx,lineStarty,lineEndx,lineEndy);}}/*右移直线*/if(key==RIGHT){if(lineStartx>=10 && lineStarty>=40 && lineEndx <=620 && lineEndy <=445){setwritemode(XOR_PUT);line(lineStartx,lineStarty,lineEndx,lineEndy);/*起始的横坐标增加*/lineStartx+=5;lineEndx+=5;line(lineStartx,lineStarty,lineEndx,lineEndy);}}/*下移直线*/if(key==DOWN){if(lineStartx>=10 && lineStarty>=40 && lineEndx <=620 && lineEndy <=445){setwritemode(XOR_PUT);line(lineStartx,lineStarty,lineEndx,lineEndy);/*起始的纵坐标增加*/lineStarty+=5;lineEndy+=5;line(lineStartx,lineStarty,lineEndx,lineEndy);}}/*上移直线*/if(key==UP){if(lineStartx>=10 && lineStarty>=40 && lineEndx <=620 && lineEndy <=445){setwritemode(XOR_PUT);line(lineStartx,lineStarty,lineEndx,lineEndy);/*起始的纵坐标减小*/lineStarty-=5;lineEndy-=5;line(lineStartx,lineStarty,lineEndx,lineEndy);}}/*放大直线*/if(key==PAGEUP){if(lineStartx>=10 && lineStarty>=40 && lineEndx <=620 && lineEndy <=445){setwritemode(XOR_PUT);line(lineStartx,lineStarty,lineEndx,lineEndy);/*如果直线是倾斜的*/if((lineStarty!=lineEndy)&& (lineStartx!=lineEndx)){/*计算直线的倾角*/angle=atan((fabs(lineEndy-lineStarty))/(fabs(lineEndx-lineStartx)));/*计算水平增量*/increment_x=cos(angle)*2;/*计算垂直增量*/increment_y=sin(angle)*2;/*计算放大后的起始坐标*/if(lineStartx<lineEndx){lineStartx-=increment_x;lineStarty-=increment_y;lineEndx+=increment_x;lineEndy+=increment_y;}if(lineStartx>lineEndx){lineEndx-=increment_x;lineEndy-=increment_y;lineStartx+=increment_x;lineStarty+=increment_y;}}/*如果直线竖直的*/if(lineStarty==lineEndy){lineStartx-=5;lineEndx+=5;}/*如果直线是水平的*/if(lineStartx==lineEndx){lineStarty-=5;lineEndy+=5;}line(lineStartx,lineStarty,lineEndx,lineEndy);}}/*缩小直线*/if(key==PAGEDOWN){if(lineStartx>=10 && lineStarty>=40 && lineEndx <=620 && lineEndy <=445){setwritemode(XOR_PUT);line(lineStartx,lineStarty,lineEndx,lineEndy);/*如果直线是倾斜的*/if((lineStarty!=lineEndy)&& (lineStartx!=lineEndx)){/*计算直线的倾角*/angle=atan((fabs(lineEndy-lineStarty))/(fabs(lineEndx-lineStartx)));/*计算水平减少量*/increment_x=cos(angle)*2;/*计算垂直减少量*/increment_y=sin(angle)*2;/*计算缩小后的起始坐标*/if(lineStartx<lineEndx){lineStartx+=increment_x;lineStarty+=increment_y;lineEndx-=increment_x;lineEndy-=increment_y;}if(lineStartx>lineEndx){lineEndx+=increment_x;lineEndy+=increment_y;lineStartx-=increment_x;lineStarty-=increment_y;}}/*如果直线竖直的*/if(lineStarty==lineEndy){lineStartx+=5;lineEndx-=5;}/*如果直线是水平的*/if(lineStartx==lineEndx){lineStarty+=5;lineEndy-=5;}line(lineStartx,lineStarty,lineEndx,lineEndy); }}}DrawMouse(x1,y1);}}DrawMouse(last_x,last_y);}/*绘制矩形函数*/void DrawRectangle(){int x0,y0,x1,y1;int last_x=0,last_y=0;int endFlag=0;int key;DrawMouse(last_x,last_y);while(1){/*单击右键,结束绘制矩形*/while((mouseStatus(&x1,&y1)==RIGHT_PRESSED))endFlag=1;if(endFlag==1)break;/*移动鼠标,仅仅绘制鼠标即可*/while(mouseStatus(&x1,&y1) == NO_PRESSED){if(last_x!=x1||last_y!=y1){DrawMouse(last_x,last_y);DrawMouse(x1,y1);last_x=x1;last_y=y1;}}/*单击左键开始绘制矩形*/if(mouseStatus(&x0,&y0)==LEFT_PRESSED){DrawMouse(last_x,last_y);rectangle(x0,y0,x1,y1);last_x=x1;last_y=y1;/*按着鼠标左键不动,绘制矩形*/while(mouseStatus(&x1,&y1)==LEFT_PRESSED){if(last_x!=x1||last_y!=y1){rectangle(x0,y0,last_x,last_y);rectangle(x0,y0,x1,y1);last_x=x1;last_y=y1;}}/*绘制结束后,记录左上角和右下角的坐标*/TOPx=x0;TOPy=y0;BOTTOMx=x1;BOTTOMy=y1;while(1){key=bioskey(0);if(key==ESC)break;/*放大矩形*/if(key==PAGEUP){if(TOPx>=10 && TOPy>=40 && BOTTOMx <=620 &&BOTTOMy <=445) {/*清除原有的直线*/setwritemode(XOR_PUT);rectangle(TOPx,TOPy,BOTTOMx,BOTTOMy);/*左上角坐标减小*/TOPx-=5;TOPy-=5;/*右下角坐标增加*/BOTTOMx+=5;BOTTOMy+=5;/*绘制放大后的矩形*/rectangle(TOPx,TOPy,BOTTOMx,BOTTOMy);}}/*缩小矩形*/if(key==PAGEDOWN){if(TOPx>=10 && TOPy>=40 && BOTTOMx <=620 &&BOTTOMy <=445) {setwritemode(XOR_PUT);rectangle(TOPx,TOPy,BOTTOMx,BOTTOMy);/*左上角坐标增加*/TOPx+=5;TOPy+=5;/*右下角坐标减小*/BOTTOMx-=5;BOTTOMy-=5;/*绘制缩小后的矩形*/rectangle(TOPx,TOPy,BOTTOMx,BOTTOMy);}}/*左移矩形*/if(key==LEFT){if(TOPx>=10 && TOPy>=40 && BOTTOMx <=620 &&BOTTOMy <=445) {setwritemode(XOR_PUT);rectangle(TOPx,TOPy,BOTTOMx,BOTTOMy);/*横坐标减小*/TOPx-=5;BOTTOMx-=5;rectangle(TOPx,TOPy,BOTTOMx,BOTTOMy);}}/*右移矩形*/if(key==RIGHT){if(TOPx>=10 && TOPy>=40 && BOTTOMx <=620 &&BOTTOMy <=445) {setwritemode(XOR_PUT);rectangle(TOPx,TOPy,BOTTOMx,BOTTOMy);/*横坐标增加*/TOPx+=5;BOTTOMx+=5;rectangle(TOPx,TOPy,BOTTOMx,BOTTOMy);}}/*下移矩形*/if(key==DOWN){if(TOPx>=10 && TOPy>=40 && BOTTOMx <=620 &&BOTTOMy <=445) {setwritemode(XOR_PUT);rectangle(TOPx,TOPy,BOTTOMx,BOTTOMy);/*纵坐标增加*/TOPy+=5;BOTTOMy+=5;rectangle(TOPx,TOPy,BOTTOMx,BOTTOMy);}}/*上移矩形*/if(key==UP){if(TOPx>=10 && TOPy>=40 && BOTTOMx <=620 &&BOTTOMy <=445) {setwritemode(XOR_PUT);rectangle(TOPx,TOPy,BOTTOMx,BOTTOMy);/*纵坐标减小*/TOPy-=5;BOTTOMy-=5;rectangle(TOPx,TOPy,BOTTOMx,BOTTOMy);}}}DrawMouse(x1,y1);}}DrawMouse(last_x,last_y);}/*用直线法生成圆*/void LineToCircle(int x0,int y0,int r){int angle;int x1,y1,x2,y2;angle=0;x1=r*cos(angle*pi/180);y1=r*sin(angle*pi/180);while(angle<45){angle+=5;x2=r*cos(angle*pi/180);y2=r*sin(angle*pi/180);while(x2==x1)x2++;while(y2==y1)y2++;line(x0+x1,y0+y1,x0+x2,y0+y2);line(x0-x1,y0+y1,x0-x2,y0+y2);line(x0+x1,y0-y1,x0+x2,y0-y2);line(x0-x1,y0-y1,x0-x2,y0-y2);line(x0+y1,y0-x1,x0+y2,y0-x2);line(x0+y1,y0+x1,x0+y2,y0+x2);line(x0-y1,y0-x1,x0-y2,y0-x2);line(x0-y1,y0+x1,x0-y2,y0+x2);x1=x2+1;y1=y2+1;}}/*绘制圆函数*/void DrawCircle(){int x0,y0,x1,y1,r,oldr;int last_x,last_y;int endFlag;int key;last_x=0;last_y=0;endFlag=0;DrawMouse(last_x,last_y);while(1){/*单击右键,绘制圆结束*/while((mouseStatus(&x1,& y1)==RIGHT_PRESSED)) {endFlag=1;}if(endFlag==1)break;/*移动鼠标,仅绘制鼠标即可*/while(mouseStatus(&x1,&y1) == NO_PRESSED){if(last_x!=x1||last_y!=y1){DrawMouse(last_x,last_y);DrawMouse(x1,y1);last_x=x1;}}/*单击左键,开始绘制圆*/if(mouseStatus(&x0,&y0)==LEFT_PRESSED){/*计算半径*/r=sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));DrawMouse(last_x,last_y);LineToCircle(x0,y0,r);last_x=x1;last_y=y1;oldr=r;/*按住鼠标左键不动,拖动鼠标绘制圆*/while(mouseStatus(&x1,&y1)==LEFT_PRESSED){if(last_x!=x1||last_y!=y1){r=sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));LineToCircle(x0,y0,oldr);LineToCircle(x0,y0,r);last_x=x1;last_y=y1;oldr=r;}}/*绘制结束后,记录圆的圆心和半径*/Rx=x0;Ry=y0;R=r;while(1){key=bioskey(0);if(key==ESC)break;/*放大圆*/if(key==PAGEUP){if(Rx-R>10 && Ry-R>40 && Rx+R<620 && Ry+R<445) {/*如果半径和初始状态一样大,则保留原来的圆*/ if(R==r){setcolor(WHITE);R+=10;circle(Rx,Ry,R);}elsesetcolor(BLACK);/*用背景色画圆,覆盖原有的*/circle(Rx,Ry,R);/*增加半径*/R+=10;setcolor(WHITE);/*绘制新圆*/circle(Rx,Ry,R);}}}/*缩小圆*/if(key==PAGEDOWN){if(Rx-R>10 && Ry-R>40 && Rx+R<620 && Ry+R<445) {/*如果半径和初始状态一样大,则保留原来的圆*/ if(R==r){setcolor(WHITE);R-=10;circle(Rx,Ry,R);}else{setcolor(BLACK);/*用背景色画圆,覆盖原有的*/circle(Rx,Ry,R);setcolor(WHITE);/*减小半径*/R-=10;circle(Rx,Ry,R);}}}}DrawMouse(x1,y1);}}DrawMouse(last_x,last_y);}/*求阶乘函数*/long factorial(int n){long s=1;if(n==0)return 1;while(n>0){s*=n;n--;}return s;}/*伯恩斯坦基函数*/float berFunction(int i,int n,double t){if(i==0&&t==0||t==1&&i==n)return 1;else if(t==0||t==1)return 0;return factorial(n)/(factorial(i)*factorial(n-i))*pow(t,i)*pow(1-t,n-i); }/*绘制Bezier曲线函数*/void DrawBezier(){int x,y,x0,y0,x1,y1;float j,t,dt;int i,n;int endFlag=0;int last_x=0,last_y=0;n=0;DrawMouse(last_x,last_y);while(mouseStatus(&x1,&y1)==LEFT_PRESSED);while(1){while((mouseStatus(&x1,&y1)==RIGHT_PRESSED))endFlag=1;if(endFlag==1)break;/*如果有两个以上的点,则将其连接,即画直线*/if(n>1)line(linePoint_x[n-1],linePoint_y[n-1],linePoint_x[n-2],linePoint_y[n-2]);/*移动鼠标*/while(mouseStatus(&x1,&y1) == NO_PRESSED){if(last_x!=x1||last_y!=y1){DrawMouse(last_x,last_y);DrawMouse(x1,y1);last_x=x1;last_y=y1;}}/*单击左键时,绘制点*/while(mouseStatus(&x0,&y0)==LEFT_PRESSED); putpixel(x0,y0,14);/*记录每次鼠标左键单击的点坐标*/linePoint_x[n]=x0;linePoint_y[n]=y0;n++;}DrawMouse(x1,y1);dt=1.0/10;setwritemode(0);for(j=0;j<=10;j+=0.5){t=j*dt;x=0;y=0;i=0;while(i<n-1){x+=berFunction(i,n-2,t)*linePoint_x[i];y+=berFunction(i,n-2,t)*linePoint_y[i];i++;}if(j==0)moveto(x,y);lineto(x,y);}setwritemode(1);}void main(){int gdriver,gmode;int x0,y0,x1,y1;int last_x,last_y;int i;x0=250;y0=250;gdriver=DETECT;while( 1){initgraph(&gdriver,&gmode,"");setbkcolor(0);setcolor(14);/*绘制画布*/rectangle(5,30,630,445);setfillstyle(1,2);/*填充画布以外的颜色,画布仍呈背景色*/ floodfill(10,10,14);/*绘制按钮框*/for(i=0;i<=7;i++){setcolor(RED);line(60*i+1,2,60*i+1,25);line(60*i+1,2,60*i+55,2);setcolor(RED);line(60*i+1,25,60*i+55,25);line(60*i+55,2,60*i+55,25);}setcolor(RED);line(0,446,639,446);line(0,478,639,478);setcolor(8);/*绘制退出按钮框*/rectangle(570,2,625,25);setfillstyle(1,RED);floodfill(620,5,8);setcolor(WHITE);outtextxy(585,10,"EXIT");/*显示“直线”*/outChinese(zhi16K, 16, 10,6, WHITE); outChinese(xian16K, 16, 28,6, WHITE);/*显示“矩形”*/outChinese(ju16K, 16, 70,6, WHITE);outChinese(xing16K, 16, 88,6, WHITE);/*显示“圆形”*/outChinese(yuan16K, 16, 130,6, WHITE); outChinese(xing16K, 16, 148,6, WHITE);outtextxy(185,10,"Bezier");/*显示“清屏”*/outChinese(qing16K, 16, 250,6, WHITE); outChinese(ping16K, 16, 268,6, WHITE);/*显示“保存”*/outChinese(bao16K, 16, 310,6, WHITE);outChinese(cun16K, 16, 328,6, WHITE);/*显示“加载”*/outChinese(jia16K, 16, 370,6, WHITE);outChinese(zai16K, 16, 388,6, WHITE);/*显示“帮助”*/outChinese(bang16K, 16, 430,6, WHITE);outChinese(zhu16K, 16, 448,6, WHITE);setMousePos(x0,y0);setwritemode(1);DrawMouse(x0,y0);last_x=x0;last_y=y0;while(!((mouseStatus(&x1,&y1)==NO_PRESSED) && x1>240 &&x1<295&&y1>1&&y1<25)){/*单击退出按钮*/if((mouseStatus(&x1,&y1)==NO_PRESSED) && x1>570 &&x1<625&&y1>1&&y1<25)exit(0);/*鼠标移动*/while(mouseStatus(&x1,&y1) == NO_PRESSED||y1>25){if(last_x!=x1 && last_y!=y1){DrawMouse(last_x,last_y);DrawMouse(x1,y1);last_x=x1;last_y=y1;}}DrawMouse(last_x,last_y);/*在按钮框中单击左键后*/while(mouseStatus(&x1,&y1)==LEFT_PRESSED);/*绘制直线*/if(x1>0 && x1<60 && y1>1 && y1<25){setwritemode(0);setcolor(8);/*呈凹陷状态*/line(1,2,1,25);line(1,2,55,2);setcolor(15);line(1,25,55,25);line(55,2,55,25);setwritemode(1);DrawLine();setwritemode(0);setcolor(RED);/*还原成初始状态*/rectangle(1,2,55,25);setcolor(15);setwritemode(1);DrawMouse(last_x,last_y);}/*绘制矩形*/if(x1>60 && x1<115 && y1>1 && y1<25) {setwritemode(0);setcolor(8);line(61,2,61,25);line(61,2,115,2);setcolor(15);line(61,25,115,25);line(115,2,115,25);setwritemode(1);DrawRectangle();setwritemode(0);setcolor(RED);rectangle(61,2,115,25);setcolor(15);setwritemode(1);DrawMouse(last_x,last_y);}/*绘制圆形*/if(x1>120 && x1<175 && y1>1 && y1<25) {setwritemode(0);setcolor(8);line(121,2,121,25);line(121,2,175,2);setcolor(15);line(121,25,175,25);line(175,2,175,25);setwritemode(1);DrawCircle();setwritemode(0);setcolor(RED);rectangle(121,2,175,25);setcolor(15);setwritemode(1);DrawMouse(last_x,last_y);}/*绘制Bezier曲线*/if(x1>180 && x1<235 && y1>1 && y1<25) {setwritemode(0);setcolor(8);line(181,2,181,25);line(181,2,235,2);setcolor(15);line(181,25,235,25);line(235,2,235,25);setwritemode(1);DrawBezier();setwritemode(0);setcolor(RED);rectangle(181,2,235,25);setcolor(15);setwritemode(1);DrawMouse(last_x,last_y);}/*保存文件*/if(x1>300 && x1<355 && y1>1 && y1<25) {setwritemode(0);setcolor(8);line(301,2,301,25);line(301,2,355,2);setcolor(15);line(301,25,355,25);line(355,2,355,25);setwritemode(1);save();setwritemode(0);setcolor(RED);rectangle(301,2,355,25);setcolor(15);setwritemode(1);DrawMouse(last_x,last_y);}/*加载已有的文件*/if(x1>360 && x1<415 && y1>1 && y1<25) {setwritemode(0);setcolor(8);line(361,2,361,25);line(361,2,415,2);setcolor(15);line(361,25,415,25);line(415,2,415,25);setwritemode(1);load();setwritemode(0);setcolor(RED);rectangle(361,2,415,25);setcolor(15);setwritemode(1);DrawMouse(last_x,last_y);}/*显示用户帮助*/if(x1>420 && x1<475 && y1>1 && y1<25) {setwritemode(0);setcolor(8);line(421,2,421,25);line(421,2,475,2);setcolor(15);line(421,25,475,25);line(475,2,475,25);setwritemode(1);showHelp();setwritemode(0);setcolor(RED);rectangle(421,2,475,25);setcolor(15);setwritemode(1);DrawMouse(last_x,last_y);}}closegraph();}}。
C课设简单画图程序
![C课设简单画图程序](https://img.taocdn.com/s3/m/c3660e61b9f3f90f77c61b1f.png)
C课设简单画图程序公司内部编号:(GOOD-TMMT-MMUT-UUPTY-UUYY-DTTI-简单画图程序1.基本功能描述本次课程设计的任务是利用计算机和VC开发环境编写一个简单画图程序,该程序的设计指标(即主要功能)有:①用鼠标拖动绘制圆、椭圆、矩形,线等基本图形;②能控制画笔的线宽和颜色;③能对图形进行颜色填充;④在鼠标移动的过程中能实时显示当前绘制的图形。
除了以上几点功能,我有另外添加了工具栏、铅笔、橡皮等功能来使程序更方便地让用户使用,简化了人机交互的过程。
2.设计思路首先是界面的问题,既然课设的题目是简单画图,那在建立工程的时候就要选择文档结构而不是以前做的基于对话框。
可选择单文档结构或多文档结构,但想到画图界面一般只有一个,从简洁的角度考虑,选择单文档结构。
而且用户界面在设计的时候要尽可能简单美观,一目了然,对相应功能有图标提示,使用户方便使用。
然后便是画图功能的具体实现。
分析课设要求,可以发现功能一要求的的椭圆、矩形、直线可以分别通过Ellipse();、Rectangle();、MoveTo();、LineTo();这四个函数来实现。
功能二控制画笔线宽和颜色可以给二者分别关联参数,通过改变线宽参数值来控制线宽,通过调用通用对话框改变颜色参数值来控制颜色。
功能三对图形进行颜色填充虽以前未接触过,但查阅资料后发现可以调用ExtFloodFill();并合理设定参数值来实现。
功能四的实时显示功能可以通过调用MouseMove();函数来实现。
这些功能需要建立菜单资源来表示各个功能选项,并建立相应的消息响应函数来进行实现。
另外,画图程序主要是通过鼠标来进行操作,所以要对鼠标消息的响应及处理函数多下功夫来思考和编写。
至于额外添加的功能,工具栏通过添加工具栏资源和关联相应菜单中画图功能ID实现;铅笔、橡皮的功能则是利用MouseMove();函数,在其中做了一些改动来实现。
2.1.程序流程图:图1 程序流程图3.软件设计3.1.设计步骤1)打开VS2010,选择新建项目,选中MFC应用程序,标题为CWN_Graphic;2)选择单文档结构,其他为默认值,点击完成。
利用C语言画图例子
![利用C语言画图例子](https://img.taocdn.com/s3/m/4ba694de760bf78a6529647d27284b73f24236f9.png)
利用C语言画图例子利用C语言画图例子1)/*#include // 就是需要引用这个图形库 #includevoid main()#include#includevoid main(){initgraph(640, 480); // 这里和 TC 略有区别circle(200, 200, 100); // 画圆,圆心(200, 200),半径100 getch(); // 按任意键继续closegraph(); // 关闭图形界面printf("***\n");}*/2)/*#include#include#includevoid main(){// 设置随机函数种子srand((unsigned) time(NULL));// 初始化图形模式initgraph(640, 480);int x, y;char c;setfont(16, 8, "Courier"); // 设置字体while(!kbhit()){for (int i=0; i<479; i++){setcolor(GREEN);for (int j=0; j<3; j++){x = (rand() % 80) * 8;y = (rand() % 20) * 24;c = (rand() % 26) + 65; outtextxy(x, y, c);}setcolor(0);line(0,i,639,i);Sleep(10);if (kbhit()) break;}}// 关闭图形模式closegraph();}*/3)/*#include#include#include#define MAXSTAR 200 // 星星总数struct STARdouble x;int y;double step;int color;};STAR star[MAXSTAR];// 初始化星星void InitStar(int i){star[i].x = 0;star[i].y = rand() % 480;star[i].step = (rand() % 5000) / 1000.0 + 1; star[i].color = (int)(star[i].step * 255 / 6.0 + 0.5); // 速度越快,颜色越亮star[i].color = RGB(star[i].color, star[i].color, star[i].color);}// 移动星星void MoveStar(int i){// 擦掉原来的星星putpixel((int)star[i].x, star[i].y, 0);// 计算新位置star[i].x += star[i].step;if (star[i].x > 640) InitStar(i);// 画新星星putpixel((int)star[i].x, star[i].y, star[i].color); }// 主函数void main()srand((unsigned)time(NULL)); // 随机种子initgraph(640, 480); // 打开图形窗口// 初始化所有星星for(int i=0; i<="" p="">{InitStar(i);star[i].x = rand() % 640;}// 绘制星空,按任意键退出while(!kbhit()){for(int i=0; i<="" p="">MoveStar(i);Sleep(20);}closegraph(); // 关闭图形窗口}*/4)/*#include#includevoid main(){float H, S, L;initgraph(640, 480);// 画渐变的天空(通过亮度逐渐增加)H = 190; // 色相S = 1; // 饱和度L = 0.7f; // 亮度for(int y = 0; y < 480; y++){L += 0.0005f;setcolor( HSLtoRGB(H, S, L) );line(0, y, 639, y);}// 画彩虹(通过色相逐渐增加)H = 0;S = 1;L = 0.5f;setlinestyle(PS_SOLID, NULL, 2); // 设置线宽为 2 for(int r = 400; r > 344; r--){H += 5;setcolor( HSLtoRGB(H, S, L) );circle(500, 480, r);}getch();closegraph();}*/5)#include#includevoid main(){// 初始化图形窗口initgraph(640, 480);MOUSEMSG m; // 定义鼠标消息while(true){// 获取一条鼠标消息m = GetMouseMsg();switch(m.uMsg){case WM_MOUSEMOVE:// 鼠标移动的时候画红色的小点putpixel(m.x, m.y, RED);break;case WM_LBUTTONDOWN:// 如果点左键的同时按下了 Ctrl 键if (m.mkCtrl)// 画一个大方块rectangle(m.x-10, m.y-10, m.x+10, m.y+10); else// 画一个小方块rectangle(m.x-5, m.y-5, m.x+5, m.y+5); break;case WM_RBUTTONUP:return; // 按鼠标右键退出程序}}// 关闭图形窗口closegraph();}。
(精选)用C语言实现键盘画图
![(精选)用C语言实现键盘画图](https://img.taocdn.com/s3/m/781eab104b73f242336c5f9e.png)
用C语言实现键盘画图1.引言笔者在开发县级电网调度自动化系统的过程中,碰到一个要绘制电力系统一次接线图的问题。
由于电力系统一次接线图比较复杂,图上有一些特殊的符号,象变压器符号、开关符号等等,用一般的编程方法来绘制比较困难,因此,笔者用C 语言开发了一个手工绘制电力系统一次接线图的键盘绘图程序,使用该程序绘制的一次接线图符合用户需求,效果良好。
2.使用方法程序中定义了几个特殊键:"V”:画笔提起"W”:开始画图"R”:开始擦图"S”:当前图形存入文件"E”:调出已有文件"C”:画圆程序一运行,屏幕上出现一个黄色的边框来设定画图的区域,区域中间出现提起的画笔符号,当按下”W“键时,画笔符号变为,此时可移动方向键(上、下、左、右、左上、左下、右上、右下)来画图;当按下”R“键时,画笔符号变为,此时可移动方向键来擦图;在画图过程中,按下“C”键,可画出一个半径为20个象素点的圆;当结束画图时,按下“S”键,将画好的图形存盘;按下“E”键可调出已有的图形进行编辑。
3.源程序清单# include "graphics.h"# include "stdio.h"# include "fcntl.h"# include "stdlib.h"main()void save(),load();void *wg,*rg,*vg,*fy;int driver,mode;int c=RED;int x=320,y=225;int x1,y1,x2,y2;int k,k1,k2;/* initialize grapher */ detectgraph(&driver,&mode); initgraph(&driver,&mode,"c:\tc");/* write the pen */bar(200,10,206,16);line(203,7,200,10);line(203,7,206,10);line(243,7,240,16);line(243,7,246,16);line(283,7,280,10);line(283,7,286,10);line(283,7,283,16);/* save the pen */wg=malloc(imagesize(200,7,206,16)); rg=malloc(imagesize(240,7,246,16)); vg=malloc(imagesize(280,7,286,16)); fy=malloc(imagesize(200,7,206,16));getimage(200,7,206,16,wg); getimage(240,7,246,16,rg); getimage(280,7,286,16,vg); cleardevice();/* write the box */setcolor(YELLOW);rectangle(4,19,637,447);x1=x-3;y1=y+1;x2=x+3;y2=y+10;getimage(x1,y1,x2,y2,fy);putimage(x1,y1,vg,XOR_PUT);/* receive the command */for (;;)while (bioskey(1)==0);k=bioskey(0);putimage(x1,y1,fy,AND_PUT);if (((k&0x00ff)|0x00)==0)k1=k&0xff?0:k>>8; /* k1 is the specialkey value */ elsek2=k&0x00ff; /* k2 is the non-specialkey value */ if (((k&0x00ff)|0x00)==0) /* Special key */switch(k1)case 45:restorecrtmode();exit(0);case 72:if (y>20)y=y-1;break;case 75:if (x>5)x=x-1;break;case 77:if (x<636)x=x+1;break;case 80:if (y<446)y=y+1;break;case 71:if ((x>5)&&(y>20))x=x-1;y=y-1;break;case 79:if ((x>5)&&(y<446))x=x-1;y=y+1;break;case 73:if ((x<636)&&(y>20))x=x+1;y=y-1;break;case 81:if ((x<636)&&(y<446))x=x+1;y=y+1;break;x1=x-3;y1=y+1;x2=x+3;y2=y+10;getimage(x1,y1,x2,y2,fy);/* non-special key */switch(k2)case 118: /* 'v' */case 86: /* 'V' */putimage(x1,y1,vg,OR_PUT);break;case 119: /* 'w' */case 87: /* 'W' */putimage(x1,y1,wg,OR_PUT);putpixel(x,y,c);break;case 114: /* 'r' */case 82: /* 'R' */putimage(x1,y1,rg,OR_PUT);putpixel(x,y,BLACK);break;case 115: /* 's' */case 83: /* 'S' */save("pic.dat");break;case 101: /* 'e' */case 69: /* 'E' */load("pic.dat");break;case 99: /*'c'*/case 67: /*'C'*/setcolor(RED);circle(x,y,20);break;default:continue;/* function for screen picture save */void save(char *fname)FILE *fp;int i;register long j;char far *ptr;fp=fopen(fname,"wb");for(i=0;i<4;i++)outportb(0x3CE,4);outportb(0x3CF,i);ptr=(char far *) 0xA0000000L;for (j=0;j<38400L;j++)putc(*ptr,fp);ptr++;fclose(fp);outportb(0x3CF,0);/* function for screen picture display */void load(char *fname)FILE *fp;register int i;int k4=1;register long j;char far *ptr;fp=fopen(fname,"rb");for (i=0;i<4;i++)outportb(0x3C4,2);outportb(0x3C5,k4);ptr=(char far *)0xA0000000L;for (j=0;j<38400L;j++)*ptr=getc(fp);ptr++;k4*=2;fclose(fp);outportb(0x3C5,0xF);4.结束语该程序在Turbo C 2.0环境下运行通过,使用效果良好。
利用VC编写简单的绘图程序
![利用VC编写简单的绘图程序](https://img.taocdn.com/s3/m/bdac7644a9956bec0975f46527d3240c8447a10d.png)
利用VC编写简单的绘图程序上机实验环境亦可选择Microsoft Visual C++〔以下简称VC〕。
VC是美国微软公司生产的基于其Windows系统的软件开发工具。
它具有使用灵活,并与32位Windows内核〔使用于Windows 2000/Windows XP〕高度兼容的特点,从而被Windows程序员们广泛使用。
VC 在图形图像处理方面有着广泛的应用,MFC中提供了大量的图形图像函数,下面我们将对使用VC/MFC编写简单的绘图程序。
一、使用VC编写MFC单文档应用程序很简单,只需要按照下面几个步骤进行:1.翻开MSVC集成开发环境。
双击桌面或“开始〞菜单中的Microsoft VisualC++6.0,不久将看到VC的编辑窗口,如图3-5:图1 VC启动界面2.选择菜单“File | New〞,在弹出的对话框中1)单击上方的选项卡“Project〞,2)选择“MFC AppWizard(exe)〞,3)在“Project name〞一栏中填写工程名,例如draw,4)在“Location〞一栏中填写你想把文件存放的位置〔目录〕。
然后按“OK〞。
见图2。
注意:第4〕步中指定你自己的目录,不要使用系统的缺省目录或者随便放在根目录或者其他的目录下。
这样便于你找到自己编写的程序。
图2 应用程序向导主界面3.在MFC Appwizard-Step 1中选择“Single Document〞,即单文档应用程序,点击“Finish〞,如图3所示。
注意:对于下面的操作我们可以忽略,直接点Finish即可。
图3 应用程序向导中选择单文档视图4.系统弹出一个当前工程信息的对话框,如图4所示,直接点“OK〞即可。
图4 新建工程信息5.进入程序编写的主界面,屏幕左下方为工作区,如图5所示,工作区中共有三种视图,分别是:1)文件视图〔“FileView〞〕,主要包括头文件,cpp文件以及资源文件。
我们在头文件中一般添加类的定义,类的成员变量和函数的声明,而在cpp文件中具体实现函数。
c语言绘图 游戏简易教程
![c语言绘图 游戏简易教程](https://img.taocdn.com/s3/m/c716633110661ed9ad51f345.png)
第一步,编写源代码作为例子,我们编写了一个输出"Hello World" 的程序。
该程序将连续输出10 遍该字符串,并且在每一次输出前首先打印一个序号。
第二步,打开“编译”工具栏这一步并非是必要的。
如果编译工具栏已经打开,或者您决定通过菜单而不是工具来进行操作,并没有必要打开工具栏。
菜单命令和工具栏快捷按钮一般是可以替代的。
使用鼠标右键单击工具栏的空白处,在弹出的菜单中选中“Build(编译)”一项,就可以打开编译工具栏。
在该工具栏中,我们可以选择"Debug"模式,或者"Release"模式进行编译。
在调试程序的过程中,我们一般选择Debug 模式。
如果使用菜单,可以选择:Build --> Build DemoQuestion.exe F7或者:Build --> Rebuild All如果使用工具栏,可以选择如下图中的按钮:如果编译完全成功,会显示"0 error(s), 0 warning(s)"。
另外,即便有一些warning,也可能编译成功。
Warning 表示该代码可能会影响程序运行,虽然可以运行,但有可能存在潜在的问题,编译器不推荐这么写。
一般情况下,代码在编写过程中必然会发生各种错误。
编译器检查出来的错误会被显示在VC 6.0 环境的Build 窗口。
如下图所示,编译器提示:在Question.c的第10行,发生了C2065 错误,变量j 从没有被声明就被使用了。
我们发现上面的错误是因为误把i 写成了j,只要改回来,这个错误就被修改好了。
运行程序单击Build 工具栏中的红色感叹号按钮,就可以运行一个编译好的程序:如果该程序在上一次被编译后又被修改,下面窗口将会弹出,问我们是否要把最新的代码重新编译。
我们一般都选择"Yes"。
随后该程序就会在一个新弹出的窗口中被运行。
C#经典实例----画图程序
![C#经典实例----画图程序](https://img.taocdn.com/s3/m/1ab51919ff00bed5b9f31d74.png)
这是一个简单的画图程序其源码是:using System.Drawing;using System;using System.Windows.Forms; using System.Drawing.Imaging; namespace WindowsApplication1 {partial class Form1{///<summary>///必需的设计器变量。
///</summary>private ponentModel.IContainer components = null;///<summary>///清理所有正在使用的资源。
///</summary>///<param name="disposing">如果应释放托管资源,为true;否则为 false。
</param>protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}public Form1(){InitializeComponent();}#region Windows 窗体设计器生成的代码///<summary>///设计器支持所需的方法 - 不要///使用代码编辑器修改此方法的内容。
///</summary>private void InitializeComponent(){ponents = newponentModel.Container();this.menuStrip1 = newSystem.Windows.Forms.MenuStrip();this.文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();this.Open = newSystem.Windows.Forms.ToolStripMenuItem();this.NEW = newSystem.Windows.Forms.ToolStripMenuItem();this.saveFile = newSystem.Windows.Forms.ToolStripMenuItem();this.Exist = newSystem.Windows.Forms.ToolStripMenuItem();this.编辑颜色ToolStripMenuItem = newSystem.Windows.Forms.ToolStripMenuItem();this.关于ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();this.toolTip1 = newSystem.Windows.Forms.ToolTip(ponents);this.menuStrip2 = newSystem.Windows.Forms.MenuStrip();this.画笔工具ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();this.画直线ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();this.画椭圆ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();this.画矩形ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();this.橡皮擦ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();this.鼠标ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();this.saveFiles = newSystem.Windows.Forms.SaveFileDialog();this.openFiles = newSystem.Windows.Forms.OpenFileDialog();this.panel1 = new System.Windows.Forms.Panel();bel1 = new bel();this.button1 = newSystem.Windows.Forms.Button();this.menuStrip1.SuspendLayout();this.menuStrip2.SuspendLayout();this.panel1.SuspendLayout();this.SuspendLayout();//// menuStrip1//this.menuStrip1.Items.AddRange(newSystem.Windows.Forms.ToolStripItem[] {this.文件ToolStripMenuItem,this.编辑颜色ToolStripMenuItem,this.关于ToolStripMenuItem});this.menuStrip1.Location = newSystem.Drawing.Point(0, 0); = "menuStrip1";this.menuStrip1.Size = newSystem.Drawing.Size(305, 24);this.menuStrip1.TabIndex = 0;this.menuStrip1.Text = "menuStrip1";//// 文件ToolStripMenuItem//this.文件ToolStripMenuItem.DropDownItems.AddRange(newSystem.Windows.Forms.ToolStripItem[] {this.Open,this.NEW,this.saveFile,this.Exist});this.文件 = "文件ToolStripMenuItem";this.文件ToolStripMenuItem.Size = newSystem.Drawing.Size(43, 20);this.文件ToolStripMenuItem.Text = "文件";//// Open// = "Open";this.Open.Size = new System.Drawing.Size(98, 22);this.Open.Text = "打开";this.Open.Click += newSystem.EventHandler(this.Open_Click);//// NEW// = "NEW";this.NEW.Size = new System.Drawing.Size(98, 22);this.NEW.Text = "新建";this.NEW.Click += newSystem.EventHandler(this.NEW_Click);//// saveFile// = "saveFile";this.saveFile.Size = new System.Drawing.Size(98, 22);this.saveFile.Text = "保存";this.saveFile.Click += newSystem.EventHandler(this.saveFile_Click);//// Exist// = "Exist";this.Exist.Size = new System.Drawing.Size(98, 22);this.Exist.Text = "退出";this.Exist.Click+= newSystem.EventHandler(this. Exist_Click);//// 编辑颜色ToolStripMenuItem//this.编辑颜色 = "编辑颜色ToolStripMenuItem";this.编辑颜色ToolStripMenuItem.Size = new System.Drawing.Size(67, 20);this.编辑颜色ToolStripMenuItem.Text = "编辑颜色";this.编辑颜色ToolStripMenuItem.Click += new System.EventHandler(this.编辑颜色ToolStripMenuItem_Click);//// 关于ToolStripMenuItem//this.关于 = "关于ToolStripMenuItem";this.关于ToolStripMenuItem.Size = new System.Drawing.Size(43, 20);this.关于ToolStripMenuItem.Text = "关于";this.关于ToolStripMenuItem.Click += new System.EventHandler(this.关于ToolStripMenuItem_Click);//// toolTip1//this.toolTip1.ShowAlways = true;//// menuStrip2//this.menuStrip2.Dock =System.Windows.Forms.DockStyle.Bottom;this.menuStrip2.Enabled = false;this.menuStrip2.GripStyle =System.Windows.Forms.ToolStripGripStyle.Visible;this.menuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.画笔工具ToolStripMenuItem,this.画直线ToolStripMenuItem,this.画椭圆ToolStripMenuItem,this.画矩形ToolStripMenuItem,this.橡皮擦ToolStripMenuItem,this.鼠标ToolStripMenuItem});this.menuStrip2.Location = newSystem.Drawing.Point(0, 332); = "menuStrip2";this.menuStrip2.Size = newSystem.Drawing.Size(305, 24);this.menuStrip2.TabIndex = 1;this.menuStrip2.Text = "menuStrip2";this.menuStrip2.ItemClicked += newSystem.Windows.Forms.ToolStripItemClickedEventHandler(this. menuStrip2_ItemClicked);//// 画笔工具ToolStripMenuItem//this.画笔工具 = "画笔工具ToolStripMenuItem";this.画笔工具ToolStripMenuItem.Size = new System.Drawing.Size(43, 20);this.画笔工具ToolStripMenuItem.Text = "画笔";//// 画直线ToolStripMenuItem//this.画直线 = "画直线ToolStripMenuItem";this.画直线ToolStripMenuItem.Size = new System.Drawing.Size(55, 20);this.画直线ToolStripMenuItem.Text = "画直线";//// 画椭圆ToolStripMenuItem//this.画椭圆 = "画椭圆ToolStripMenuItem";this.画椭圆ToolStripMenuItem.Size = new System.Drawing.Size(55, 20);this.画椭圆ToolStripMenuItem.Text = "画椭圆";//// 画矩形ToolStripMenuItem//this.画矩形 = "画矩形ToolStripMenuItem";this.画矩形ToolStripMenuItem.Size = new System.Drawing.Size(55, 20);this.画矩形ToolStripMenuItem.Text = "画矩形";//// 橡皮擦ToolStripMenuItem//this.橡皮擦 = "橡皮擦ToolStripMenuItem";this.橡皮擦ToolStripMenuItem.Size = new System.Drawing.Size(55, 20);this.橡皮擦ToolStripMenuItem.Text = "橡皮擦";//// 鼠标ToolStripMenuItem//this.鼠标 = "鼠标ToolStripMenuItem";this.鼠标ToolStripMenuItem.Size = new System.Drawing.Size(43, 20);this.鼠标ToolStripMenuItem.Text = "鼠标";//// openFiles//this.openFiles.FileName = "图像文件";//// panel1//this.panel1.Controls.Add(bel1);this.panel1.Controls.Add(this.button1);this.panel1.Location = newSystem.Drawing.Point(12, 59); = "panel1";this.panel1.Size = new System.Drawing.Size(281, 131);this.panel1.TabIndex = 2;this.panel1.Visible = false;//// label1//bel1.AutoSize = true;bel1.Location = newSystem.Drawing.Point(3, 29); = "label1";bel1.Size = new System.Drawing.Size(275, 12);bel1.TabIndex = 1;bel1.Text = "更多资料到查看?/zhouxiaoming";//// button1//this.button1.Location = newSystem.Drawing.Point(121, 105); = "button1";this.button1.Size = new System.Drawing.Size(75, 23);this.button1.TabIndex = 0;this.button1.Text = "关闭";eVisualStyleBackColor = true;this.button1.Click += newSystem.EventHandler(this.button1_Click);//// Form1//this.AutoScaleDimensions = newSystem.Drawing.SizeF(6F, 12F);this.AutoScaleMode =System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(305, 356);this.Controls.Add(this.panel1);this.Controls.Add(this.menuStrip1);this.Controls.Add(this.menuStrip2);this.Cursor =System.Windows.Forms.Cursors.Default;this.MainMenuStrip = this.menuStrip1; = "Form1";this.Text = "Form1";this.Paint += newSystem.Windows.Forms.PaintEventHandler(this.Form1_Paint);this.SizeChanged += newSystem.EventHandler(this.Form1_SizeChanged);this.MouseUp += newSystem.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);this.MouseMove += newSystem.Windows.Forms.MouseEventHandler(this.Form1_MouseMove );this.MouseDown += newSystem.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);this.menuStrip1.ResumeLayout(false);this.menuStrip1.PerformLayout();this.menuStrip2.ResumeLayout(false);this.menuStrip2.PerformLayout();this.panel1.ResumeLayout(false);this.panel1.PerformLayout();this.ResumeLayout(false);this.PerformLayout();}#endregionprivate System.Windows.Forms.MenuStrip menuStrip1;private System.Windows.Forms.ToolStripMenuItem文件ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem Open;private System.Windows.Forms.ToolStripMenuItem NEW;private System.Windows.Forms.ToolStripMenuItem saveFile;private System.Windows.Forms.ToolStripMenuItemExist;private System.Windows.Forms.ToolStripMenuItem编辑颜色ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem关于ToolStripMenuItem;private System.Windows.Forms.ToolTip toolTip1;private System.Windows.Forms.MenuStrip menuStrip2;private System.Windows.Forms.ToolStripMenuItem画笔工具ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem画直线ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem画矩形ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem画椭圆ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem橡皮擦ToolStripMenuItem;private System.Windows.Forms.SaveFileDialog saveFiles;private System.Windows.Forms.OpenFileDialog openFiles;private System.Windows.Forms.ToolStripMenuItem鼠标ToolStripMenuItem;private System.Windows.Forms.Panel panel1;private bel label1;private System.Windows.Forms.Button button1;///<summary>///应用程序的主入口点。
C课设简单画图程序
![C课设简单画图程序](https://img.taocdn.com/s3/m/d652e594c5da50e2524d7f8a.png)
简单画图程序1.基本功能描述本次课程设计的任务是利用计算机和VC开发环境编写一个简单画图程序,该程序的设计指标(即主要功能)有:①用鼠标拖动绘制圆、椭圆、矩形,线等基本图形;②能控制画笔的线宽和颜色;③能对图形进行颜色填充;④在鼠标移动的过程中能实时显示当前绘制的图形。
除了以上几点功能,我有另外添加了工具栏、铅笔、橡皮等功能来使程序更方便地让用户使用,简化了人机交互的过程。
2.设计思路首先是界面的问题,既然课设的题目是简单画图,那在建立工程的时候就要选择文档结构而不是以前做的基于对话框。
可选择单文档结构或多文档结构,但想到画图界面一般只有一个,从简洁的角度考虑,选择单文档结构。
而且用户界面在设计的时候要尽可能简单美观,一目了然,对相应功能有图标提示,使用户方便使用。
然后便是画图功能的具体实现。
分析课设要求,可以发现功能一要求的的椭圆、矩形、直线可以分别通过Ellipse();、Rectangle();、MoveTo();、LineTo();这四个函数来实现。
功能二控制画笔线宽和颜色可以给二者分别关联参数,通过改变线宽参数值来控制线宽,通过调用通用对话框改变颜色参数值来控制颜色。
功能三对图形进行颜色填充虽以前未接触过,但查阅资料后发现可以调用ExtFloodFill();并合理设定参数值来实现。
功能四的实时显示功能可以通过调用MouseMove();函数来实现。
这些功能需要建立菜单资源来表示各个功能选项,并建立相应的消息响应函数来进行实现。
另外,画图程序主要是通过鼠标来进行操作,所以要对鼠标消息的响应及处理函数多下功夫来思考和编写。
至于额外添加的功能,工具栏通过添加工具栏资源和关联相应菜单中画图功能ID实现;铅笔、橡皮的功能则是利用MouseMove();函数,在其中做了一些改动来实现。
.程序流程图:图1程序流程图3.软件设计.设计步骤1)打开VS2010,选择新建项目,选中MFC应用程序,标题为CWN_Graphic;2)选择单文档结构,其他为默认值,点击完成。
用C语言实现画图程序
![用C语言实现画图程序](https://img.taocdn.com/s3/m/f2c078fc941ea76e58fa0438.png)
一、选题背景:画图程序,通过画图中的功能绘制出美丽的图案。
二、设计思想:利用数学三角函数制作山峰和花朵出一条曲线、用画圆函数绘制太阳的形状、再进行颜色填充用绘制直线的函数来绘制比较粗的光线、用矩形函数画出矩形的边框、再画地球、直线画赤道、弧线画南北极和钟表的刻度盘。
三、流程图:四、程序清单:#include"graphics.h" /*调用图形库函数*/#include"math.h" /*调用数学函数*/#include"stdio.h" /*调用标准I/O函数*/#define PI 3.141596 /*宏定义PI字符串*/main() /*主函数*/{float i,x,y; /*定义单精度浮点型变量i,x,y*/int gdriver=DETECT,gmode,a=1; /*定义整型变量gdriver,gmode*/initgraph(&gdriver,&gmode,"d:\\tc"); /*定义变量后,初始化图形系统*/cleardevice();setbkcolor(a); /*背景颜色*/printf("\n");printf("\n"); /*C 语言图形函数*/printf("\n");printf(" the following math functions were used in the main function.\n");printf(" setbkcolor(int color);\n"); /* 背景颜色*/printf(" setcolor(int color);\n"); /* 画笔颜色*/printf(" putpexel(x,y,color);\n"); /* 画像素点*/printf(" line(x1,y1,x2,y2)\n"); /* 直线函数*/printf(" rectangle(xl,yt,xr,yb)\n");; /* 矩形函数*/printf(" arc(x,y,as,ae,r)\n"); /* 圆弧函数*/printf(" circle(x,y,r)\n"); /*圆形函数*/printf(" ellipse(x,y,as,ae,rx,ry)\n"); /* 椭圆函数*/printf("\n"); /* 按任意键开始演示*/setcolor(2);setlinestyle(0,0,3);rectangle(4,4,635,475); /*绘制矩形框*/getch();cleardevice();printf("\n"); /* 模拟手工画图*/printf("\n"); /* 函数曲线图形*/setcolor(3);setlinestyle(3,3,3);rectangle(4,4,635,475); /*绘制图纸边框*/for (i=0;i<=2*PI;i+=PI/99999){putpixel(40*i,170-21*i*sin(1.6*i),2);putpixel(40.3*i,170-22*i*sin(1.6*i),3);putpixel(40.6*i,170-23*i*sin(1.6*i),10);}for (i=0;i<=2*PI;i+=PI/99999) /*绘制花朵*/{putpixel(118-15*cos(4*i)*cos(i),160-15*cos(4*i)*sin(i),14);putpixel(118-25*cos(4*i)*cos(i),160-25*cos(4*i)*sin(i),13);putpixel(118-35*cos(4*i)*cos(i),160-35*cos(4*i)*sin(i),10);}for (i=0;i<=PI;i+=PI/99999){putpixel(320-315*cos(i),360-95*sin(i),11); /*绘制拱桥*/ putpixel(320-315*cos(i),360-96*sin(i),11); /*绘制拱桥*/ putpixel(320-315*cos(i),360-97*sin(i),11); /*绘制拱桥*/ }for (a=70;a<=570;a+=50)for (i=0;i<=PI;i+=PI/9999){putpixel(a-25*cos(i),360-40*sin(i),11); /*绘制桥*/}}for (x=0;x<=640;x+=0.001){putpixel(8*x,380-8*sin(x),9); /*绘制曲线水流*/}for (x=0;x<=600;x+=0.001){putpixel(10*x,405-10*sin(x),9); /*绘制曲线水流*/}for (x=0;x<=560;x+=0.001){putpixel(12*x,430-12*sin(x),9); /*绘制曲线水流*/}for(x=60;x<=80;x+=0.01){ellipse(270,360,180 ,0,160-x,25);}for (x=0;x<=520;x+=0.001){putpixel(8*x,455-8*sin(x),9); /*绘制曲线水流*/}setlinestyle(0,0,1);setfillstyle(1,12);fillellipse(320,60,25,25); /*绘制太阳*/for (x=280;x>=250;x-=0.0001)putpixel(x,60,12); /*绘制阳光线*/}for (x=360;x>=390;x+=0.0001){putpixel(x,60,12); /*绘制阳光线*/}for (y=24;y>=12;y-=0.0001){putpixel(320,y,12); /*绘制阳光线*/}for (y=96;y<=108;y+=0.0001){putpixel(320,y,12); /*绘制阳光线*/}setlinestyle(3,0,1);setcolor(12);for (i=0;i<=2*PI;i+=PI/12) /*绘制阳光线*/{line(320+40*cos(i),60-36*sin(i),320+70*cos(i),60-48*sin(i)); for (x=0;x<=55555;x+=0.1){y=y+x; /*延时控制*/}}setcolor(13);setlinestyle(0,0,1);rectangle(460,100,620,200); /*绘制地图框(矩形)*/ setcolor(11);setlinestyle(0,0,3);ellipse(540,150,0,360,77,48); /*绘制地球(椭圆)*/circle(540,150,46); /*绘制经线(圆形)*/ellipse(540,100,210,330,45,16); /*绘制北极圈(椭圆弧)*/ellipse(540,200,30,150,45,16); /*绘制南极圈(椭圆弧)*/setcolor(14);setlinestyle(3,0,1);line(460,150,620,150); /*绘制赤道(水平线)*/line(540,100,540,200); /*绘制经线(垂直线)*/setcolor(11); setlinestyle(0,0,1);for (i=0;i<=2*PI;i+=PI/300){putpixel(590-35*cos(i),50-35*sin(i),11); /*绘制0.1秒刻度*/}setcolor(14);setlinestyle(0,0,1);circle(590,50,2); /*绘制中心轴*/setcolor(13);setlinestyle(0,0,3);for (i=0;i<=2*PI;i+=PI/6){line(590+25*sin(i),50-25*cos(i),590+30*sin(i),50-30*cos(i));/*绘制小时*/for (x=0;x<=5555;x+=0.001){y=y+x; /*延时控制*/}getch();closegraph(); }五、主要解决问题的方法及技术关键1、主要问题及解决方法✓抛物线的画法用插补法画抛物线。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
/*绘制阳光线*/
/*绘制阳光线*/
/*绘制阳光线*/
/*绘制阳光线*/
/*绘制阳光线*/
line(320+40*cos(i),60-36*sin(i),320+70*cos(i),60-48*sin(i)); for (x=0;x<=55555;x+=0.1) { y=y+x; } } setcolor(13); setlinestyle(0,0,1); rectangle(460,100,620,200); setcolor(11); setlinestyle(0,0,3); ellipse(540,150,0,360,77,48); setcolor(10); setlinestyle(0,0,1); /*绘制地球(椭圆)*/ /*绘制地图框(矩形)*/ /*延时控制*/
ü 抛物线的画法 用插补法画抛物线。 ü 调色板的设置 用 set_pattern()函数设置调色板,将颜色寄存器设置成需要的值。
2、
技术关键
ü 使用 BIOS 中断 INT 10H 的功能随机生成图案。 ü INT 10H 的颜色块设定于图片生成等。
六、设计结果说明
1、设计优点:本程序实现了根据给定的起点及旋转角度,用指定的颜色画图。
2、设计不足: 某些地方的颜色还有些不足,要想效果更加好,还需加以改正。
PDF 文件使用 "pdfFactory Pro" 试用版本创建
/* 按任意键开始演示*/
/*绘制矩形框*/
/* 模拟手工画图*/ /* 函数曲线图形*/
/*绘制图纸边框*/
putpixel(40.6*i,170-23*i*sin(1.6*i),10); } for (i=0;i<=2*PI;i+=PI/99999) { putpixel(118-15*cos(4*i)*cos(i),160-15*cos(4*i)*sin(i),14); putpixel(118-25*cos(4*i)*cos(i),160-25*cos(4*i)*sin(i),13); putpixel(118-35*cos(4*i)*cos(i),160-35*cos(4*i)*sin(i),10); } for (i=0;i<=PI;i+=PI/99999) { putpixel(320-315*cos(i),360-95*sin(i),11); putpixel(320-315*cos(i),360-96*sin(i),11); putpixel(320-315*cos(i),360-97*sin(i),11); } for (a=70;a<=570;a+=50) { /*绘制拱桥*/ /*绘制拱桥*/ /*绘制拱桥*/ /*绘制花朵*/
printf(" setcolor(int color);\n"); printf(" putpexel(x,y,color);\n"); printf(" line(x1,y1,x2,y2)\n"); printf(" rectangle(xl,yt,xr,yb)\n");; printf(" arc(x,y,as,ae,r)\n"); printf(" circle(x,y,r)\n"); printf(" ellipse(x,y,as,ae,rx,ry)\n"); printf("\n");
PDF 文件使用 "pdfFactory Pro" 试用版本创建
getch(); closegraph(); }
PDF 文件使用 "pdfFactory Pro" 试用版本创建
五、主要解决问题的方法及技术关键
1、 主要问题及解决方法
一、选题背景:
画图程序,通过画图中的功能绘制出美丽的图案。
二、设计思想:
利用数学三角函数制作山峰和花朵 出一条曲线、 用画圆函数绘制太阳的形 状、再进行颜色填充用绘制直线的函数来绘制比较粗的光线、用矩形函数画出矩 形的边框、再画地球、直线画赤道、弧线画南北极和钟表的刻度盘。
PDF 文件使用 "pdfFactory Pro" 试用版本创建
PDF 文件使用 "pdfFactory Pro" 试用版本创建
for (i=0;i<=PI;i+=PI/9999) { putpixel(a-25*cos(i),360-40*sin(i),11); /*绘制桥*/ } } for (x=0;x<=640;x+=0.001) { putpixel(8*x,380-8*sin(x),9); } for (x=0;x<=600;x+=0.001) { putpixel(10*x,405-10*sin(x),9); } for (x=0;x<=560;x+=0.001) { putpixel(12*x,430-12*sin(x),9); } for(x=60;x<=80;x+=0.01) { ellipse(270,360,180 ,0,160-x,25); } for (x=0;x<=520;x+=0.001) { putpixel(8*x,455-8*sin(x),9); } setlinestyle(0,0,1); setfillstyle(1,12); fillellipse(320,60,25,25); for (x=280;x>=250;x-=0.0001) { /*绘制太阳*/ /*绘制曲线水流*/ /*绘制曲线水流*/ /*绘制曲线水流*/ /*绘制曲线水流*/
四、程序清单:
#include"graphics.h" #include"math.h" #include"stdio.h" #define PI 3.141596 main() { float i,x,y; i,x,y*/ int gdriver=DETECT,gmode,a=1; gdriver,gmode*/ initgraph(&gdriver,&gmode,"d:\\tc"); 统*/ cleardevice(); setbkcolor(a); printf("\n"); printf("\n"); printf("\n"); printf(" the following math functions were used in the main function.\n"); printf(" setbkcolor(int color);\n"); /* /* 背景颜色*/ 画笔颜色*/ /*C 语言图形函数*/ /*背景颜色*/ /*定义变量后,初始化图形系 /* 定 义 整 型 变 量 /*定义单精度浮点型变量 /*调用图形库函数*/ /*调用数学函数*/ /*调用标准 I/O 函数*/ /*宏定义 PI 字符串*/ /*主函数*/
/* 画像素点*/ /* 直线函数*/ /* 矩形函数*/ /* 圆弧函数*/
/*圆形函数*/ /* 椭圆函数*/
PDF 文件使用 "pdfFactory Pro" 试用版本创建
printf("\n"); setcolor(2); setlinestyle(0,0,3); rectangle(4,4,635,475); getch(); cleardevice(); printf("\n"); printf("\n"); setcolor(3); setlinestyle(3,3,3); rectangle(4,4,635,475); for (i=0;i<=2*PI;i+=PI/99999) { putpixel(40*i,170-21*i*sin(1.6*i),2); putpixel(40.3*i,170-22*i*sin(1.6*i),3);
PDF 文件使用 "pdfFactory Pro" 试用版本创建
putpixel(x,60,12); } for (x=360;x>=390;x+=0.0001) { putpixel(x,60,12); } for (y=24;y>=12;y-=0.0001) { putpixel(320,y,12); } for (y=96;y<=108;y+=0.0001) { putpixel(320,y,12); } setlinestyle(3,0,1); setcolor(12); for (i=0;i<=2*PI;i+=PI/12) {
PDF 文件使用 "pdfFactory Pro" 试用版本创建
circle(540,150,46); ellipse(540,100,210,330,45,16); 弧)*/ ellipse(540,200,30,150,45,16); 弧)*/ setcolor(14); setlinestyle(3,0,1); line(460,150,620,150); 线)*/ line(540,100,540,200); 线)*/ setcolor(11); setlinestyle(0,0,1); for (i=0;i<=2*PI;i+=PI/300) { putpixel(590-35*cos(i),50-35*sin(i),11); */ } setcolor(14); setlinestyle(0,0,1); circle(590,50,2); setcolor(13); setlinestyle(0,0,3); for (i=0;i<=2*PI;i+=PI/6) {