C语言图形开发库函数graphics
- 格式:doc
- 大小:354.50 KB
- 文档页数:8
C语⾔图形开发函数graphics 函数名: fillellipse功能: 画出并填充⼀椭圆⽤法: void far fillellipse(int x, int y, int xradius, int yradius); 程序例: #include#includeint main(void){int gdriver = DETECT, gmode;int xcenter, ycenter, i;initgraph(&gdriver,&gmode,"");xcenter = getmaxx() / 2;ycenter = getmaxy() / 2;for (i=0; i<13; i++){setfillstyle(i,WHITE);fillellipse(xcenter,ycenter,100,50);getch();}closegraph();return 0;}Graphics 类.NET Framework 类库Graphics 类封装⼀个GDI+ 绘图图⾯。
⽆法继承此类。
命名空间:System.Drawing程序集:System.Drawing(在system.drawing.dll 中)语法Visual Basic(声明)Public NotInheritable Class GraphicsInherits MarshalByRefObjectImplements IDeviceContext, IDisposableVisual Basic(⽤法)Dim instance As GraphicsC#public sealed class Graphics : MarshalByRefObject, IDeviceContext, IDisposableC++public ref class Graphics sealed : public MarshalByRefObject, IDeviceContext, IDisposableJ#public final class Graphics extends MarshalByRefObject implements IDeviceContext, IDisposableJScriptpublic final class Graphics extends MarshalByRefObject implements IDeviceContext, IDisposable备注Graphics类提供将对象绘制到显⽰设备的⽅法。
C语言图形编程一、字符屏幕一、屏幕操作函数1. clrscr()清除字符窗口函数2. window()字符窗口函数3. gotoxy()光标定位函数4. clreol() 清除光标行尾字符函数5. insline() 插入空行函数6. delline() 删除一行函数7. gettext() 拷进文字函数8. puttext() 拷出文字函数9. movetext() 移动文字函数二、字符属性函数10. textmode() 文本模式函数11. highvideo()高亮度函数12. lowvideo() 低亮度函数13. normvideo(void);14. textcolor() 文本颜色函数15. textattr() 文本属性函数16.textbackground() 文本背景函数三、屏显状态函数17. wherex() 光标处x坐标函数18. wherey() 光标处y坐标函数19. gettextinfo() 获取文本窗口信息函数在Borland C++里面提供了字符屏幕和图形函数。
字符屏幕的核心是窗口(Window),它是屏幕的活动部分,字符输出或显示在活动窗口中进行。
窗口在缺省时,就是整个屏幕。
窗口可以根据需要指定其大小。
同样,对图形函数的操作,也提供了(Viewport)。
也就是说图形函数的操作都是在视口上进行。
图形视口与字符窗口具有相同的特性,用户可以在屏幕上定义大小不同的视口,若不定义视口大小,它就是整个屏幕。
窗口是在字符屏幕下的概念,只有字符才能在窗口中显示出来,这时用户可以访问的最小单位为一个字符。
视口是在图形屏幕状态下的概念,文本与图形都可以在视口上显示,用户可访问的最小单位是一个像素(像素这一术语最初用来指显示器上最小的、单独的发光点单元。
然而现在,其含义拓宽为指图形显示器上的最小可访问点)。
字符和图形状态下,屏幕上的位置都是由它们的行与列所决定的。
有一点须指出:字符状态左上角坐标为(1,1),但图形左上角坐标为(0,0)。
C语言画图函数与图形有关的函数GRAPHICS.H 库文件bar【功能】画出一条栏目。
【原型】void far bar(int left,int top,int right,int bottom)【位置】graphics.hgraphics.h【参见】bar3d,setfillstyle,rectanglebar3d【功能】画出一条3-D栏目。
【原型】void far bar3d(int left,int top,int right,int bottom,int depth,int topflag) 【位置】graphics.h【参见】barcircle【功能】以(x,y)为圆心按照指定的半径画出一个圆。
【原型】void far circle(int x,int y,int radius)【位置】graphics.h【参见】arccleardevice【功能】清除图形画面。
【原型】void far cleardevice(void)【位置】graphics.h【参见】clearviewportclearviewport【功能】清除当前可视区域。
【原型】clearviewport(void)【位置】graphics.h【参见】setviewport,cleardeviceclosegraph【功能】关闭图形系统。
【原型】void far closegraph(void)【位置】graphics.h【参见】initgraphdetecgraph【功能】通过检查硬件确定使用的图形驱动程序和模式。
【原型】void far detectgraph(int far *graphdriver,int far *graphmode)【位置】graphics.h【参见】initgraph,graphresultdrawpoly【功能】画出一个多边形的轮廓。
【原型】void far drawpoly(int numpoints,int far polypoints[])【位置】graphics.h【说明】polypoints中包括一共numpoints对数值。
C语言中的画图函数基本图形函数包括画点,线以及其它一些基本图形的函数。
本节对这些函数作一全面的介绍。
1、画点I. 画点函数 void far putpixel(int x, int y, int color);该函数表示有指定的象元画一个按color 所确定颜色的点。
对于颜色color 的值可从表3中获得而对x, y是指图形象元的坐标。
在图形模式下,是按象元来定义坐标的。
对VGA适配器,它的最高分辨率为640x480,其中640为整个屏幕从左到右所有象元的个数,480为整个屏幕从上到下所有象元的个数。
屏幕的左上角坐标为(0,0),右下角坐标为(639, 479),水平方向从左到右为x 轴正向,垂直方向从上到下为y轴正向。
TURBO C的图形函数都是相对于图形屏幕坐标,即象元来说的。
关于点的另外一个函数是: int far getpixel(int x, int y); 它获得当前点(x, y)的颜色值。
II、有关坐标位置的函数int far getmaxx(void);返回x轴的最大值。
int far getmaxy(void); 返回y轴的最大值。
int far getx(void); 返回游标在x轴的位置。
void far gety(void); 返回游标有y轴的位置。
void far moveto(int x, int y); 移动游标到(x, y)点,不是画点,在移动过程中亦画点。
void far moverel(int dx, int dy); 移动游标从现行位置(x, y)移动到(x+dx, y+dy)的位置,移动过程中不画点。
2、画线I. 画线函数TURBO C提供了一系列画线函数,下面分别叙述:void far line(int x0, int y0, int x1, int y1); 画一条从点(x0, y0)到(x1, y1)的直线。
void far lineto(int x, int y); 画一作从现行游标到点(x, y)的直线。
1•初始化图形系统函数名:ini tgraph功能:初始化图形系统用法:void far initgraph(int far *graphdriver, int far *grciphmode, char far *pathtodriver);程序例:^include <graphics. h>★include <stdlib. h>^include <stdio. h> #includo <conio・ h> int main(void){/* request auto detection */int gdriver = DETEC1\ gmode, errorcode;/* initialize graphics mode */initgraph(&gdriver, &gmode,"“);/* read result of initialization */errorcode 二graphresult():if (errorcode != grOk) /* an error occurred */(prin tf (''Graphics error: %s\n: grapherrormsg (errorcode)):printf("Press any key to halt:"):getch ();exi t(1); /* return wi th error code *//* draw a line */line(0, 0, gctmaxx0, gctmaxy());/* clean up */getch ();closegraph ();return 0;2.#include〈graphics・ h>★include <stdlib. h>^include <stdio. h>#include <conio.h> irH main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode; int maxx, mcixy;/* our polygon array */int polyL1OJ;/* initialhe graphics and local variables */initgraph(&gdriver, &gmode,;/* read result of initialization */ errorcode = graphresult();if (errorcode != grOk)/* an error occurred */{printf(^Graphics error: %s\n", \ grapherrormsg(orrorcode));prin订("Press any key to halt/); getch ();/♦ terminate with an error code */ exi t (1);}meixx = getmeixx ();mcixy = getmcixy 0 ;poly[0] = 20; /* 1st vertext */poly[1] = maxy / 2;poly[2] = maxx - 20; /* 2nd */ poly[3] = 20;poly [4] = maxx - 50; /* 3rd */ poly [5] = maxy - 20;poly[6] = maxx / 2;/* 4th */poly[7] = maxy / 2;/*drawpoly doesn't automatically close the polygon, so we close il・poly [8] = poly[0]:poly[9] = poly[l]:/* draw the polygon */ drawpoly(5, poly);/* clean up */ getchO ; elosegraph ();return 0;}#include <graphics・h> #include <stdlib. h> #includo <stdio・h> ^include <conio.h> int main(void)/* request auto detection */int gdriver = DETECT, gmode, errorcode;int midx, midy;ini stangle = 0, endangle = 360;int xradius = 100, yradius = 50;/* initidli/e graphics, local variables */ inilgraph(&gdrivg &gmode,"“);/* read result of initialization */ errorcode = graphrcsult();if (errorcode != grOk)/* an error occurred */(prin(『("Graphics error: %s\r)zz, grapherrormsg (errorcode));printf("Press any key to halt:");getch ();exit(1);/* term in ate with an error code */}midx = getmaxx () / 2;midy = getmaxy () / 2;setcolor (getmtixcolor ());/* draw ellipse */ellipse(midx, midy, stangle, endangle, xradius, yradius);/* clean up */getch ();closegraph();return 0;}功能:画出并填充一椭恻用法:void far fillellipse(int x, int y, int xradius, int yradius); 程序例:#includo〈graphics・ h>#include <conio. h>int main(void){int gdriver 二DETECT, gmode;int xcenter, ycenter, i;initgraph(&gdriver, &gmode,"“); xcenter = getmaxxO / 2;ycenter = getmaxy() / 2;for (i=0; i<13; i++){setfillstyle(i, WHITE);fillellipse(xcenter, ycenter, 100, 50); getch ();}closegraph();return 0;}#include <graphics・h> #include <stdlib. h> #includo <string・h> ^include <stdio.h> ^include <conio. h>int main(void)/* request auto detection */int gdriver = DETECT, gmode, errorcode;int bkcolor, midx, midy; char bknamc[35];/* initialize graphics and local variables */ initgraph(&gdrivor, &gmode,"”);/* road result of initializalion */errorcode = graphresult():/* an error occurred */if (errorcode != grOk){printf(z,Grciphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:z/); getch0 ;/* terminate with an error code */exit(1);}midx = getmaxx () / 2;midy 二gelmtixy() / 2; setcolor (getmaxcolor ());/* for centering text on the display */ settextjustify(CENTER_TEXT, CENTER_TEXT);/* get the current background color */ bkcolor = getbkcolor0 ;/* convert color value into a string */ itoa(bkcolor, bkname, 10);strcat (bknamc,"is the current background color・“);/* display a message */outtextxy (midx, midy, bkntune);/* clean up */getch();closegraph ();return 0;函数名:line 功能:在指定两点间画一直线用法:void far line(int xO, int yO, int xl, int yl);程序例:#include <graphics・h>^include <stdlib. h> #includo <stdio. h>^include <conio. h> int main(void){/* request auto detection */int gdriver 二DETECT, gmode, errorcode;int xmax, ymax;/* iniliali/e graphics and 1ocal variables */ initgraph(&gdriver, &gmode,"”):/* read result of initialization */cri^orcodc = graphrcsult ();/* an error occurred */if (errorcode != grOk){prin订("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:"); getch ();exi t (1);setcolor (getmcixcolor ());xmax = getmeixx ();ymeix 二getmtixy ();/* draw a diagonal line */ line(0, 0, xmax, ymax);/* clean up */ getchO ; closegraph ();return 0;}函数名:rectangle功能:画一个矩形)\] 法:void far rectangle(int left, int top, int right, int bottom);函数名:sctbkcolor功能:用调色板设置当前背景颜色用法:void far setbkcolor(int color): 程序例:ttinclude <graphics. h>tfinclude <stdlib. h>ttinclude <stdio. h>ttinclude <conio. h>int main(void){/* select a driver and mode that supports *//* multiple background colors・*/int gdrivcr 二EGA, gmodc = EGAHI, errorcode; int bkcol, maxcolor, x, y;char msg[80];/* initialize graphics and local variables */ initgraph(&gdriver,&gmode,"”);/* read result of initialization */ errorcode = graphresult();if (errorcode != grOk) /* an e门occurred */prinlf ("Graphics error: %s\n/z, grapherrormsg (errorcode)); printf("Press any key to halt/);getch0 ;exit(1) ; /* terminate with an error code */ }/* maximum color index supported */ maxcolor = getmtixcolor ();/* for centering text messages */seitextjustify(CENTER TEXT, CENTER TEXT);x 二getmaxxO / 2;y = getmaxyO / 2;/* loop through the available colors */for (bkcol~0; bkcol<=maxcolor; bkcol++){/* c l ear the screen */cleardevice();/* select a new background color */ sctbkcolor(bkcol);/* output a messsage */if (bkcol == WHITE)setcolor(EGA_BLUE):sprintf (msg, ''Background color: bkcol);outtextxy (x, y, msg);getch ();}/* clean up */closcgraphO ;return 0;}函数名:setcolor功能:设置当前画线颜色用法:void far setcolor(int color);程序例:ttinclude <graphics. h>^include <stdlib. h>ftinclude <stdio.h>#includc <conio.h>int m3in(void){/* select a driver and mode that supports *//* multiple drawing colors・*/int gdriver = EGA, gmode = EGAI11, errorcode;int color, maxcolor, x, y;char msg [80];/* initialize graphics and local variables */ initgraph(&gdrivcr, &gmode,;/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf (''Graphics error: %s\n", grapherrormsg (errorcode)); printf("Press any key to halt:,z);gctchO ;exit(1); /* terminate with an error code */}/* maximum color index supported */ mtixcolor 二getmtixcolor ();/* for centering text messages */settextjustify(CENTER_TEXT, CENTER_TEXT);x = getmaxxO / 2;y = getmaxyO / 2;/* loop through the available colors */for (color=i; color<-maxcolor; color++){/* clear the screen */cleardevice();/* select a new background color */ setcolor(color);/* output a messsage */sprintf (msg, "Color: color): outtextxy(x, y, msg); getch ();}/* clean up */ closcgraph ();return 0;}函数名:setfillstyle功能:设登填充模式和颜色用法:void far setfi 1 lstyle(int pattern, int color); 程序例:^include <graphics. h> 廿include <stdlib. h> ^include〈string. h> ^include <stdio.h> #inelude <conio. h>/* the names of the fill styles supported */ char *fname[] = { "EMPTY_FILL","SOLID FILL","LINE FII丄","LTSLASH FILI/;"SLASII_F1LL", "BKSLASII_FILL","LTBKSLASH_FILL","HATCH FILL","XHATCH_FILL","INTERLEAVE_FILL","WIDE DOT FILL","CLOSE DOT FILI/;"USER FILL" int main(void)/* request auto detection */int gdriver = DETECT, gmode, errorcode;int style, midx, midy;char stylestr[40];/* initialize graphics and 1ocal variables */ initgraph(&gdriver, &gmode, ");/* read result of initialization */errorcodc = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n〃,grapherrormsg(errorcode)); printf("Press any key to halt/):getchO ;exi t (1) ; /* term in ate with an error code */}midx = getmtixx () / 2;midy = getmtixy () / 2;for (style = EMPTY_FILL; style < USER一FILL; style++){/* select the fill style */setfillstyle(style, getmaxcolor());/* convert style into a string */strepy(stylestr, fname[style]);/* fill a bar */bar 3d (0, 0, midx-10, midy, 0, 0);/* output a message */outtextxy (midx, midy, stylestr);/* wait for a key */getch ();cleardevice();}/* clean up */getchO ;closegraph();return 0;函数名:set linestyle功能:设置当前画线宽度和类型用法:void far setlinestyle(int linestype, unsigncd upattern); 程序例:#include <graphics・ h>#include <stdlib. h> #include <string・ h>^include <stdio>h>ttinclude <conio. h> /* the names of the line styles supported */ char amc [] = {,,SOL1D_L1NE,\,,DOTTED_LINE,,I"CENTER LTNE\"DASHED_LINE","USERBnjLINE"};int main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int style, midx, midy, userpat;char stylestr[40];/* initialize graphics and local variables */initgraph(&gdrivg &gmodc,"”);/* read result of initialization */errorcode 二graphrcsult():if (errorcode != grOk) /* an error occurred */{printf("Graphics error: grapherrormsg(errorcode));printf(”Press any key to halt:");getchO ;exit(1); /* terminate with an error code */midx = getmaxx () / 2;midy = getmaxy () / 2;/* a user defined line pattern *//* binary: "0000000000000001" */userpat = 1;for (style=SOLTD LTNE; style<=USERBTT LTNE; style++){/* select the line style */setlinestyle(style, userpat, 1);/* convert style into a string */strcpy(stylestr, InameEstyle]);/* draw a line */linc(0, 0, midx-10, midy);/* draw a rectanglc */rectanglc(0, 0, getmaxx (), getmaxy ());/* output a message */outtextxy (midx, midy, stylestr);/* wait for a key */getchO ;cleardevice0 ;}/* clean up */closegraph();return 0;。
easygraphics函数easygraphics函数是一种用于图形编程的函数库,它可以帮助编程初学者轻松地实现各种图形的绘制和交互操作。
本文将介绍easygraphics函数的基本用法和一些常见的应用场景,以帮助读者更好地理解和使用这个函数库。
easygraphics函数库提供了一系列简单易用的函数,用于绘制各种形状的图形,如线段、矩形、圆形等。
通过调用这些函数,我们可以在屏幕上绘制出各种漂亮的图形,实现丰富多样的效果。
例如,我们可以使用easygraphics函数库绘制一个五角星,只需用几行代码就可以完成,非常方便快捷。
除了绘制静态图形,easygraphics函数库还可以实现一些动态效果,如图形的平移、旋转、缩放等。
通过调用相应的函数,我们可以实现图形的平滑移动、旋转、变形等效果,使得图形更加生动有趣。
例如,我们可以使用easygraphics函数库实现一个动态的跳动的小球,只需使用几行代码就可以完成,非常简单。
除了绘制和动态效果,easygraphics函数库还提供了一些交互功能,如鼠标点击、键盘输入等。
通过调用这些函数,我们可以实现与用户的交互,接受用户的输入,并根据用户的操作做出相应的反应。
例如,我们可以使用easygraphics函数库实现一个简单的画板程序,用户可以在画板上绘制图形,选择颜色和线条粗细等。
easygraphics函数库的使用非常简单,只需包含相应的头文件,并在代码中调用相应的函数即可。
它提供了一系列函数,包括绘制图形的函数、实现动态效果的函数、处理交互的函数等,我们只需按照需要调用相应的函数即可实现相应的功能。
此外,easygraphics 函数库还提供了丰富的文档和示例代码,供我们参考学习。
easygraphics函数库的应用非常广泛。
它可以用于教育领域,帮助学生更好地理解和学习图形学相关知识;它可以用于游戏开发,帮助开发者快速实现各种精美的游戏效果;它还可以用于可视化领域,帮助研究人员将复杂的数据可视化展示。
C#Graphic绘制圆、三⾓形、椭圆、图⽚在form和panel上可以绘制图形,线段,圆,⽂字,图形等等。
绘制代码必须放在OnPaint()函数⾥⾯,因为窗体刷新的时候,都会调⽤该函数,重新刷新所绘的图。
⽰例代码在Panel上绘制图形来简单的描述下绘线和绘图原理。
using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Reflection;namespace TestGraphic{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void panel1_Paint(object sender, PaintEventArgs e){Graphics gc = e.Graphics;///设置绘图的颜⾊Brush greenBrush = new SolidBrush(Color.Green);int radius = 30;// 绘制圆,(0, 0)为左上⾓的坐标,radius为直径gc.FillEllipse(greenBrush, 0, 0, radius, radius);Brush yellowBush = new SolidBrush(Color.Yellow);// 绘制椭圆,其实圆时椭圆的特殊的⼀种,即两个定点重合, (50, 60)为左上⾓的坐标,// 70位椭圆的宽度,100位椭圆的⾼度gc.FillEllipse(yellowBush, 50, 60, 70, 100);// 绘制三⾓形,指定红⾊和线宽5。
二、C 的图形模式编程2.1图形编程基础VC+EasyX 库里提供了图形函数就可以在VC 环境下进行图形编程。
对图形函数的操作都是在视口(Viewport )上进行。
用户可以在屏幕上定义大小不同的视口,若不定义视口大小,它就是整个屏幕。
视口是在图形屏幕状态下的概念,用户可访问的最小单位是一个像素(像素这一术语最初用来指显示器上最小的、单独的发光点单元。
然而现在,其含义拓宽为指图形显示器上的最小可访问点)。
文本与图形都可以在视口上显示。
图形视口的左上角坐标为(0,0)。
例如:分辨率为640*480的视口像素点的定位显示器在图形模式下工作时,显示的单位是像素点,通过控制各像素点的颜色和灰度等级来形成图形。
因此绘图的第一步是进行图形模式的初始化,系统进入绘图模式。
(1) initgraph() 图形初始化函数用法: HWND initgraph(int width,int height,int flag = NULL);示例:以下局部代码创建一个尺寸为 640x480 的绘图环境:initgraph(640, 480);例2-1:调用initgraph()设置640*480的图形模式,在屏幕中央显示如下的图形。
参考代码:#include<graphics.h>#include <conio.h>int main(){initgraph(640, 480);line(200, 240, 440, 240);line(320, 120, 320, 360);getch();(closegraph();return 0;}[学习单步执行]试着单步执行刚才的程序,由于绘图和多线程等因素的限制,请务必按照以下步骤尝试(熟练了以后就不用了):1. 将VC取消最大化,并缩小窗口,能看到代码就行。
2. 按一下F10(单步执行),会看到屏幕上出现一个黄色的小箭头,指示将要执行的代码。
3. 当箭头指向initgraph()语句时,按F10,能看到窗口发生了变化。
怎样在VC环境下实现 #include<graphics.h> 库函数#include<stdio.h>#include<graphics.h>#include<string.h>#include<math.h>#define Scale 1.35void DrawFace(int F,int Fc[30][11],float St[50][3],float Rol,float DE, float Aux1,float Aux2,float Aux3,float Aux4,float Aux5,float Aux6, float Aux7,float Aux8){float XObs,YObs,ZObs,XProj,YProj;int XScreen,YScreen;int S,NS,No;float X,Y,Z,X0,Y0,Z0;int MaxX=getmaxx();int MaxY=getmaxy();NS=Fc[F][0];for(S=1;S<=NS;S++){No=Fc[F][S];X=St[No][1];Y=St[No][2];Z=St[No][3];XObs=-X*Aux1+Y*Aux3;YObs=-X*Aux5-Y*Aux6+Z*Aux4;ZObs=-X*Aux7-Y*Aux8-Z*Aux2+Rol;XProj=DE*XObs/ZObs;YProj=DE*YObs/ZObs;XScreen=floor(0.5+XProj*Scale+MaxX/2);YScreen=floor(0.5+MaxY/2-YProj); if(S==1){moveto(XScreen,YScreen);X0=XScreen;Y0=YScreen;}elselineto(XScreen,YScreen);}lineto(X0,Y0);}void DrawObject(int Fc[30][11],float St[50][3],int NF,float Rol,float Theta,float Phi,float DE,int Dot){float Th,Ph,Aux1,Aux2,Aux3,Aux4,Aux5,Aux6,Aux7,Aux8;int F,St1,St2,St3;float P1,P2,P3,Q1,Q2,Q3;float v1,v2,v3,n1,n2,n3;float O1,O2,O3,SProduct;Th=3.1415926*Theta/180;Ph=3.1415926*Phi/180;Aux1=sin(Th);Aux2=sin(Ph);Aux3=cos(Th);Aux4=cos(Ph);Aux5=Aux3*Aux2; Aux6=Aux1*Aux2;Aux7=Aux3*Aux4;Aux8=Aux1*Aux4;O1=Rol*Aux7;O2=Rol*Aux8;O3=Rol*Aux2;for(F=1;F<=NF;F++){St1=Fc[F][1];St2=Fc[F][2]; St3=Fc[F][3];v1=O1-St[St1][1];v2=O2-St[St1][2];v3=O3-St[St1][3];P1=St[St2][1]-St[St1][1];P2=St[St2][2]-St[St1][2];P3=St[St2][3]-St[St 1][3];Q1=St[St3][1]-St[St1][1];Q2=St[St3][2]-St[St1][2];Q3=St[St3][3]-St[St 1][3];n1=P2*Q3-Q2*P3;n2=P3*Q1-Q3*P1;n3=P1*Q2-Q1*P2;SProduct=v1*n1+v2*n2+v3*n3;if(SProduct>0.0){setlinestyle(SOLID_LINE,0,NORM_WIDTH);DrawFace(F,Fc,St,Rol,DE,Aux1,Aux2,Aux3,Aux4,Aux5,Aux6,Aux7,Aux8);}问题补充 2009-01-05 16:59else if(Dot==1){setlinestyle(DOTTED_LINE,0,NORM_WIDTH);DrawFace(F,Fc,St,Rol,DE,Aux1,Aux2,Aux3,Aux4,Aux5,Aux6,Aux7,Aux8);}}}void Polyhedron(int pColor){int NF,Fc[30][11],MaxX,MaxY;float St[50][3];MaxX=getmaxx();MaxY=getmaxy();setcolor(pColor);setviewport(0,0,MaxX,MaxY,1);St[1][1]=40;St[1][2]=54;St[1][3]=-40;St[2][1]=40;St[2][2]=54;St[2][3]=0;St[3][1]=40;St[3][2]=-54;St[3][3]=0;St[4][1]=40;St[4][2]=-54;St[4][3]=-40;St[5][1]=-40;St[5][2]=-54;St[5][3]=-40;St[6][1]=-40;St[6][2]=54;St[6][3]=-40;St[7][1]=-40;St[7][2]=54;St[7][3]=0;St[8][1]=0;St[8][2]=34;St[8][3]=40;St[9][1]=0;St[9][2]=-34;St[9][3]=40;St[10][1]=-40;St[10][2]=-54;St[10][3]=0;NF=9;Fc[1][0]=4;Fc[1][1]=1;Fc[1][2]=2;Fc[1][3]=3;Fc[1][4]=4; Fc[2][0]=4;Fc[2][1]=1;Fc[2][2]=6;Fc[2][3]=7;Fc[2][4]=2; Fc[3][0]=3;Fc[3][1]=2;Fc[3][2]=7;Fc[3][3]=8;Fc[4][0]=4;Fc[4][1]=2;Fc[4][2]=8;Fc[4][3]=9;Fc[4][4]=3; Fc[5][0]=4;Fc[5][1]=1;Fc[5][2]=4;Fc[5][3]=5;Fc[5][4]=6; Fc[6][0]=4;Fc[6][1]=7;Fc[6][2]=10;Fc[6][3]=9;Fc[6][4]=8; Fc[7][0]=3;Fc[7][1]=3;Fc[7][2]=9;Fc[7][3]=10;Fc[8][0]=4;Fc[8][1]=10;Fc[8][2]=5;Fc[8][3]=4;Fc[8][4]=3; Fc[9][0]=4;Fc[9][1]=5;Fc[9][2]=10;Fc[9][3]=7;Fc[9][4]=6; DrawObject(Fc,St,NF,800.0,330,30,1000,1);}void main(){int ErrorCode,GraphDriver,GraphMode;GraphDriver=0;initgraph(&GraphDriver,&GraphMode,"");Polyhedron(1);getch();closegraph();}。
一、选题背景:画图程序,通过画图中的功能绘制出美丽的图案。
二、设计思想:利用数学三角函数制作山峰和花朵出一条曲线、用画圆函数绘制太阳的形状、再进行颜色填充用绘制直线的函数来绘制比较粗的光线、用矩形函数画出矩形的边框、再画地球、直线画赤道、弧线画南北极和钟表的刻度盘。
三、流程图:四、程序清单:#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、主要问题及解决方法✓抛物线的画法用插补法画抛物线。
c语言image用法在C语言中,image(图像)通常以像素(pixels)的形式存储,并使用数组来表示。
每个像素可以将其颜色表示为RGB(红绿蓝)值,通常使用整数或字节来表示。
在处理图像时,我们可以使用C语言来完成各种操作,例如读取、修改、保存图像,以及执行图像处理算法,比如滤波、边缘检测等等。
以下是一些常用的C库和函数,可用于处理图像:1. Simple DirectMedia Layer(SDL)库:提供了一系列函数,用于创建窗口、加载图像、显示图像等操作。
2. OpenCV(Open Source Computer Vision)库:一个广泛使用的计算机视觉库,支持图像和视频处理、特征提取、目标识别等功能。
3. CImg库:一个简单易用的C++图像处理库,提供了丰富的图像处理和分析函数。
4. fread()和fwrite()函数:可以用来读取和写入二进制图像文件,如位图(.bmp)、JPEG(.jpg)等。
下面是一个简单的示例代码,展示了如何使用C语言读取和修改图像的像素:```c#include <stdio.h>#define WIDTH 256#define HEIGHT 256typedef struct {unsigned char r, g, b;} Pixel;void modifyImage(Pixel *image, int width, int height) { for (int i = 0; i < height; i++) {for (int j = 0; j < width; j++) {//修改像素值image[i * width + j].r = 255; //设置为红色image[i * width + j].g = 0; //设置为绿色image[i * width + j].b = 0; //设置为蓝色}}}int main() {Pixel image[WIDTH * HEIGHT];//读取图像FILE *file = fopen("image.bmp", "rb");fread(image, sizeof(Pixel), WIDTH * HEIGHT, file); fclose(file);//修改图像modifyImage(image, WIDTH, HEIGHT);//保存图像FILE *outputFile = fopen("output.bmp", "wb");fwrite(image, sizeof(Pixel), WIDTH * HEIGHT, outputFile);fclose(outputFile);return 0;}```上述代码中,我们首先定义了一个Pixel结构来表示图像的像素,其中包含了r、g、b三个成员分别表示红、绿、蓝分量的值。
函数名: fillellipse功能: 画出并填充一椭圆用法: void far fillellipse(int x, int y, int xradius, int yradius); 程序例:#include <graphics.h>#include <conio.h>int main(void){int gdriver = DETECT, gmode;int xcenter, ycenter, i;initgraph(&gdriver,&gmode,"");xcenter = getmaxx() / 2;ycenter = getmaxy() / 2;for (i=0; i<13; i++){setfillstyle(i,WHITE);fillellipse(xcenter,ycenter,100,50);getch();}closegraph();return 0;}Graphics 类.NET Framework 类库Graphics 类封装一个GDI+ 绘图图面。
无法继承此类。
命名空间:System.Drawing程序集:System.Drawing(在system.drawing.dll 中)语法Visual Basic(声明)Public NotInheritable Class GraphicsInherits MarshalByRefObjectImplements IDeviceContext, IDisposableVisual Basic(用法)Dim instance As GraphicsC#public sealed class Graphics : MarshalByRefObject, IDeviceContext, IDisposableC++public ref class Graphics sealed : public MarshalByRefObject, IDeviceContext, IDisposableJ#public final class Graphics extends MarshalByRefObject implements IDeviceContext, IDisposableJScriptpublic final class Graphics extends MarshalByRefObject implements IDeviceContext, IDisposable备注Graphics类提供将对象绘制到显示设备的方法。
Graphics与特定的设备上下文关联。
通过调用从System.Windows.Forms.Control继承的对象的Control.CreateGraphics方法,或通过处理控件的Control.Paint事件并访问System.Windows.Forms.PaintEventArgs类的Graphics属性,可以获取Graphics。
继承层次结构System.ObjectSystem.MarshalByRefObjectSystem.Drawing.Graphics线程安全此类型的任何公共静态(Visual Basic 中的Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter EditionGraphics 成员.NET Framework 类库Graphics 成员封装一个GDI+ 绘图图面。
无法继承此类。
下表列出了由 Graphics 类型公开的成员。
公共属性名称说明Clip获取或设置 Region ,该对象限定此 Graphics 的绘图区域。
ClipBounds获取一个 RectangleF 结构,该结构限定此Graphics 的剪辑区域。
CompositingMode 获取一个值,该值指定如何将合成图像绘制到此Graphics。
CompositingQuality获取或设置绘制到此 Graphics的合成图像的呈现质量。
DpiX获取此Graphics 的水平分辨率。
DpiY获取此Graphics 的垂直分辨率。
InterpolationMode 获取或设置与此Graphics 关联的插补模式。
IsClipEmpty 获取一个值,该值指示此Graphics 的剪辑区域是否为空。
IsVisibleClipEmpty 获取一个值,该值指示此Graphics 的可见剪辑区域是否为空。
PageScale 获取或设置此 Graphics的全局单位和页单位之间的比例。
PageUnit 获取或设置用于此 Graphics中的页坐标的度量单位。
PixelOffsetMode 获取或设置一个值,该值指定在呈现此Graphics 的过程中像素如何偏移。
RenderingOrigin 为抵色处理和阴影画笔获取或设置此 Graphics 的呈现原点。
SmoothingMode 获取或设置此 Graphics 的呈现质量。
TextContrast 获取或设置呈现文本的灰度校正值。
TextRenderingHint获取或设置与此Graphics关联的文本的呈现模式。
Transform获取或设置此Graphics的世界变换。
VisibleClipBounds获取此Graphics的可见剪辑区域的边框。
页首公共方法(请参见受保护的方法)名称说明AddMetafileComment向当前Metafile添加注释。
BeginContainer已重载。
保存具有此Graphics的当前状态的图形容器,然后打开并使用新的图形容器。
Clear清除整个绘图面并以指定背景色填充。
CopyFromScreen已重载。
执行颜色数据从屏幕到Graphics的绘图图面的位块传输。
CreateObjRef创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。
(从MarshalByRefObject继承。
)Dispose释放由Graphics使用的所有资源。
DrawArc已重载。
绘制一段弧线,它表示由一对坐标、宽度和高度指定的椭圆部分。
DrawBezier已重载。
绘制由4 个Point结构定义的贝塞尔样条。
DrawBeziers已重载。
用Point结构数组绘制一系列贝塞尔样条。
DrawClosedCurve已重载。
绘制由Point结构的数组定义的闭合基数样条。
DrawCurve已重载。
绘制经过一组指定的Point结构的基数样条。
DrawEllipse已重载。
绘制一个由边框(该边框由一对坐标、高度和宽度指定)定义的椭圆。
DrawIcon已重载。
在指定坐标处绘制由指定的Icon表示的图像。
DrawIconUnstretched绘制指定的Icon表示的图像,而不缩放该图像。
DrawImage已重载。
在指定位置并且按原始大小绘制指定的Image。
DrawImageUnscaled已重载。
在由坐标对指定的位置,使用图像的原始物理大小绘制指定的图像。
DrawImageUnscaledAndClipped在不进行缩放的情况下绘制指定的图像,并在需要时剪辑该图像以适合指定的矩形。
DrawLine已重载。
绘制一条连接由坐标对指定的两个点的线条。
DrawLines已重载。
绘制一系列连接一组Point结构的线段。
DrawPath绘制GraphicsPath。
DrawPie已重载。
绘制一个扇形,该形状由一个坐标对、宽度、高度以及两条射线所指定的椭圆定义。
DrawPolygon已重载。
绘制由一组Point结构定义的多边形。
DrawRectangle已重载。
绘制由坐标对、宽度和高度指定的矩形。
DrawRectangles已重载。
绘制一系列由Rectangle结构指定的矩形。
DrawString已重载。
在指定位置并且用指定的Brush和Font对象绘制指定的文本字符串。
EndContainer关闭当前图形容器,并将此Graphics的状态还原到通过调用BeginContainer方法保存的状态。
EnumerateMetafile已重载。
将指定Metafile中的记录逐个发送到回调方法以在指定的点处显示。
Equals已重载。
确定两个Object实例是否相等。
(从Object继承。
)ExcludeClip已重载。
更新此Graphics的剪辑区域,以排除Rectangle结构所指定的区域。
FillClosedCurve已重载。
填充由Point结构数组定义的闭合基数样条曲线的内部。
FillEllipse已重载。
填充边框所定义的椭圆的内部,该边框由一对坐标、一个宽度和一个高度指定。
FillPath填充GraphicsPath的内部。
FillPie已重载。
填充由一对坐标、一个宽度、一个高度以及两条射线指定的椭圆所定义的扇形区的内部。
FillPolygon已重载。
填充Point结构指定的点数组所定义的多边形的内部。
FillRectangle已重载。
填充由一对坐标、一个宽度和一个高度指定的矩形的内部。
FillRectangles已重载。
填充由Rectangle结构指定的一系列矩形的内部。
FillRegion填充Region的内部。
Flush已重载。
强制执行所有挂起的图形操作并立即返回而不等待操作完成。
FromHdc已重载。
从设备上下文的指定句柄创建新的Graphics。
FromHdcInternal返回指定设备上下文的Graphics。
FromHowFromHwnd从窗口的指定句柄创建新的Graphics。
FromHwndInternal创建指定Windows 句柄的新Graphics。
FromImage从指定的Image创建新的Graphics。
GetHalftonePalette获取当前Windows 的半色调调色板的句柄。
GetHashCode用作特定类型的哈希函数。
GetHashCode适合在哈希算法和数据结构(如哈希表)中使用。
(从Object继承。
)GetHdc获取与此Graphics关联的设备上下文的句柄。
GetLifetimeService检索控制此实例的生存期策略的当前生存期服务对象。