/**********************************************************************/ /* */ /* (c) Copyright, 1997 by Professor Gabriel Robins */ /* */ /* Department of Computer Science, University of Virginia */ /* Charlottesville, VA 22903-2442 (804) 982-2207 */ /* robins@cs.virginia.edu http://www.cs.virginia.edu/~robins/ */ /* */ /* This code may be freely used for all non-commercial purposes. */ /* All copies/portions of this code must contain this header. */ /* */ /**********************************************************************/ /**********************************************************************/ /* Graphics.c */ /**********************************************************************/ #include "geometry.h" /**********************************************************************/ int scale(int value) { return((int) (value * ((float) window_height) / grid_size)); } /**********************************************************************/ void draw_point(int x, int y, int diameter) { #ifdef MAC int offset= diameter/2; Rect myRect; if(GRAPHICS) { SetPort(CGWindow); SelectWindow(CGWindow); SetRect(&myRect, scale(x) - offset, scale(y) - offset, scale(x) - offset + diameter, scale(y) - offset + diameter); FillOval(&myRect, black); } #endif #ifdef SUN int offset= diameter; if(GRAPHICS) { XFillArc(the_display,window,gc, scale(x) - offset, scale(y) - offset, offset, offset, 0,64*360); XFlush(the_display); sleep(wait); } #endif } /**********************************************************************/ void draw_line(struct point p1, struct point p2, int thickness) { #ifdef MAC int offset= thickness/2; if(GRAPHICS) { SetPort(CGWindow); SelectWindow(CGWindow); PenSize(thickness,thickness); MoveTo(scale(p1.X) - offset, scale(p1.Y) - offset ); LineTo(scale(p2.X) - offset, scale(p2.Y) - offset); } #endif #ifdef SUN int offset= thickness; if (GRAPHICS) { XDrawLine ( the_display, window, gc, scale(p1.X) - offset, scale(p1.Y) - offset, scale(p2.X) - offset, scale(p2.Y) - offset); XFlush(the_display); sleep(wait); } #endif } void write_index(struct point p1, int index) { #ifdef SUN char str1[10]; if (GRAPHICS) { sprintf(str1,"%d",index); XDrawString ( the_display, window, gc, scale(p1.X), scale(p1.Y),str1,2); XFlush(the_display); sleep(wait); } #endif } /**********************************************************************/ void erase_window(void) { #ifdef MAC int x, y, diameter; if(GRAPHICS) { Rect myRect; SetPort(CGWindow); SelectWindow(CGWindow); SetRect(&myRect, 0, 0, window_width, window_height); EraseRect(&myRect); } #endif #ifdef SUN if (GRAPHICS) { XClearArea(the_display,window,0,0,0,0,1); } #endif }