读书人

小弟我在TC上编的绘制特殊线的程序如何

发布时间: 2012-09-14 11:53:44 作者: rapoo

我在TC下编的绘制特殊线的程序怎么在linux下成功运行?那个graphics.h是在不会改 那位帮忙把我改改 能再linux下运行
现在我把我的代码贴进来
# include "graphics.h"
# include "math.h"
# include "conio.h"
# define PATH "d:\\tc"
# define PI 3.1415926535
main()
{
int gdriver=VGA;
int gmode = VGAHI;
double a=0,b;
int x0=340,y0=240,radius=100,i,x,y;
initgraph(&gdriver,&gmode,PATH);
setcolor(2);
setlinestyle(0,0,0);
for(i=0;i<6;i++,a+=60)
{ b=a*PI/180;
x=x0+radius*cos(b);
y=y0+radius*sin(b);

arc(x,y,120-i*60,240-i*60,radius);

}
getch();
closegraph();
}
各位帮帮忙

[解决办法]
linux下的图形库多得很:SDL,gtk+,qt,iup,Xlib,不一定要全屏下实现的.
如果要跨平台,最好选一个通用的库.
[解决办法]
珍惜生命,远离TC及相关过于陈旧的书籍。
[解决办法]
我让你用TC……
Linux下的绘图库可以看看Cairo,跨平台的。
[解决办法]
在cygwin X环境下编译通过.使用Xlib库,编译命令:gcc prog.c -lX11
相信在linux X环境下没问题.修改的别人的代码

C/C++ code
// Written by Ch. Tronche (http://tronche.lri.fr:8000/)// Copyright by the author. This is unmaintained, no-warranty free software.// Please use freely. It is appreciated (but by no means mandatory) to// acknowledge the author's contribution. Thank you.// Started on Thu Jun 26 23:29:03 1997//// Xlib tutorial: 2nd program// Make a window appear on the screen and draw a line inside.// If you don't understand this program, go to// http://tronche.lri.fr:8000/gui/x/xlib-tutorial/2nd-program-anatomy.html//#include <X11/Xlib.h> // Every Xlib program must include this#include <assert.h>   // I include this to test return values the lazy way#include <unistd.h>   // So we got the profile for 10 seconds#include <math.h>#include <stdio.h>#define NIL (0)       // A name for the void pointer#define PI 3.1415926535main(){    // Open the display    Display *dpy = XOpenDisplay(":0");    assert(dpy);    // Get some colors    int blackColor = BlackPixel(dpy, DefaultScreen(dpy));    int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));    int i;    double a=0,b;    int x0=340,y0=240,radius=100,x,y;    // Create the window    Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,                                   800, 600, 0, blackColor, blackColor);    // We want to get MapNotify events    XSelectInput(dpy, w, StructureNotifyMask);    // "Map" the window (that is, make it appear on the screen)    XMapWindow(dpy, w);    // Create a "Graphics Context"    GC gc = XCreateGC(dpy, w, 0, NIL);    // Tell the GC we draw using the white color    XSetForeground(dpy, gc, whiteColor);    // Wait for the MapNotify event    for (;;) {        XEvent e;        XNextEvent(dpy, &e);        if (e.type == MapNotify)            break;    }    for (i=0; i<6; i++,a+=60)    {        b=a*PI/180;        x=x0+radius*cos(b);        y=y0+radius*sin(b);        XDrawArc(dpy,w,gc,x-50,y-50,radius*2,radius*2,(120-i*60)*64,120*64);            }    XFlush(dpy);    sleep(100);}
[解决办法]
XDrawArc()的后6个参数分别是:外切方框的左上角的X值,Y值,外切框的宽,高,弧的起始度*64,相对要画的度数*64(不是结束的度数),这个函数跟TC的那个画法不一样.

读书人网 >C语言

热点推荐