Date: Fri, 21 Aug 1992 0:48:29 MST From: CHAYS AT MRSVAX DOT MIS DOT ARIZONA DOT EDU (Tear it down ... there's got to be a better way) Subject: some interesting performance notes for libgrx2.02 and djgpp1.08 To: djgpp AT sun DOT soe DOT clarkson DOT edu /* circle2.c * coded in C on a hot day in Tucson AZ by Chris Hays from Michael Eisenburg's * "Programming In Scheme" pc scheme implementation of circle2, * originally by John E. Connet of the University of Minnisota * * Performance Note: * * This program took 25 minutes to run using a trident SVGA card * and 14 seconds (640x480) and 37 seconds (1024x768) using an * ATI Graphics Vantage with libgrx 2.02 and DJGPP 1.08 -- a nice improvement * both cards on the same 40-Mhz 386 with 8Mbytes RAM * * don't forget to include Casa Biegl's libgrx.a when compiling */ #include #include "e:/djgpp/contrib/libgrx/include/grx.h" /* change this path to wherever Casa Biegl's grx.h is */ #define screen_region_left_x 0 #define screen_region_bottom_y 0 double square (double num); int pixel_x_distance (int pixel_x); int pixel_y_distance (int pixel_y); double matching_x (int pixel_x, int square_left_x, int square_side_length); double matching_y (int pixel_y, int square_bottom_y, int square_side_length); int single_row_loop (int row_y, int column_x, int sq_left_x, int sq_bottom_y, int sq_side_length); int choose_pen_color (int pix_x, int pix_y, int sq_left_x, int sq_bottom_y, int sq_side_length); void region_loop (int row_y, int sq_left_x, int sq_bottom_y, int sq_side_length); void circle_squared (int sq_left_x, int sq_bottom_y, int sq_side_length); int max_x, max_y, x1, y1, zoom; void main() { printf("\n\n\nEnter the x and y coordinates and the zoom factor > "); scanf("%d %d %d",&x1,&y1,&zoom); GrSetMode (GR_default_graphics); /* GrSetMode (GR_width_height_graphics,640,480); */ max_x=GrMaxX(); max_y=GrMaxY(); GrClearScreen(0); circle_squared (x1,y1,zoom); /* at 640 x 480 with 256 colors -> awesome! circle_squared (-5,-5,250); */ /* at 1024 x 768 with 16 colors -> circle_squared (80,65,355); or 85 99 1200 look interesting */ getchar();getchar(); /* extra getchar collects the enter key hit after scanf * Note: once you hit enter the second time the graphics disapears * as the video mode is set to a text mode */ GrSetMode (GR_default_text); /* GrSetMode (GR_width_height_text,80,25); */ } double square (double num) { double answer; answer = num*num; return answer; } int pixel_x_distance (int pixel_x) { int answer; answer = pixel_x - screen_region_left_x; return answer; } int pixel_y_distance (int pixel_y) { int answer; answer = pixel_y - screen_region_bottom_y; return answer; } double matching_x (int pixel_x, int square_left_x, int square_side_length) { double answer, pixel_x_d; pixel_x_d=pixel_x_distance(pixel_x); answer = square_left_x + (square_side_length * (pixel_x_d / max_x)); return answer; } double matching_y (int pixel_y, int square_bottom_y, int square_side_length) { double answer, pixel_y_d; pixel_y_d=pixel_y_distance(pixel_y); answer = square_bottom_y + (square_side_length * (pixel_y_d / max_y)); return answer; } int single_row_loop (int row_y, int column_x, int sq_left_x, int sq_bottom_y, int sq_side_length) { int pen_color; pen_color=choose_pen_color (column_x,row_y,sq_left_x,sq_bottom_y,sq_side_length); if (column_x != max_x) { GrPlot (column_x,row_y,pen_color); single_row_loop (row_y,(1+ column_x),sq_left_x,sq_bottom_y,sq_side_length); } else return 0; } int choose_pen_color (int pix_x, int pix_y, int sq_left_x, int sq_bottom_y, int sq_side_length) { long answer, match_x, match_y; match_x=square(matching_x(pix_x,sq_left_x,sq_side_length)); match_y=square(matching_y(pix_y,sq_bottom_y,sq_side_length)); answer = (match_x + match_y) % 256; return answer; } void region_loop (int row_y, int sq_left_x, int sq_bottom_y, int sq_side_length) { if (row_y >= max_y) ; else { single_row_loop (row_y, screen_region_left_x, sq_left_x, sq_bottom_y, sq_side_length); region_loop ((1+row_y), sq_left_x, sq_bottom_y, sq_side_length); } } void circle_squared (int sq_left_x, int sq_bottom_y, int sq_side_length) { region_loop (screen_region_bottom_y, sq_left_x, sq_bottom_y, sq_side_length); }