Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!lll-winken!cert!netnews.upenn.edu!eniac.seas.upenn.edu!eck From: eck@eniac.seas.upenn.edu (Brian Eck) Newsgroups: comp.sys.mac.programmer Subject: Think C question Message-ID: <30876@netnews.upenn.edu> Date: 10 Oct 90 01:00:09 GMT Sender: news@netnews.upenn.edu Reply-To: eck@eniac.seas.upenn.edu (Brian Eck) Distribution: usa Organization: University of Pennsylvania Lines: 144 I am trying to write the contents of an array of integers to the screen. The array is two dimensional; it is a representation of an electric field. I would like to write the values at integer-valued points in the field at each iteration of the field update. I have tried DrawString and DrawChar, but have met with little success. I get output, but it's garbage. Here's the source: #include #define BASE_RES_ID 400 #define NIL_POINTER 0L #define MOVE_TO_FRONT -1L #define REMOVE_ALL_EVENTS 0 #define GRIDX 40 #define GRIDY 40 #define POINTS 2 #define TOLERANCE 4 int grid [GRIDY] [GRIDX]; int oldgrid [GRIDY] [GRIDX]; struct coordinates { int x, y, val; } field [POINTS]; int i, o, t; int loop = 0; int tolerance = TOLERANCE; WindowPtr gPictureWindow; /*** Main ***/ main() { ToolBoxInit(); WindowInit(); MainLoop(); while(!Button()); } /*** ToolBoxInit ***/ ToolBoxInit() { InitGraf(&thePort); InitFonts(); FlushEvents(everyEvent,REMOVE_ALL_EVENTS); InitWindows(); InitMenus(); TEInit(); InitDialogs(NIL_POINTER); InitCursor(); } /*** WindowInit ***/ WindowInit() { gPictureWindow = GetNewWindow(BASE_RES_ID, NIL_POINTER, MOVE_TO_FRONT); ShowWindow(gPictureWindow); SetPort(gPictureWindow); } /*** MainLoop ***/ MainLoop() { /*** FieldInit ***/ field[0].y = 19; field[0].x = 25; field[0].val = 100; field[1].y = 19; field[1].x = 15; field[1].val = 100; /*** GridInit ***/ for (i=0; i= TOLERANCE) && (loop<100)) { ++loop; tolerance = 0; for (i = 0; i < GRIDY; i++) /* copy grid */ for (o = 0; o < GRIDX; o++) oldgrid [i] [o] = grid [i] [o]; for (i = 1; i < GRIDY - 1; i++) /* recalculate */ { for (o = 1; o < GRIDX - 1; o++) { if (NotInField(i,o)) { grid[i][o] = (oldgrid [i-1] [o] + oldgrid [i+1] [o] + oldgrid [i] [o-1] + oldgrid [i] [o+1])/4; t = grid [i-1] [o] - grid [i] [o]; if (t>tolerance) tolerance = t; } MoveTo ((o*10),(i*10)); TextSize(9); DrawChar(grid[i][o]); } } } } /*** Not In Field ***/ NotInField(y,x) { int i, o; for (i = 0; i < POINTS; i++) if ((field[i].x == x) && (field[i].y == y)) return(0); return(1); } Please do not chastise me too severely if I am making a ridiculous error; I kind of jumped into a project that is a bit over my head (crazy Toolbox...) Brian eck@eniac.seas.upenn.edu