本文介绍了我该怎么做图形很容易地在一个现代的Linux?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是何许C程序的例子人们可以在旧时代写的:
的#include<&graphics.h中GT;
#包括LT&;&stdlib.h中GT;
#包括LT&;&stdio.h中GT;
#包括LT&;&CONIO.H GT;无效的主要()
{
INT GD = DETECT,克; initgraph(安培; GD,和安培;克,C:\\\\ \\\\ TURBOC BGI);
圆(200100150); 残培();
closegraph();
}
我认为这是MSDOS下的Turbo C。它可以让你在屏幕上绘图,并可以很容易地扩展到迅速做动画图形,如在黑客的xscreensaver发现。
我怎么会写在Ubuntu在GCC等价?它可以用Java做?
解决方案
#包括LT&; X11 / Xlib.h>
#包括LT&;&stdlib.h中GT;/ * GCC -std = gnu99 -o圈circle.c -lX11 * /INT主(INT ARGC,CHAR *的argv [])
{ / *连接到X服务器,使一个窗口* /
显示* DPY = XOpenDisplay(GETENV(显示));
窗口W = XCreateSimpleWindow(DPY,DefaultRootWindow(DPY)
100,100,640,480,1,
BlackPixel(DPY,DefaultScreen(DPY))
WhitePixel(DPY,DefaultScreen(DPY))); / *提高并等待* /
XSelectInput(DPY,W,StructureNotifyMask);
XMapRaised(DPY,w)的;
对于(XEventË;(e.type = MapNotify)!;
XWindowEvent(DPY,W,StructureNotifyMask,急症室)); / *创建一个图形上下文在窗口绘制* /
GC G = XCreateGC(DPY,W,0,NULL); / *绘制一个圆* /
XDrawArc(DPY,W,G,200,100,150,150,0,360 * 64);
XFlush(DPY); / *等待按键preSS * /
XSelectInput(DPY,W,KeyReleaseMask);
对于(XEventË;(e.type = KeyRelease)!;
XWindowEvent(DPY,W,KeyReleaseMask,急症室)); /*清理*/
XDestroyWindow(DPY,w)的;
XCloseDisplay(DPY);
}
Here is an example of the sort of C program one could write in the old days:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void main()
{
int gd=DETECT, gm;
initgraph(&gd, &gm, "c:\\turboc\\bgi");
circle(200,100,150);
getch();
closegraph();
}
I think this was turbo C under MSDOS. It gives you a drawing on the screen and can be easily extended to do speedy animated graphics such as those found in xscreensaver hacks.
How would I write the equivalent in gcc on ubuntu? Can it be done in Java?
解决方案
#include<X11/Xlib.h>
#include<stdlib.h>
/* gcc -std=gnu99 -o circle circle.c -lX11 */
int main (int argc, char *argv[])
{
/* connect to the X server and make a window */
Display *dpy = XOpenDisplay (getenv ("DISPLAY"));
Window w = XCreateSimpleWindow (dpy, DefaultRootWindow (dpy),
100, 100, 640, 480, 1,
BlackPixel (dpy, DefaultScreen (dpy)),
WhitePixel (dpy, DefaultScreen (dpy)));
/* raise it and wait */
XSelectInput (dpy, w, StructureNotifyMask);
XMapRaised (dpy, w);
for(XEvent e; ( e.type != MapNotify );
XWindowEvent (dpy, w, StructureNotifyMask, &e));
/* create a graphics context for drawing in the window */
GC g = XCreateGC (dpy, w, 0, NULL);
/* draw a circle */
XDrawArc(dpy,w,g,200,100,150,150,0,360*64);
XFlush(dpy);
/*wait for key press*/
XSelectInput (dpy, w, KeyReleaseMask);
for(XEvent e; ( e.type != KeyRelease );
XWindowEvent (dpy, w, KeyReleaseMask, &e));
/*clean up*/
XDestroyWindow( dpy, w );
XCloseDisplay (dpy);
}
这篇关于我该怎么做图形很容易地在一个现代的Linux?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!