⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x_windows_stream_example.cpp

📁 Free C++ toolkit to facilitate Monte-Carlo simulation. This is a library covered under the LGPL. "MC
💻 CPP
字号:
#include <X11/Xlib.h>#include <X11/Xutil.h>#include <cstdio>#include <cstdlib>#include <cstring>// include mcsLibre simulation library#include "mcsLibre.h" void draw_stuff(Window win, GC gc, Display *display, int screen, XColor font_color, int stream_base){  // Prepare graphics  XSetForeground(display, gc, font_color.pixel);  XDrawString(display, win, gc, 19, 110, "Uniform", strlen("Uniform"));  XDrawString(display, win, gc, 124, 110, "Normal", strlen("Normal"));  XDrawString(display, win, gc, 20, 157, "Click in window to", strlen("Click in window to"));  XDrawString(display, win, gc, 7, 172, "alter random streams.", strlen("alter random streams."));  // create object for simulation  mcsLibre sim;  // random variables  int ux, uy, nx, ny;    // simulation loop  int samples = 1000;      // number of simulations  for (int loopvar = 0; loopvar < samples; loopvar++)    {      // get values from streams      ux = (int) sim.uniform(20, 80, stream_base);       uy = (int) sim.uniform(20, 80, stream_base + 1);       nx = (int) sim.normal(150, 10, stream_base + 2);       ny = (int) sim.normal(50, 10, stream_base + 3);       // display results      XDrawLine(display,win, gc, ux, uy, ux, uy);      XDrawLine(display,win, gc, nx, ny, nx, ny);    }}main(){  Display *display;  int screen;  Window win;  XColor blue;  unsigned int width = 200;  unsigned int height = 200;  XFontStruct *font_info;  GC gc;  Colormap cmap;  XEvent x_event;  XGCValues values;  if ( (display = XOpenDisplay(NULL)) == NULL )     {      perror("Could not open X display.");      exit(1);    }  screen = DefaultScreen(display);  win = XCreateSimpleWindow(display, RootWindow(display, screen), 0, 0, width, height, 5, BlackPixel(display, screen), WhitePixel(display, screen));  cmap = DefaultColormap(display, screen);  XParseColor(display, cmap, "blue", &blue);  XAllocColor(display, cmap, &blue);  XParseColor(display, cmap, "ZZ_NO_SUCH_COLOR", &blue);  if ((font_info = XLoadQueryFont(display, "9x15")) == NULL)     {      perror("Use fixed font\n");      font_info = XLoadQueryFont(display, "fixed");    }  gc = XCreateGC(display, win, (unsigned long)0, &values);  XSetFont(display, gc, font_info->fid);  XSetForeground(display, gc, BlackPixel(display, screen));  XSetStandardProperties(display, win, "Stuff", "QQQ", None, 0, 0, NULL);  XSelectInput(display, win, ExposureMask | ButtonPressMask);  XMapWindow(display, win);   int streams = 1;  draw_stuff(win, gc, display, screen, blue, streams);  while (1) {    XNextEvent(display, &x_event);    switch (x_event.type) {    case Expose:      draw_stuff(win,gc,display,screen,blue, streams);      break;    case ButtonPressMask:      streams = streams + 5;      if (streams >= 90)	{	  streams = 1;	}      XClearWindow(display, win);      draw_stuff(win,gc,display,screen,blue, streams);      break;    default:      break;    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -