#include #include #include #include #include #include #define PI 3.1415926 /* gcc g2_MC.c -L/usr/X11R6/lib -lm -lg2 -lX11 */ /* simple monte carlo integration trubasic style */ int color,blk,count; long n,N; float x,y,pie; int d; /* a g2-object file handle */ int main(int argc, char*argv[]) { N=atol(argv[1]); srand((unsigned int)getpid()); count=0; /* open a 400 by 400 pixel window */ /* lower left is (0,0), upper right is (400,400) */ d=g2_open_X11(400, 400); color=g2_ink(d,1.0,0.0,0.0); /* red */ g2_pen(d,color); /* draw a bounding box */ g2_rectangle(d,0,0,400,400); /* draw in some coordinate axes */ g2_line(d, 200,0, 200, 400); /* y axis */ g2_line(d, 0, 200, 400, 200); /* x axis */ /* draw tick-marks */ for(n=1; n<20;n++){ g2_line(d,20*n,196,20*n,204); g2_line(d,196,20*n,204,20*n); } g2_circle(d,200.0,200.0,200.0); blk=g2_ink(d,0.0,0.0,0.0); g2_pen(d,blk); /* black */ for(n=0;n