// Program based loosely on Apple's Simple Color QuickDraw Sample Application // SillyBalls. The program uses the QuickDraw and MacOS Carbon/Classic // Initialization routines from SillyBalls.c from Apple. // The program is a point-light display program that displays the order number // of each dot next to each dot. For instancef or the head, a "0" would be placed // next to the dot representing the head. The program is designed to allow the user // to indicate whether two point-light order numbers should be switched. If so, the // user must press the up arrow key then press the appropriate keys representing // the dot order number (0-9 for dots zero through nine, and =,/,* for 10,11 and 12 // respectively. The program records this switch and outputs a new file. // The new file will end with "_edit" #include #include #include #include #include /* Constants */ #define BobSize 24 /* Size of text in each ball */ #define NUMACTIONS 50 /* Globals */ Rect windRect; int IEWidth, IEHeight; int Datax[100][3000],Datay[100][3000]; int Avgx[100][200],Avgy[100][200]; unsigned char nameList[100][64]; SInt32 nameListSize; /* Prototypes */ void Initialize(void); void BlankScreen(void); void Dot(int x, int y, int d, int z); void swap(int i, int j); void main(void) { int x,xx,y,ty; EventRecord theEvent; int theChar; FILE * stream = NULL; int xl,yl,xr,yr,dl,dr; RGBColor ballColor; Point globalMouse; long int newLeft, newTop; long string; char buffer[128]; char *end; long numruns; int intruns; char hold[256]; Str255 ohold; int numframe[100]; int tt,ticks; int rep, numreps,numsignalreps; int b, perframe[100], clickcounter[100]; char temp[256]; unsigned long *finalTicks=0; int b1, b2, nblocks, numtrials,ordert[200],order[200], btn, temp1; long int bt,drand; int nt, tempt; int fig = 0; int numfigs=0; int currframe; int ccount; long int TempRand; int speed; int tickdelay[5]; Point dialogPt; int i = 0; int j=0; int k=0; char tempName[256]; FILE * out = NULL; int go = 0; int usd = 0; Str255 xStr,yStr,frameStr; int swap1,swap2; int tempx, tempy; FILE * swapFile = NULL; int swapf = 0; char nameFile[NUMACTIONS][80]; int outfig = 0; int eventNum; Initialize(); x=0; y=0; IEWidth=40; IEHeight=40; ballColor.red = 0; ballColor.green = 0; ballColor.blue = 0; RGBForeColor (&ballColor); xl=-200; yl=0; xr=150; yr=0; dr=100; dl=90; numreps=2; numsignalreps=1; ticks=2; tickdelay[0]=1; tickdelay[1]=2; tickdelay[2]=4; nblocks=5; numfigs=3; // Update numfigs for each customized run of program swap1 = 0; swap2 = 0; // Update nameFile for each customized run of the program // Update numfigs as well strcpy(nameFile[0], "run10"); strcpy(nameFile[1], "run5"); strcpy(nameFile[2], "run75"); /*************** open files ***************************************/ for (fig=0;fig800) { Datax[fig][tt]=0; Datay[fig][tt]=0; } if (Datay[fig][tt]>600) { Datax[fig][tt]=0; Datay[fig][tt]=0; } } fclose(stream); } do { if (GetNextEvent (keyDownMask,&theEvent)) { theChar=theEvent.message & charCodeMask; if (theChar==29) //show next signal { y=5000; SysBeep(10); } } } while (y<1000); y=0; /*************** calculate average x and y for each frame****************************/ for (fig=0;fig (2 * perframe[fig])) { tt = tt - (2*perframe[fig]); } swap1 = 0; swap2 = 0; y = 5000; } else if(theChar == 30) { j=0; k=0; do { if(GetNextEvent(keyDownMask, &theEvent)) { // 61 is '=', 47 is '/', 42 is '*' eventNum = theEvent.message & charCodeMask; if(j==0) { swap1= eventNum; if(swap1 == 61) swap1 = swap1 - 3; else if(swap1 == 47) swap1 = swap1 + 12; else if(swap1 == 42) swap1 = swap1 + 18; j++; k=0; } else { swap2=eventNum; if(swap2 == 61) swap2 = swap2 - 3; else if(swap2 == 47) swap2 = swap2 + 12; else if(swap2 == 42) swap2 = swap2 + 18; if((swap2 >=47) && (swap2 <= 60)) { if((swap1 >=47) && (swap1 <= 60)) k = 5000; else j = 0; } else j = 0; } } }while(k < 1000); tempx = Datax[fig][(swap1-48) + (tt-(perframe[fig]-1))]; tempy = Datay[fig][(swap1-48) + (tt-(perframe[fig]-1))]; Datax[fig][(swap1-48)+(tt-(perframe[fig]-1))] = Datax[fig][(swap2-48)+(tt-(perframe[fig]-1))]; Datay[fig][(swap1-48)+(tt-(perframe[fig]-1))] = Datay[fig][(swap2-48)+(tt-(perframe[fig]-1))]; Datax[fig][(swap2-48)+(tt-(perframe[fig]-1))] = tempx; Datay[fig][(swap2-48)+(tt-(perframe[fig]-1))] = tempy; swap1 = 0; swap2 = 0; y = 5000; tt=tt-(perframe[fig]); } else if(theChar == 113) { y = 5000; tt = clickcounter[fig]; } } }while(y<1000); y=0; QDFlushPortBuffer(GetQDGlobalsThePort(), NULL ); /* carbon accessor */ Delay(2,finalTicks); // use delay of 4 for applying dots BlankScreen(); } } out = fopen(strcat(nameFile[fig],"_edit"), "w"); fprintf(out, "%d\n", perframe[fig]); fprintf(out, "%d\n", numframe[fig]); for(tt=0; tt<=clickcounter[fig]; tt++) { if((Datax[fig][tt] == 0) && (Datay[fig][tt] == 0)) { fprintf(out,"%d\n",Datax[fig][tt]); fprintf(out,"%d\n",Datay[fig][tt]); } else { fprintf(out,"%d\n",Datax[fig][tt]+Avgx[fig][tt/perframe[fig]]-windRect.right/2); fprintf(out,"%d\n",Datay[fig][tt]+Avgy[fig][tt/perframe[fig]]-windRect.bottom/2); } } fclose(out); do { if(GetNextEvent(keyDownMask, &theEvent)) { y=5000; theChar=theEvent.message & charCodeMask; if (theChar == 29) //repeat { go = 1; } if (theChar == 28) //next { go = 2; fig++; usd=0; } if (theChar == 113) //stop { go = 0; } if (theChar == 30) { go = 2; usd =1; } } }while(y<1000); y=0; }while(go == 1); }while((go != 0) && (fig < numfigs)); } // // Initialize everything for the program, make sure we can run // //MW specified argument and return type. void Initialize(void) { //MW added to support new Carbon routines #if TARGET_API_MAC_CARBON BitMap theScreenBits; #endif WindowPtr mainPtr; unsigned long theDateTime; OSErr error; SysEnvRec theWorld; // // Test the computer to be sure we can do color. // If not we would crash, which would be bad. // If we canÕt run, just beep and exit. // // //MW added !TARGET_API_MAC_CARBON for Carbon version #if TARGET_API_MAC_CARBON //MW do nada now #else error = SysEnvirons(1, &theWorld); if (theWorld.hasColorQD == false) { SysBeep(50); ExitToShell(); /* If no color QD, we must leave. */ } #endif /* Initialize all the needed managers for Classic version only! */ // //MW added !TARGET_API_MAC_CARBON for Carbon version #if TARGET_API_MAC_CARBON //MW don't need to init any of the managers below for Carbon #else InitGraf(&qd.thePort); InitFonts(); InitWindows(); InitMenus(); TEInit(); InitDialogs(nil); #endif InitCursor(); // // To make the Random sequences truly random, we need to make the seed start // at a different number. An easy way to do this is to put the current time // and date into the seed. Since it is always incrementing the starting seed // will always be different. DonÕt for each call of Random, or the sequence // will no longer be random. Only needed once, here in the init. // //MW added !TARGET_API_MAC_CARBON for Carbon version #if TARGET_API_MAC_CARBON GetDateTime( &theDateTime ); SetQDGlobalsRandomSeed( theDateTime ); /* carbon accessor */ #else GetDateTime((unsigned long*) &qd.randSeed); //qd.randSeed = theDateTime; #endif // // Make a new window for drawing in, and it must be a color window. // The window is full screen size, made smaller to make it more visible. // //MW added !TARGET_API_MAC_CARBON for Carbon version #if TARGET_API_MAC_CARBON GetQDGlobalsScreenBits( &theScreenBits ); /* carbon accessor */ windRect = theScreenBits.bounds; #else windRect = qd.screenBits.bounds; #endif InsetRect(&windRect, 0, 0); mainPtr = NewCWindow(nil, &windRect, "\p", true, documentProc, (WindowPtr) -1, false, 0); //MW added for Carbon version #if TARGET_API_MAC_CARBON SetPortWindowPort( mainPtr ); /* carbon accessor */ #else SetPort( mainPtr ); /* set window to current graf port */ #endif TextSize(BobSize); /* smaller font for drawing. */ } void BlankScreen(void) { RGBColor ballColor; Rect ballRect; long int newLeft, newTop; ballColor.red = 0; ballColor.green = 0; ballColor.blue = 0; RGBForeColor(&ballColor); newTop = 0; newLeft = 0; SetRect(&ballRect, newLeft, newTop, newLeft+windRect.right, newTop+windRect.bottom); MoveTo(newLeft, newTop); PaintRect (&ballRect); ballColor.red = 65535; ballColor.green = 65535; ballColor.blue = 65535; RGBForeColor(&ballColor); } void Dot(int x, int y, int d, int z) { RGBColor ballColor; Rect ballRect; Rect bigRect; long int newLeft, newTop; newTop = y-d; newLeft = x-d; SetRect(&ballRect, newLeft, newTop, newLeft+d, newTop+d); SetRect(&bigRect, newLeft-5, newTop-5,newLeft+10,newTop+10); MoveTo(newLeft, newTop); if(z != 4) PaintOval (&ballRect); else PaintOval(&bigRect); // // Invert the color and draw the text there. This wonÕt look quite right in 1 bit // mode, since the foreground and background colors will be the same. // Color QuickDraw special cases this to not invert the color, to avoid // invisible drawing. // } void swap(int i, int j) { unsigned char tmp[64]; int k=0; //strcpy(tmp, (const char *)lNameList[i]); for(k=0;k<64;k++) tmp[k] = nameList[i][k]; for(k=0;k<64;k++) nameList[i][k] = nameList[j][k]; for(k=0;k<64;k++) nameList[j][k] = tmp[k]; }