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

📄 mandelbrot.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
staticvoid reset_vdc(){Xgl_bounds_f2d vdc;  vdc.xmin = center.real - range.real;  vdc.xmax = center.real + range.real;  vdc.ymin = center.imag - range.imag;  vdc.ymax = center.imag + range.imag;  xgl_object_set(ctx, XGL_CTX_VDC_WINDOW, &vdc,  0);}static void reset_proc(){/*  * Init globals */  center.imag=0.0; center.real=0.0;  range.imag=2.0; range.real=2.0;  scale.real=32.0; scale.imag=32.0;  iterations = MY_CMAP_SIZE;    xgl_context_new_frame(ctx);  reset_vdc();  shift_factor = (iterations-1)/ MY_CMAP_SIZE;  update_panel();  page_proc();}staticvoid granular_proc(item, value, event)Panel_item item;int value;Event *event;{  scale.real = scale.imag = (float)value;}staticvoid iterate_proc(item, value, event)Panel_item item;int value;Event *event;{  iterations = value;}staticvoid redraw_proc(){  xgl_context_new_frame(ctx);  page_proc();}/* =============== Z O O M M I N G  IN ! ! ================== */#undef MAX#undef MIN#define MAX(a,b)    (((a) > (b)) ? (a):(b))#define MIN(a,b)    (((a) <(b)) ? (a):(b))#define _ABS(x)	    ((x) < 0 ? -(x) : (x))static voidpix_to_world(pix_x, pix_y, wor_x, wor_y)    float     pix_x, pix_y;    float     *wor_x, *wor_y;{    *wor_x =  2*range.real*pix_x/can_wid + center.real - range.real;     *wor_y =  2*range.imag*pix_y/can_hgt + center.imag - range.imag;}/* Conversion routine for delta calculations in world coordinates*/static voidworld_delta(p1_x, p1_y, p2_x, p2_y, wor_wid, wor_hgt,diff_x, diff_y)    int	    p1_x, p1_y, p2_x, p2_y;    int     *diff_x, *diff_y, wor_wid,  wor_hgt;{    int	    sub;    /* x delta */    sub = p1_x -p2_x;    *diff_x = ((int)((wor_wid*sub)/can_wid));    /* y delta */    sub = p1_y - p2_y;    *diff_y = ((int)((-wor_hgt*sub)/can_hgt));}/* Draw the rubber-banding box for zoom */staticvoid zoom_box(pt1_x, pt1_y, pt2_x, pt2_y)float  pt1_x, pt1_y, pt2_x, pt2_y;{    Init_Pt_F2D(zoom_pts[0], pt1_x, pt1_y);    Init_Pt_F2D(zoom_pts[1], pt1_x, pt2_y);    Init_Pt_F2D(zoom_pts[2], pt2_x, pt2_y);    Init_Pt_F2D(zoom_pts[3], pt2_x, pt1_y);    Init_Pt_F2D(zoom_pts[4], pt1_x, pt1_y);    xgl_multipolyline(ctx, NULL, 1, &zoom_pl);}static	float	anchor_x, anchor_y;  /* where button goes down */static	float	last_x, last_y;/*Mouse control zoom & pan */voidzoom_pan_proc(canvas, event, arg)	Canvas canvas;Event *event;caddr_t arg;{    static	float	world_x, world_y;static	float	current_x, current_y;/* current & last allow rbbr-band */static  int     first_event = 1;  int		width, height;    /* Zoom with rubber banding */   switch(event_action(event)) {    case LOC_WINENTER:	case LOC_WINEXIT:	  xgl_window_raster_reinstall_colormap(ras);      break;    case WIN_RESIZE:      width = (int)xv_get(pw, XV_WIDTH);      height = (int)xv_get(pw, XV_HEIGHT);      xgl_window_raster_resize(ras, width, height);      break;    case WIN_REPAINT:      page_proc();    break;    case ACTION_SELECT:	if (event_is_down(event)){	        /* draw the rubberband box in white lines with XOR */		xgl_object_set(ctx, XGL_CTX_ROP, XGL_ROP_XOR, 0);		pix_to_world((float)event_x(event),			     (float)event_y(event), 			     &world_x, &world_y);		last_x    = current_x = anchor_x  = world_x;		last_y    = current_y = anchor_y  = world_y;	        first_event = 0;	} else if (event_is_up(event)){		if (first_event) break;		zoom_box(anchor_x, anchor_y, last_x, last_y);		if (last_x > anchor_x) {		    center.real   = anchor_x + (last_x - anchor_x)* 0.5;		} else {		    center.real   = anchor_x - (anchor_x - last_x)* 0.5;		}		if (last_y > anchor_y) {		    center.imag   = anchor_y + (last_y - anchor_y)* 0.5;		} else {		    center.imag   = anchor_y - (anchor_y - last_y)* 0.5;		}		range.real = _ABS(anchor_x-last_x)/2.0;		range.imag = _ABS(anchor_y-last_y)/2.0;		reset_vdc();		xgl_context_new_frame(ctx);		xgl_object_set(ctx, XGL_CTX_ROP, XGL_ROP_COPY, 0);    		page_proc();	}    break;    /*This is to zoom out */    case ACTION_ADJUST:	    if (event_is_down(event)){		   		   range.real *= 2.0;		   range.imag *= 2.0;		   reset_vdc();		   xgl_context_new_frame(ctx);		   page_proc();	    }    break;    /* Drag event !! */    case LOC_DRAG:        if (event->ie_shiftmask == 128)	  {	    if (first_event) break;     	    /* This is for drawing the rubber-banding zoom-box */	    pix_to_world((float)event_x(event),	    		 (float)event_y(event), 			  &world_x, &world_y);	    current_x = world_x;	    current_y = world_y;	    /* erase the previous box*/	    zoom_box( anchor_x, anchor_y, last_x, last_y);	    /* draw a new box */	    zoom_box( anchor_x, anchor_y, current_x, current_y);	    last_x = current_x;	    last_y = current_y;	   }	    break;    default:    break;    }	    }/* ========================================================= *//* COLORFUL 64 Crayola */#define Color_RGB(c, R, G, B) (c.rgb.r = R, c.rgb.g = G, c.rgb.b = B)staticvoid choose_cmap_proc(item, value,event)Panel_item      item;int             value;Event           *event;{    int	i;        switch(value) {      case 0:  /* crayola */	for (i = 0; i < MY_CMAP_SIZE; i++) {	    switch(i) {	      case  0: /* BLACK */      		Color_RGB( c[i], 0.00, 0.00, 0.00 ); break;	      case  1: /* APRICOT */         		Color_RGB( c[i], 1.00, 0.36, 0.30 );break;	      case  2: /* AQUAMARINE */      		Color_RGB( c[i], 0.00, 0.81, 0.64 ); break;	      case  3: /* BITTERSWEET */      		Color_RGB( c[i], 0.81, 0.04, 0.00 ); break;	      case  4: /* BLUE */      		Color_RGB( c[i], 0.00, 0.00, 1.00 ); break;	      case  5: /* BLUE_GREEN */      		Color_RGB( c[i], 0.00, 0.49, 0.25 ); break;	      case  6: /* BLUE_GREY */      		Color_RGB( c[i], 0.16, 0.09, 0.25 ); break;	      case  7: /* BLUE_VIOLET */      		Color_RGB( c[i], 0.09, 0.00, 0.20 ); break;	      case  8: /* BRICK_RED */      		Color_RGB( c[i], 0.64, 0.01, 0.00 ); break;	      case  9: /* BROWN */      		Color_RGB( c[i], 0.20, 0.03, 0.00 ); break;	      case 10: /* BURNT_ORANGE */ 		Color_RGB( c[i], 0.49, 0.62, 0.00 ); break;	      case 11: /* BURNT_SIENNA */   		Color_RGB( c[i], 0.49, 0.62, 0.04 ); break;	      case 12: /* CADET_BLUE */       		Color_RGB( c[i], 0.09, 0.09, 0.36 ); break;	      case 13: /* CARNATION_PINK */       		Color_RGB( c[i], 1.00, 0.20, 0.25 ); break;	      case 14: /* COPPER */       		Color_RGB( c[i], 0.56, 0.62, 0.00 ); break;	      case 15: /* CORNFLOWER */    		Color_RGB( c[i], 0.25, 0.25, 1.00 ); break;	      case 16: /* CYAN */    		Color_RGB( c[i], 0.00, 1.00, 1.00 ); break;	      case 17: /* FOREST_GREEN */  		Color_RGB( c[i], 0.00, 0.36, 0.09 ); break;	      case 18: /* GOLD */    		Color_RGB( c[i], 1.00, 0.20, 0.00 ); break;	      case 19: /* GOLDENROD */   		Color_RGB( c[i], 1.00, 0.36, 0.00 ); break;	      case 20: /* GRAY */      		Color_RGB( c[i], 0.50, 0.50, 0.50 ); break;	      case 21: /* GREEN */      		Color_RGB( c[i], 0.00, 1.00, 0.00 ); break;	      case 22: /* GREEN_BLUE */     		Color_RGB( c[i], 0.00, 0.25, 1.00 ); break;	      case 23: /* GREEN_YELLOW */    		Color_RGB( c[i], 0.81, 1.00, 0.00 ); break;	      case 24: /* INDIAN_RED */     		Color_RGB( c[i], 0.20, 0.00, 0.00 ); break;	      case 25: /* LAVENDAR */      		Color_RGB( c[i], 1.00, 0.12, 1.00 ); break;	      case 26: /* LEMON_YELLOW */      		Color_RGB( c[i], 1.00, 0.72, 0.04 ); break;	      case 27: /* MAGENTA */      		Color_RGB( c[i], 1.00, 0.00, 1.00 ); break;	      case 28: /* MAHOGANY */      		Color_RGB( c[i], 0.25, 0.00, 0.00 ); break;	      case 29: /* MAIZE */      		Color_RGB( c[i], 1.00, 0.25, 0.00 ); break;	      case 30: /* MAROON */      		Color_RGB( c[i], 0.30, 0.00, 0.09 ); break;	      case 31: /* MELON */      		Color_RGB( c[i], 0.81, 0.62, 0.04 ); break;	      case 32: /* MIDNITE_BLUE */      		Color_RGB( c[i], 0.00, 0.00, 0.36 ); break;	      case 33: /* MULBERRY */      		Color_RGB( c[i], 0.20, 0.00, 0.62 ); break;	      case 34: /* NAVY_BLUE */      		Color_RGB( c[i], 0.00, 0.00, 0.64 ); break;	      case 35: /* OLIVE_GREEN */      		Color_RGB( c[i], 0.64, 0.49, 0.00 ); break;	      case 36: /* ORANGE */      		Color_RGB( c[i], 1.00, 0.12, 0.00 ); break;	      case 37: /* ORANGE_RED */      		Color_RGB( c[i], 0.56, 0.01, 0.00 ); break;	      case 38: /* ORANGE_YELLOW */      		Color_RGB( c[i], 1.00, 0.49, 0.00 ); break;	      case 39: /* ORCHID */      		Color_RGB( c[i], 0.64, 0.22, 0.81 ); break;	      case 40: /* PEACH */      		Color_RGB( c[i], 1.00, 0.25, 0.30 ); break;	      case 41: /* PERIWINKLE */      		Color_RGB( c[i], 0.36, 0.36, 1.00 ); break;	      case 42: /* PINE_GREEN */      		Color_RGB( c[i], 0.00, 0.12, 0.22 ); break;	      case 43: /* PINK */      		Color_RGB( c[i], 1.00, 0.20, 0.25 ); break;	      case 44: /* PLUM */      		Color_RGB( c[i], 0.12, 0.00, 0.07 ); break;	      case 45: /* PURPLE */      		Color_RGB( c[i], 0.09, 0.00, 0.12 ); break;	      case 46: /* RAW_SIENNA */      		Color_RGB( c[i], 0.25, 0.04, 0.01 ); break;	      case 47: /* RAW_UMBER */      		Color_RGB( c[i], 0.20, 0.62, 0.00 ); break;	      case 48: /* RED */      		Color_RGB( c[i], 1.00, 0.00, 0.00 ); break;	      case 49: /* RED_ORANGE */      		Color_RGB( c[i], 1.00, 0.04, 0.00 ); break;	      case 50: /* RED_VIOLET */      		Color_RGB( c[i], 0.36, 0.00, 0.25 ); break;	      case 51: /* SALMON */      		Color_RGB( c[i], 0.36, 0.01, 0.04 ); break;	      case 52: /* SEA_GREEN */      		Color_RGB( c[i], 0.16, 1.00, 0.16 ); break;	      case 53: /* SEPIA */      		Color_RGB( c[i], 0.16, 0.03, 0.00 ); break;	      case 54: /* SILVER */      		Color_RGB( c[i], 0.49, 0.49, 0.49 ); break;	      case 55: /* SKY_BLUE */      		Color_RGB( c[i], 0.16, 0.36, 0.81 ); break;	      case 56: /* SPRING_GREEN */      		Color_RGB( c[i], 0.36, 1.00, 0.36 ); break;	      case 57: /* TAN */      		Color_RGB( c[i], 0.56, 0.12, 0.00 ); break;	      case 58: /* THISTLE */      		Color_RGB( c[i], 0.81, 0.04, 1.00 ); break;	      case 59: /* TURQUOISE_BLUE */      		Color_RGB( c[i], 0.00, 0.56, 0.64 ); break;	      case 60: /* VIOLET */      		Color_RGB( c[i], 0.09, 0.00, 0.12 ); break;	      case 61: /* VIOLET_BLUE */      		Color_RGB( c[i], 0.04, 0.00, 0.16 ); break;	      case 62: /* VIOLET_RED */      		Color_RGB( c[i], 0.64, 0.00, 0.25 ); break;	      case 63: /* WHITE */      		Color_RGB( c[i], 1.00, 1.00, 1.00 ); break;	      case 64: /* YELLOW */      		Color_RGB( c[i], 1.00, 1.00, 0.00 ); break;	      case 65: /* YELLOW_GREEN */      		Color_RGB( c[i], 0.49, 1.00, 0.00 ); break;	      case 66: /* YELLOW_ORANGE */      		Color_RGB( c[i], 1.00, 0.23, 0.00 ); break;	      default:		Color_RGB(c[i], (float)i/128.0, (float)i/128.0, (float)i/128.0);		break;	    }	}	break;      case 1:  /* green gradient */		Color_RGB(c[0], .1, .2, .4);	Color_RGB(c[MY_CMAP_SIZE -1], .8, .2, .9 );	for (i=1; i < MY_CMAP_SIZE - 1; i++) {	    Color_RGB(c[i], 0.3, (float)i/(float)MY_CMAP_SIZE, 0.3);	}	break;    }    /* create color list */    clist.start_index = 0;    clist.length = MY_CMAP_SIZE;    clist.colors = c;    if (cmap != NULL) {	xgl_object_destroy(cmap);    }    cmap = xgl_color_map_create(XGL_CMAP_COLOR_TABLE_SIZE, MY_CMAP_SIZE,			       XGL_CMAP_COLOR_TABLE, &clist, 			       0);    xgl_object_set(ras, XGL_RAS_COLOR_MAP, cmap, 0);}static voidcanvas_repaint_proc(canvas, paint_window, dpy, xwin, xrects)Canvas		canvas;Xv_Window	paint_window;Display		*dpy;Window		xwin;Xv_xrectlist	*xrects;{	page_proc();}static voidcanvas_resize_proc(canvas, width, height)Canvas	canvas;int	width, height;{    /* Get the size of the canvas in pixels */    can_wid = width;    can_hgt = height;    xgl_window_raster_resize(ras);}

⌨️ 快捷键说明

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