int main (void) { int xSize=600, ySize=600, xMouse, yMouse, j; float h=100; char c; gfx_open(xSize, ySize, "Window"); while (1) { c = gfx_wait(); xMouse = gfx_xpos(); yMouse = gfx_ypos(); switch (c) { case '0': draw_zero(xMouse, yMouse, h); break; case '1': draw_one(xMouse, yMouse, h); break; case '2': draw_two(xMouse, yMouse, h); break; case '3': draw_three(xMouse, yMouse, h); break; case '4': draw_four(xMouse, yMouse, h); break; case '5': draw_five(xMouse, yMouse, h); break; case '6': draw_six(xMouse, yMouse, h); break; case '7': draw_seven(xMouse, yMouse, h); break; case '8': draw_eight(xMouse, yMouse, h); break; case '9': draw_nine(xMouse, yMouse, h); break; case '-': h = h/2; break; case '=': h = h*2; break; case 'q': return 0; } } return 0; }
int main() { int xsize = 500; int ysize = 300; char c; // Open a new window for drawing. gfx_open(xsize, ysize, "Example Graphics Program"); // Clear the background. gfx_clear(); // Set the current drawing color gfx_color(0,200,100); // Draw a triangle on the screen. gfx_line(100,100,200,100); gfx_line(200,100,150,150); gfx_line(150,150,100,100); // change color, and draw a circle gfx_color(200,100,50); gfx_circle(300,150,40); while(1) { // Wait for the user to press a character. c = gfx_wait(); // Quit if it is the letter q. if(c=='q') break; } return 0; }
int main(int argc, char *argv[]) { if (argc > 1) file = fopen(argv[1], "r"); gfx_open(width*sizex, width*sizey, "Life"); // cycle through cells to determine next generation state of each, not including edges for simplicity while(1){ if (choice!='p') input(&argc); system("clear"); if (choice=='q') break; neighborcount(); // display next generation for(y=0; y<sizey; y++){ for(x=0; x<sizex; x++){ // transfer state data from temp to new generation life grid if (edit != 1) life[y][x]=temp[y][x]; // reset temp grid temp[y][x]=0; if (life[y][x]==1){ gfxcell(x, y); } } } gfx_flush(); usleep(75000); if (edit != 1) gfx_clear(); } }
int main() { int ysize = 300; int xsize = 300; char c; // Open a new window for drawing. gfx_open(xsize,ysize,"Example Graphics Program"); // Set the current drawing color to green. gfx_color(0,200,100); // Draw a triangle on the screen. gfx_line(100,100,200,100); gfx_line(200,100,150,150); gfx_line(150,150,100,100); while(1) { // Wait for the user to press a character. c = gfx_wait(); if(c=='n') gfx_line(200,200,300,200); gfx_line(300,200,250,250); gfx_line(250,250,200,200); // Quit if it is the letter q. if(c=='q') break; } return 0; }
int main() { char fractal; int x=width/2,y=height/2,radius=width/3; int margin=20; int x1=margin,x2=width-margin,x3=width/2,y1=margin,y2=margin,y3=height-margin; gfx_open(width,height,"Fractals"); gfx_clear_color(0,0,0); gfx_clear(); gfx_color(255,255,255); printf("Which fractal would you like to see?\n1: Sierpinski Triangles\n2: Shrinking Squares\n3: Spiral Squares\n4: Circular Lace\n5: Snowflake\n6: Tree\n7: Fern\n8: Spiral of Spirals\n\n"); while(fractal!='q'){ fractal=gfx_wait(); gfx_clear(); switch(fractal){ case 'q': return 0; break; case '1': printf("Sierpinski Triangles\n\n"); sierpTriangles(x1,y1,x2,y2,x3,y3); break; case '2': printf("Shrinking Squares\n\n"); shrinkSquares(x,y,width/4); break; case '3': printf("Spiral Squares\n\n"); spiralSquares(x,y,-M_PI/4,width*2/3); break; case '4': printf("Circular Lace\n\n"); circularLace(x,y,width); break; case '5': printf("Snowflake\n\n"); snowflake(x,y,radius); break; case '6': printf("Tree\n\n"); tree(x,height,x,height*3/4,0,height/4); break; case '7': printf("Fern\n\n"); fern(width/2,height-margin,2*height/3,0); break; case '8': printf("Spiral of Spirals\n\n"); spiralSpirals(x,y,0,width); break; default: printf("Please enter a valid option\n\n"); break; } } }
int main() { int height, width; height=700; width=700; srand(time(NULL)); gfx_open(width, height, "Asteroids"); flyship(); return 0; }
int main () { int x, y, dx, dy, radius = 100; double pi, i = 0.07; char c; pi = M_PI; gfx_open(500,500,"Rotating Animation Emily"); printf("To speed up display press f key; to slow down display press s key.\n"); while (1) { drawPerson(); x = radius*cos(i) + 250; y = radius*sin(i) + 150; gfx_color(0, 0, 255); gfx_circle(x, y, 20); //ball 1 (blue) x = radius*cos(i+1.5) + 250; y = radius*sin(i+1.5) + 150; gfx_color(0, 255, 0); gfx_circle(x, y, 20); //ball 2 (green) x = radius*cos(i+3.) + 250; y = radius*sin(i+3.) + 150; gfx_color(255, 0, 0); gfx_circle(x, y, 20); //ball 3 (red) gfx_flush(); usleep(10000); gfx_clear(); if (gfx_event_waiting()) { c = gfx_wait(); if (c =='s') { //slows down juggling i-=0.1; } else if (c =='f') { //speeds juggling i+=0.1; } else if (c =='q') { break; } } i+= 0.01; } return 0; }
int main() { int width = 400; int height = 550; int gameLoop = 1; int highScore = 0; gfx_open(width, height, "Flappy Bird"); //create two pipes to be recycled Pipe* leadPipe = (Pipe*)malloc(sizeof(Pipe)); Pipe* trailPipe = (Pipe*)malloc(sizeof(Pipe)); while (gameLoop) { //initialize each pipe initializePipe(leadPipe, width, height); initializePipe(trailPipe, width, height); //set background color gfx_clear_color(85, 203, 217); gfx_clear(); //present game home screen char c; int flap = 0; double birdX = 150, birdY = 275, birdR = 12, degrees = 0; while (1) { gfx_clear(); if(gfx_event_waiting()){ if(gfx_wait()==' ') break; } presentHomeScreen(width, height); stationaryBird(&birdY,degrees); flap = drawBird(birdX, birdY, birdR, flap); gfx_flush(); usleep(50000); degrees+=(2*M_PI)/20; } //begin animation int score = startGame(leadPipe, trailPipe, width, height); highScore = endGame(score, highScore, width, height); char d; } return 0; }
int main(void) { gfx_open(400,400,"Bounce"); int stillGoing = 1; float dt = 0.01; float xpos =rand() %400+1; float ypos =rand() %400+1; float xvel =(double)rand()/RAND_MAX * 10.0 - 5.0; float yvel =(double)rand()/RAND_MAX * 10.0 - 5.0; float RIGHT_EDGE = 400; float LEFT_EDGE = 0; float TOP = 0; float BOTTOM = 400; while(stillGoing){ xpos += xvel; ypos += yvel; if(xpos <= LEFT_EDGE || xpos >= RIGHT_EDGE) xvel *=-1; if(ypos <= TOP || ypos >= BOTTOM) yvel *= -1; gfx_clear(); drawPoly(30,xpos,ypos); gfx_flush(); usleep(10000); if(gfx_event_waiting()){ char c = gfx_wait(); if(c==1){ xpos = gfx_xpos(); ypos = gfx_ypos(); xvel =(double)rand()/RAND_MAX * 10.0 - 5.0; yvel =(double)rand()/RAND_MAX * 10.0 - 5.0; } else if (c=='q' || c=='Q'){ break; } } } return 0; }
int main() { int i,ic,height=650, width=1200; int lives=5, level=1; int fgx=12, fgy=11, *frogx=&fgx, *frogy=&fgy; int row=13,col=25,board[row][col]; //dimensions char direction='R', play; int wnum=50, wseg=width/wnum, hnum=100, hseg=height/hnum, boardw=2*wseg, boardh=8*hseg; gfx_open(width,height,"Frogger"); //open graphics window play=welcome(); //begin game while(play!='q'){ //while user wants to play the game and not quit background(width,height,level); //eventaully this will be in draw function draw_lives(lives); //evnetually in draw function drawfrog(*frogx,*frogy,boardw,boardh,direction);//eventuall in draw function usleep(500000); if (gfx_event_waiting() == 1){ //if user tries to move frog direction = hopper(frogx,frogy); //move frog according to input if valid } /*switch(board[*frogx][*frogy]){ case 0: //frog dies in this location lives=lives-1; if(lives==0){ play=blood(); //game over, play again or end lives=5; } level=1; //reset everything here NEED TO DO break; case 1: //frog can be in this location and game continues break; case 2: //frog made it to lilly pad level++; if (level>5){ play=win();//you won! if (play != 'q'){ level = 1; lives = 5; } } break; }*/ } }
//begin main function int main (void) { int xsize = 800, ysize = 800 ; gfx_open( xsize, ysize, "Test Graph of Function triangle_waveform" ) ; int stillgoing = 1; while (stillgoing) { gfx_clear() ; gfx_color(255, 255, 255) ; //axis is white draw_axes( xsize, ysize) ; gfx_color(150, 0, 255) ; plot_triangle(xsize, ysize, -10., 10, .1) ; gfx_flush() ; char c = gfx_wait() ; if (c == 'q') stillgoing = 0 ; } return 0 ; } //end main
int main() { int size = 500; int value = 1; int wait; int counter = 0; gfx_open(size, size, "Graphing Calculator"); while(value != 0) { gfx_color(255, 255, 255); xAxis(size, size); yAxis(size, size); wait = gfx_wait(); gfx_color(255, 0, 0); switch(wait) { case 1: gfx_clear(); counter = 0; plot(size, size, counter); break; case '=': gfx_clear(); counter++; plot(size, size, counter); break; case '-': gfx_clear(); counter--; plot(size, size, counter); break; case 'q': value = 0; break; default: break; } printf("%i\n", counter); } return 0; }
int main(){ char c; int width = 500, height = 500, num = 1; double x = 1; gfx_open(width, height, "Taylor Series Graph"); while(c != 'q'){ gfx_clear(); xAxis(); yAxis(); plot(num); c = gfx_wait(); switch(c){ case '=': num++; break; case '-': num--; break; } } }
int main () { char userInput; int i, sideLength; double theta, dtheta, numberSides; double x, y; double x_new, y_new; gfx_open(500,500,"Symbol_Emily_Koh"); //gfx_xpos(); gets x coordinates of mouse pointer //gfx_ypos(); gets y coordinates of mouse pointer while (1) { gfx_event_waiting(); if (gfx_event_waiting() == True) { userInput = gfx_wait(); } if (userInput == 1) { //if user clicks mouse button 1 then display blue square gfx_color(0, 0, 255); //dictates color as blue x = gfx_xpos(); y = gfx_ypos(); gfx_line(x-50, y-50, x-50, y+50); gfx_line(x-50, y-50, x+50, y-50); gfx_line(x+50, y-50, x+50, y+50); gfx_line(x+50, y+50, x-50, y+50); } else if (userInput == 't') { //if user types in t then display green triangle gfx_color(0, 255, 0); //dictates color as green x = gfx_xpos(); y = gfx_ypos(); gfx_line(x-50, y-50, x+50, y-50); gfx_line(x-50, y-50, x, y+50); gfx_line(x, y+50, x+50, y-50); } else if (userInput == 'c') { //if user types in c then display white circle gfx_color(255, 255, 255); //dictates color as white x = gfx_xpos(); y = gfx_ypos(); gfx_circle(x, y, 50); //circle centered at x, y, and with radius 50 } else if (userInput >= '3' && userInput <= '9') { //if user types in numbers 3~9, display purple polygon with that many sides sideLength = 30; numberSides = userInput - '0'; //makes numberSides = number of polygon sides dtheta = (2*M_PI/numberSides); //calculate the angle at which line will rotate theta = 0; gfx_color(171, 92, 223); //dictates color as purple x = gfx_xpos(); y = gfx_ypos(); x = x + (sideLength/2); //to center polygon, shift polygon by this x and the following y value y = y + (sideLength/(2*tan(M_PI/numberSides))); //apothem - perpendicular y distance for (i = 0; i < numberSides; i++) { theta += dtheta; x_new = x + sideLength*cos(theta); y_new = y - sideLength*sin(theta); gfx_line(x, y, x_new, y_new); gfx_flush(); x = x_new; y = y_new; } userInput = '0'; } else if (userInput == 'q') { //if user types in q then quit program break; } } // gcc symbol.c gfx_mac.o -lX11 -lm -I/opt/X11/include/ -L/opt/X11/lib/ -o symbol return 0; }
int main(void) // we will be constructing a symbolic typewriter using a basic graphics library { int mousePosX; // mouse point position in x and y directions int mousePosY; int screenX = 900; // screen resolution in pixels int screenY = 900; float x1; // position 1 float y1; float x2; // position 2 float y2; float radians; // need radians and radius when dealing with polar coordinated float radius; float pi = atan(1)*4; // pi constant int min = 0; // minimum number of degrees int c = 0; // counter for for loops int randomDegrees = 0; // random integer degree int polygon = 0; // place for number of polygon sides char user; // this will be the value of the user input srand(time(NULL)); // random integer seed // begin symbolic typewriter gfx_open(screenX, screenY, "Symbolic Typewriter"); while( 1 ) { user = gfx_wait(); // waiting for a user-given symbol switch( user ) { case 1: // mouse click, we will print a blue square outline { gfx_color(0, 0, 255); // changing color to blue radius = 25; mousePosX = gfx_xpos(); // storing the current mouse position mousePosY = gfx_ypos(); x1 = mousePosX + radius; // upper right point y1 = mousePosY + radius; x2 = mousePosX - radius; // upper left point y2 = mousePosY + radius; gfx_line((int)x1, (int)y1, (int)x2, (int)y2); // top line x1 = mousePosX + radius; // upper right point y1 = mousePosY + radius; x2 = mousePosX + radius; // lower right point y2 = mousePosY - radius; gfx_line((int)x1, (int)y1, (int)x2, (int)y2); // right line x1 = mousePosX + radius; // lower right point y1 = mousePosY - radius; x2 = mousePosX - radius; // lower left point y2 = mousePosY - radius; gfx_line((int)x1, (int)y1, (int)x2, (int)y2); // lower line x1 = mousePosX - radius; // lower left point y1 = mousePosY - radius; x2 = mousePosX - radius; // upper left point y2 = mousePosY + radius; gfx_line((int)x1, (int)y1, (int)x2, (int)y2); // left line gfx_flush(); // actually draw the square break; } case 't': // display a green triangle outline { gfx_color(0, 255, 0); // changing color to green radius = 25; mousePosX = gfx_xpos(); // storing the current mouse position mousePosY = gfx_ypos(); x1 = mousePosX; // upper point y1 = mousePosY - radius; x2 = mousePosX + radius; // lower right point y2 = mousePosY + radius; gfx_line((int)x1, (int)y1, (int)x2, (int)y2); // right line x1 = mousePosX + radius; // lower right point y1 = mousePosY + radius; x2 = mousePosX - radius; // lower left point y2 = mousePosY + radius; gfx_line((int)x1, (int)y1, (int)x2, (int)y2); // bottom line x1 = mousePosX - radius; // lower left point y1 = mousePosY + radius; x2 = mousePosX; // upper point y2 = mousePosY - radius; gfx_line((int)x1, (int)y1, (int)x2, (int)y2); // left line gfx_flush(); break; } case 'c': // display a white circle outline { gfx_color(255, 255, 255); // change the color to white radius = 25; // circle radius of 5 pixels mousePosX = gfx_xpos(); mousePosY = gfx_ypos(); x2 = mousePosX + radius; // determine the first point y2 = mousePosY; for( c = 0; c <= 360; c++ ) // go through an entire circle (convert to radians) { x1 = x2; // assign the last point to be the first point for the next line y1 = y2; x2 = mousePosX + (cos(c*pi/180)*radius); y2 = mousePosY + (sin(c*pi/180)*radius); gfx_line((int)x1, (int)y1, (int)x2, (int)y2); } gfx_flush(); break; } case '3': case '4': case '5': case '6': case '7': case '8': case '9': // print a polygon with the alotted number of sides { switch ( user ) // find the integer number of sides { case '3': { polygon = 3; min = 80; // setting the minimum degrees between each point break; // the angle must be between this min and 360/sides } case '4': { polygon = 4; min = 65; break; } case '5': { polygon = 5; min = 62; break; } case '6': { polygon = 6; min = 55; break; } case '7': { polygon = 7; min = 50; break; } case '8': { polygon = 8; min = 45; break; } case '9': { polygon = 9; min = 39; break; } } gfx_color(150, 0, 150); // change the color to purple radius = 50; randomDegrees = 0; mousePosX = gfx_xpos(); mousePosY = gfx_ypos(); x2 = mousePosX + radius; // determine the first point y2 = mousePosY; for( c = 1; c < polygon; c++ ) // making only the specified number of points { x1 = x2; // assign the last point to be the first point for the next line y1 = y2; randomDegrees = randomDegrees + (min + (rand() % ((360 / polygon)-min+2))); // random integer degree limit // the degrees added are in the range of min to max, where the max is dependent on the number of sides x2 = mousePosX + (cos(randomDegrees*pi/180)*radius); y2 = mousePosY + (sin(randomDegrees*pi/180)*radius); gfx_line((int)x1, (int)y1, (int)x2, (int)y2); } x1 = x2; // for the last point we need to make sure it returns to the original point y1 = y2; x2 = mousePosX + radius; y2 = mousePosY; gfx_line((int)x1, (int)y1, (int)x2, (int)y2); gfx_flush(); break; } case ' ': // clear the graphics window { gfx_clear(); break; } case 'q': // quit the graphics window { break; } } if( user == 'q' ) // quitting actual while loop { break; } } }
int main( int argc, /* arg count */ char * argv[] /* arg vector */ ){ static char * context = "main(chain)"; char * stem = NULL; /* dump filename stem */ char * suffix = NULL; /* dump filename suffix */ char * suff2 = NULL; /* last half of suffix */ int nr, nc; /* integer matrix sizes */ int n; /* square matrix/vector size */ real base_x, base_y; /* base of Mandelbrot */ real ext_x, ext_y; /* extent of Mandelbrot */ int limit, seed; /* randmat controls */ real fraction; /* invperc/thresh filling */ int itersLife; /* life iterations */ int itersElastic, relax; /* elastic controls */ int2D i2D; /* integer matrix */ bool2D b2D; /* boolean matrix */ pt1D cities; /* cities point vector */ int n_cities; /* number of cities */ pt1D net; /* net point vector */ int n_net; /* number of net points */ real2D r2D_gauss; /* real matrix for Gaussian */ real2D r2D_sor; /* real matrix for SOR */ real1D r1D_gauss_v; /* real vector input for Gaussian */ real1D r1D_sor_v; /* real vector input for SOR */ real1D r1D_gauss_a; /* real vector answer for Gaussian */ real1D r1D_sor_a; /* real vector answer for SOR */ real1D r1D_gauss_c; /* real vector check for Gaussian */ real1D r1D_sor_c; /* real vector check for SOR */ real tol; /* SOR tolerance */ real realDiff; /* vector difference */ bool choicesSet = FALSE; /* path choices set? */ bool doMandel = TRUE; /* mandel vs. randmat */ bool doInvperc = TRUE; /* invperc vs. thresholding */ bool doDump = FALSE; /* dump intermediate results? */ int argd = 1; /* argument index */ /* arguments */ #if NUMA MAIN_INITENV(,32000000) #endif while (argd < argc){ CHECK(argv[argd][0] == '-', fail(context, "bad argument", "index", "%d", argd, NULL)); switch(argv[argd][1]){ case 'E' : /* elastic */ itersElastic = arg_int(context, argc, argv, argd+1, argv[argd]); relax = arg_int(context, argc, argv, argd+2, argv[argd]); argd += 3; break; case 'F' : /* fraction (invperc/thresh) */ fraction = arg_real(context, argc, argv, argd+1, argv[argd]); argd += 2; break; case 'L' : /* life */ itersLife = arg_int(context, argc, argv, argd+1, argv[argd]); argd += 2; break; case 'M' : /* mandel */ base_x = arg_real(context, argc, argv, argd+1, argv[argd]); base_y = arg_real(context, argc, argv, argd+2, argv[argd]); ext_x = arg_real(context, argc, argv, argd+3, argv[argd]); ext_y = arg_real(context, argc, argv, argd+4, argv[argd]); argd += 5; break; case 'N' : /* winnow */ n_cities = arg_int(context, argc, argv, argd+1, argv[argd]); argd += 2; break; case 'R' : /* randmat */ limit = arg_int(context, argc, argv, argd+1, argv[argd]); seed = arg_int(context, argc, argv, argd+2, argv[argd]); argd += 3; break; case 'S' : /* matrix size */ nr = arg_int(context, argc, argv, argd+1, argv[argd]); nc = arg_int(context, argc, argv, argd+2, argv[argd]); argd += 3; break; case 'T' : /* SOR tolerance */ tol = arg_real(context, argc, argv, argd+1, argv[argd]); argd += 2; break; case 'c' : /* choice */ CHECK(!choicesSet, fail(context, "choices already set", NULL)); suffix = arg_str(context, argc, argv, argd+1, argv[argd]); argd += 2; switch(suffix[0]){ case 'i' : doInvperc = TRUE; break; case 't' : doInvperc = FALSE; break; default : fail(context, "unknown choice(s)", "choice", "%s", suffix, NULL); } switch(suffix[1]){ case 'm' : doMandel = TRUE; break; case 'r' : doMandel = FALSE; break; default : fail(context, "unknown choice(s)", "choice", "%s", suffix, NULL); } suff2 = suffix+1; choicesSet = TRUE; break; case 'd' : /* dump */ doDump = TRUE; argd += 1; if ((argd < argc) && (argv[argd][0] != '-')){ stem = arg_str(context, argc, argv, argd, argv[argd-1]); argd += 1; } break; #if GRAPHICS case 'g' : gfx_open(app_chain, arg_gfxCtrl(context, argc, argv, argd+1, argv[argd])); argd += 2; break; #endif #if MIMD case 'p' : DataDist = arg_dataDist(context, argc, argv, argd+1, argv[argd]); ParWidth = arg_int(context, argc, argv, argd+2, argv[argd]); argd += 3; break; #endif case 'u' : io_init(FALSE); argd += 1; break; default : fail(context, "unknown flag", "flag", "%s", argv[argd], NULL); break; } } CHECK(choicesSet, fail("context", "choices not set using -c flag", NULL)); /* initialize */ #if MIMD sch_init(DataDist); #endif /* mandel vs. randmat */ if (doMandel){ mandel(i2D, nr, nc, base_x, base_y, ext_x, ext_y); if (doDump) io_wrInt2D(context, mkfname(stem, NULL, suff2, "i2"), i2D, nr, nc); } else { randmat(i2D, nr, nc, limit, seed); if (doDump) io_wrInt2D(context, mkfname(stem, NULL, suff2, "i2"), i2D, nr, nc); } /* half */ half(i2D, nr, nc); if (doDump) io_wrInt2D(context, mkfname(stem, "h", suff2, "i2"), i2D, nr, nc); /* invperc vs. thresh */ if (doInvperc){ invperc(i2D, b2D, nr, nc, fraction); if (doDump) io_wrBool2D(context, mkfname(stem, NULL, suffix, "b2"), b2D, nr, nc); } else { thresh(i2D, b2D, nr, nc, fraction); if (doDump) io_wrBool2D(context, mkfname(stem, NULL, suffix, "b2"), b2D, nr, nc); } /* life */ life(b2D, nr, nc, itersLife); if (doDump) io_wrBool2D(context, mkfname(stem, "l", suffix, "b2"), b2D, nr, nc); /* winnow */ winnow(i2D, b2D, nr, nc, cities, n_cities); if (doDump) io_wrPt1D(context, mkfname(stem, "w", suffix, "p1"), cities, n_cities); /* norm */ norm(cities, n_cities); if (doDump) io_wrPt1D(context, mkfname(stem, "n", suffix, "p1"), cities, n_cities); /* elastic */ n_net = (int)(ELASTIC_RATIO * n_cities); CHECK(n_net <= MAXEXT, fail(context, "too many net points required", "number of net points", "%d", n_net, NULL)); elastic(cities, n_cities, net, n_net, itersElastic, relax); if (doDump) io_wrPt1D(context, mkfname(stem, "e", suffix, "p1"), net, n_net); /* outer */ n = n_net; outer(net, r2D_gauss, r1D_gauss_v, n); if (doDump){ io_wrReal2D(context, mkfname(stem, "o", suffix, "r2"), r2D_gauss, n, n); io_wrReal1D(context, mkfname(stem, "o", suffix, "r1"), r1D_gauss_v, n); } cpReal2D(r2D_gauss, r2D_sor, n, n); cpReal1D(r1D_gauss_v, r1D_sor_v, n); /* gauss */ gauss(r2D_gauss, r1D_gauss_v, r1D_gauss_a, n); if (doDump) io_wrReal1D(context, mkfname(stem, "g", suffix, "r1"), r1D_gauss_a, n); /* product (gauss) */ product(r2D_gauss, r1D_gauss_a, r1D_gauss_c, n, n); if (doDump) io_wrReal1D(context, mkfname(stem, "pg", suffix, "r1"), r1D_gauss_c, n); /* sor */ sor(r2D_sor, r1D_sor_v, r1D_sor_a, n, tol); if (doDump) io_wrReal1D(context, mkfname(stem, "s", suffix, "r1"), r1D_gauss_a, n); /* product (sor) */ product(r2D_sor, r1D_sor_a, r1D_sor_c, n, n); if (doDump) io_wrReal1D(context, mkfname(stem, "ps", suffix, "r1"), r1D_gauss_c, n); /* difference */ vecdiff(r1D_gauss_a, r1D_sor_a, n, &realDiff); if (doDump) io_wrReal0D(context, mkfname(stem, "v", suffix, "r0"), realDiff); #if IEEE ieee_retrospective(stderr); #endif #if NUMA MAIN_END; #endif return 0; }
int main (void) { char c; int xsize=350, ysize=350, vseed, j; float x=175, y=175, vx, vy, xMouse, yMouse, dt=1, r=15, ypos, i, di=.1, pi=3.14159; gfx_open(xsize, ysize, "Bouncing Ball"); gfx_color(0, 200, 100); srand(time(0)); vseed = rand()%100; vx = cos((float)vseed/15.915); vy = sin((float)vseed/15.915); while (1) { for (i=0; i<2*pi; i+=di) { gfx_line(r*cos(i)+x, -r*sin(i)+y, r*cos(i+di)+x, -r*sin(i+di)+y); } gfx_flush(); usleep(dt*10000); gfx_clear(); x = x+vx*dt; y = y+vy*dt; if ( x<=15 || x>=335 ) vx = -vx; if ( y<=15 || y>=335 ) vy = -vy; j = gfx_event_waiting(); if (j) { c = gfx_wait(); switch (c) { case 'q': return 0; case 1: xMouse = gfx_xpos(); yMouse = gfx_ypos(); x = xMouse; y = yMouse; vseed = rand()%100; vx = cos((float)vseed/15.915); vy = sin((float)vseed/15.915); break; } } } return 0; }
int main(){ int xposS = 370; char c; //user input int xdist = 0, ydist =0; int dx = 1; int Bnum = 0; int posB[2][10] = {0}; unsigned int i, j; gfx_open(SIZEX, SIZEY, "Space Invaders"); //open window initializeBullets(posB); while(true){ gfx_clear(); //clear screen dispScore(); uShooter(xposS); drawAliens(xdist, ydist); if(gfx_event_waiting()){ //if true c = gfx_wait(); //find choice if (c == 'b'){ xposS-=10; if (xposS <= 0) xposS = 0; }else if (c == 'n'){ xposS +=10; if (xposS >= SIZEX-30) xposS = SIZEX-30; }else if (c == ' '){ for(i=0; i<10; i++){ if(posB[0][i] == -1){ posB[0][i] = drawBullet(xposS); posB[1][i] = YPOS; } } }else if (c == 'q') return 0; else continue; } xdist+=dx; if(xdist>=370 || xdist <=-100){ dx*=-1; } if(xdist == 370 || xdist ==-100){ ydist +=5; } if(ydist == 225) return 0; //change lives num for(j=0; j<10; j++){ if(posB[0][j] != -1){ moveBullet(posB, j); } checkBullet(posB,j); } usleep(25000); gfx_flush(); } }
int main() { int i,ic; //variables for incrementing in for loops int lives=5, level=1; //initialize lives and level int fgx=12, fgy=11, *frogx=&fgx, *frogy=&fgy; //initialize frog position int row=12,col=25,board[row][col]; //dimensions for board char play; //declare play character int x[19]= {5-width/4,width+5,10-width/4,15-width/4,width+10,5-width/2,1.2*width,10-width/2,15-width/2,1.2*width,5-width,1.5*width,10-width,15-width,1.5*width,width+5,5-width,width+10,10-width/2}; //array of starting positions of moving objects //initialize board for(i=0; i<6; i++) for(ic=0; ic<col; ic++) board[i][ic]=0; for(i=6; i<row; i++) for(ic=0; ic<col; ic++) board[i][ic]=1; for(i=2; i<col; i+=4) board[0][i]=2; gfx_open(width,height,"Frogger"); //open graphics window play=welcome(); //begin game while(play!='q') { //while user wants to play the game and not quit background(level); draw_lives(lives); draw(col,board,level,x,frogx,frogy); drawfrog(*frogx,*frogy,play); gfx_flush(); usleep(100000); /* for(i=0;i<row;i++){ //prints board in terminal for(ic=0;ic<col;ic++) printf("%d",board[i][ic]); printf("\n"); } //end for(i=0;i<row;i++) printf("\n"); */ if (gfx_event_waiting()) { //if user tries to move frog play = hopper(frogx,frogy,row,col); //move frog according to input if valid } //end if (gfx_event_waiting()) switch(board[*frogy][*frogx]) { case 0: //frog dies in this location lives--; //lose a life *frogx=12; *frogy=11; if(lives==0) { play=blood(); //game over, play again or end lives=5; level=1; } //end if(lives==0) break; case 1: //frog can be in this location and game continues break; case 2: //frog made it to lilly pad level++; //level up *frogx=12; *frogy=11; if (level>5) { play=win();//you won! level = 1; lives = 5; } //end if (level>5) break; } //end switch(board[*frogx][*frogy]) } //end while(play!='q') } //end main
int main() { // Print instructions for user printf("Asteroid!\nTry to collect as many colored circles as you can.\nThe game is simple. Use the arrow keys to navigate your rocket.\nUp accelerates\nDown brakes immediately\nLeft and Right turn your rocket.\n\nHave fun!!\n"); // Define variables int xSize=800, ySize=600; char c; int stillgoing=1; float xc=xSize/2, yc=ySize/2, *pxc=&xc, *pyc=&yc; float dr=.1; // rotation increment int sign = 1; // rotation sign int r = 15; // box radius int i; // box counter int j; // triangle counter double rotatea=0; // rotation angle of rocket float dx=0, dy=0; // chane in position of rocket float dt=0; // change in time for acceleration float accel=.07; // acceleration of rocket srand(time(NULL)); int rCir=0; // radius of circle int xCir=xc,yCir=yc; // position of circle's center int rC=255,gC=255,bC=255; // circle color int cirCount=-1; // number of circles collected(starts at -1 because initial circle is created at center, then random placement begins. Fisrt circle placed at center does not count towards total. int isaccel=0; double rotatet=rotatea; double yRotate=0, xRotate=0; float xB, yB; // position of fired shot gfx_open(xSize,ySize,"Rocketship!"); startGame(xSize, ySize); while(stillgoing==1) { gfx_clear(); drawAsteroid(xCir,yCir,rCir,rC,gC,bC); drawRocket(xc,yc,rotatet,r); // uses rotatet, because this will draw the rocket as turning when the left/right arrows are pressed scoreboard(cirCount); gfx_flush(); usleep(2000); if(gfx_event_waiting()){ c=gfx_wait(); switch(c){ case 'R': // Accelerate dt+=.01; dx+=accel*dt; // increases speed dx by increasing the time and adding to dx if(dx>.8) dx=.8; // this caps dx and dy at 1. Thus the maximum speed is dx=dy=1 dy=dx; isaccel=1; // the rocket is currently accelerating break; case 'Q': // Turn left rotatet-=dr; // decreases angle of rotation break; case 'S': // Turn right //printf("ROTATET: %lf\n",rotatet); rotatet+=dr; // increases angle of rotation //printf("ROTATET: %lf\n",rotatet); break; case 'T': // Brake dx=0; // sets speed dx and dy to 0 dy=0; rotatea=rotatet; yRotate=0; xRotate=0; break; case ' ': fire(rotatet, xc, yc, r); break; case 'q': // Quit stillgoing=0; printf("\nYou collected %i circles!\n",cirCount); break; default: break; } } if(isaccel==1){ printf("ROTATEA: %lf\n",rotatea); if(sin(rotatea)<sin(rotatet)){ yRotate-=fabs(sin(rotatea+.1)); printf("check1\n"); }else if(sin(rotatea)>sin(rotatet)){ yRotate+=fabs(sin(rotatea-.1)); printf("check2\n"); }//else direction of acceleration is equal to direction rocket is facing if(cos(rotatea)>cos(rotatet)){ xRotate-=fabs(cos(rotatea+.1)); printf("check3\n"); }else if(cos(rotatea)<cos(rotatet)){ xRotate+=fabs(cos(rotatea-.1)); printf("check4\n"); } if(xRotate!=0) rotatea=atan(yRotate/xRotate); printf("yRotate: %lf\nxRotate: %lf\nrotatea: %lf\nrotatet: %lf\n",yRotate,xRotate,rotatea,rotatet); } xc+=dx*cos(rotatea); // implements x and y speed(dx and dy) by changing position(xc,yc) of rocket at varying rate yc+=dy*sin(rotatea); // why i use rotatea, not rotatet: the rocket will only update the angle of movement, if the rocket is accelerating. This way, you can turn the rocket while it is moving in another direction isaccel=0; // Transports rocket from one side of screen to other wormhole(pxc,pyc,xSize,ySize); // Creates new circle if rocket comes too close if(sqrt(pow((xc-xCir),2)+pow((yc-yCir),2))<1.6*r+rCir){ cirCount++; rCir=10+rand()%20; do{ xCir=rand()%xSize; yCir=rand()%ySize; rC=100+rand()%155; gC=100+rand()%155; bC=100+rand()%155; }while(sqrt(pow((xc-xCir),2)+pow((yc-yCir),2))<50); } } }
int main( int argc, /* arg count */ char * argv[] /* arg vector */ ){ static char * context = "main(life)"; bool2D world; /* world to evolve */ int nr, nc; /* matrix size */ int iters; /* number of iterations */ char * infn = NULL; /* input file name */ char * outfn = NULL; /* output file name */ int argd = 1; /* argument index */ void * args[5]; /* arguments */ #if NUMA MAIN_INITENV(,32000000) BARINIT(GlobalBar); #endif while (argd < argc){ CHECK(argv[argd][0] == '-', fail(context, "bad argument", "index", "%d", argd, NULL)); switch(argv[argd][1]){ case 'L' : iters = arg_int(context, argc, argv, argd+1, argv[argd]); argd += 2; break; #if GRAPHICS case 'g' : gfx_open(app_life, arg_gfxCtrl(context, argc, argv, argd+1, argv[argd])); argd += 2; break; #endif #if PARALLEL case 'p' : DataDist = arg_dataDist(context, argc, argv, argd+1, argv[argd]); ParWidth = arg_int(context, argc, argv, argd+2, argv[argd]); argd += 3; break; #endif case 'i' : infn = arg_str(context, argc, argv, argd+1, argv[argd]); argd += 2; break; case 'o' : outfn = arg_str(context, argc, argv, argd+1, argv[argd]); argd += 2; break; case 'u' : io_init(FALSE); argd += 1; break; default : fail(context, "unknown flag", "flag", "%s", argv[argd], NULL); break; } } /* setup */ sch_init(DataDist); CHECK(0 < iters, fail(context, "non-positive number of iterations", "number of iterations", "%d", iters, NULL)); io_rdBool2D(context, infn, world, &nr, &nc); /* run */ TP_any(args, 0, world); TP_any(args, 1, nr); TP_any(args, 2, nc); TP_any(args, 3, iters); thr_grp(life_thr, args); /* takedown */ io_wrBool2D(context, outfn, world, nr, nc); #if GRAPHICS gfx_close(); #endif #if IEEE ieee_retrospective(stderr); #endif #if NUMA BARFREE(GlobalBar); MAIN_END; #endif return 0; }
int main(void) { // Declare & Define Variables int xsize; // Window dimensions int ysize; char input; // For determining user input float curxpos; // Position (Location) of the shape float curypos; float newx; // For drawing the circle float newy; float oldx; float oldy; double deltat; // Change in time float vx; // Velocities in their respective directions float vy; int radius; // Radius of the figure float PI = 3.14159; // Constant PI float theta; // Angles char c; // Check for input float theta2; // Second theta for rotation radius = 30; xsize = 400; ysize = 400; curxpos = radius; curypos = ysize-radius; oldx = curxpos-radius; oldy = curypos; vx = 0; vy = 0; srand(time(NULL)); deltat = 0.01; theta2 = 0; // Open a new window for drawing gfx_open(xsize, ysize, "Rotate"); while(input != 'q') { gfx_clear(); gfx_color(0,255,255); gfx_line(curxpos,curypos,curxpos+radius*cos(theta2),curypos+radius*sin(theta2)); gfx_line(curxpos,curypos,curxpos-radius*cos(theta2),curypos-radius*sin(theta2)); gfx_line(curxpos,curypos,curxpos+radius*cos(theta2),curypos-radius*sin(theta2)); gfx_line(curxpos,curypos,curxpos-radius*cos(theta2),curypos+radius*sin(theta2)); for (theta = 0; theta <= 2*PI; theta+=.01) { gfx_color(255,0,0); newx = cos(theta)*radius+curxpos; newy = sin(theta)*radius+curypos; gfx_line(oldx,oldy,newx,newy); oldx = newx; oldy = newy; c = gfx_event_waiting(); if (c == 1) { input = gfx_wait(); if (input == 1) { vx += 1; theta2 += PI/16; } if (input == 3) { vx -= 1; theta -= PI/16; } if (input =='1') { gfx_color(0,255,0); } if (input == '2') { gfx_color(0,0,255); } if (input == '3') { gfx_color(255,0,0); } if (input == '4') { gfx_color(255,255,255); } if (input == 'q') break; } } if (newx >= xsize || newx <= radius) { vx = -vx; } curxpos += vx; if (vx > 0) { theta2 += PI/16; } if (vx < 0) { theta2 -= PI/16; } if (vx == 0) { theta2 = curxpos/curypos; } gfx_flush(); usleep(deltat*1000000); } return 0; }
int main (void) { // Declare all of the variables that will be used in the function char c; int xsize=400, ysize=400, j; float pi=3.14159, rClock, xcc, ycc, rDot, yDotNeg, yDotPos, xDotNeg, xDotPos, bhPos, shPos, bhVel=-2*pi/60, shVel=bhVel/12, i, di=0.01, k, dk=2*pi/3; // Initializes the positions of the big and small hands of the clock bhPos = pi/2; shPos = pi/2; // From here to the first gfx command, all of the size sensitive variables are initialized xcc = xsize/2; ycc = ysize/2; if (xsize <= ysize) { rClock = xsize/2; rDot = xsize/20; } else { rClock = ysize/2; rDot = ysize/20; } yDotNeg = ycc + rClock-20; yDotPos = ycc - rClock+20; xDotNeg = xcc - rClock+20; xDotPos = xcc + rClock-20; //creates screen size and caption gfx_open(xsize, ysize, "Clock - 's'- switch direction, 'q'- quit"); //While loop that generates the clock while (1) { for (i=0; i<=2*pi; i+=di) { gfx_color(255, 255, 255); gfx_line(xcc + rClock*cos(i), ycc + rClock*sin(i), xcc + rClock*cos(i+di), ycc + rClock*sin(i+di)); } for (k=0; k<=2*pi; k+=dk) { gfx_color(0, 100, 200); gfx_line(xcc + rDot*sin(k), yDotNeg + rDot*-cos(k), xcc + rDot*sin(k+dk), yDotNeg + rDot*-cos(k+dk)); } for (k=0; k<=2*pi; k+=dk) { gfx_color(0, 100, 200); gfx_line(xcc + rDot*sin(k), yDotPos + rDot*cos(k), xcc + rDot*sin(k+dk), yDotPos + rDot*cos(k+dk)); } for (k=0; k<=2*pi; k+=dk) { gfx_color(0, 100, 200); gfx_line(xDotNeg + rDot*cos(k), ycc + rDot*sin(k), xDotNeg + rDot*cos(k+dk), ycc + rDot*sin(k+dk)); } for (k=0; k<=2*pi; k+=dk) { gfx_color(0, 100, 200); gfx_line(xDotPos + rDot*-cos(k), ycc + rDot*sin(k), xDotPos + rDot*-cos(k+dk), ycc + rDot*sin(k+dk)); } for (k=0; k<=2*pi; k+=dk/4) { gfx_color(0, 100, 200); gfx_line(xcc + rClock*cos(k)*10/11, ycc + rClock*sin(k)*10/11, xcc + rClock*cos(k)*9/11, ycc + rClock*sin(k)*9/11); } gfx_color(0, 200, 100); gfx_line(xcc, ycc, xcc + rClock*9/10 * cos(bhPos), ycc + rClock*9/10 * -sin(bhPos)); gfx_line(xcc, ycc, xcc + rClock*5/10 * cos(shPos), ycc + rClock*5/10 * -sin(shPos)); bhPos += bhVel; shPos += shVel; gfx_flush(); usleep(300000); gfx_clear(); j = gfx_event_waiting(); if ( j==1 ) { c = gfx_wait(); switch (c) { case 's': bhVel = -bhVel; shVel = -shVel; break; case 'q': return 0; } } } return 0; }
int main(){ char m; int x, y, r; float t, dt, ax, ay, bx, by; gfx_open(500, 400, "Symbol.c"); while(m != 'q') { m = gfx_wait(); switch(m){ case 'c': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 255, 255); gfx_circle(x, y, 20); gfx_flush; break; case 't': x = gfx_xpos(); y = gfx_ypos(); gfx_color(0, 255, 0); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/3){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case 1: x = gfx_xpos(); y = gfx_ypos(); gfx_color(0, 0, 200); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/4){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '3': x = gfx_xpos(); y = gfx_ypos(); gfx_color(200, 0, 200); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/3){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '4': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 0, 255); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/4){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '5': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 0, 255); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/5){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '6': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 0, 255); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/6){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '7': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 0, 255); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/7){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '8': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 0, 255); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/8){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '9': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 0, 255); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/9){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; } } }
int main() { memcpy(board2,board,sizeof(int)*rows*columns); int height=800,width=800; //height and width of screen gfx_open(width,height,"Pacman"); gfx_clear_color(0,0,0); gfx_clear(); int boardHeight=radius*rows,boardWidth=radius*columns;//Height of the board int xtopleft=width/2-boardWidth/2; //x coord of top left corner of board int ytopleft=height/2-boardHeight*9/16; //y coord of top left corner of board char movement; int i,lives=3;//start with 3 lives int win=0; int active=0; //this changes depending on number of dots left int initialDots=dotsNumber(); int remainingDots=dotsNumber(); int score=0; int loop[4]={0,0,0,0}; int frightenLoop[4]={0}; int newScore[3]={0,0,0};//values [0]:new score to display(when ghost is killed),[1]:xvalue,[2]:yvalue Location pacman; Location ghosts[4];// enumerated to blinky, pinky, inky, clyde; /*There are four states: 0: Chase, 1: Scatter, 2: Frighten, 3: Dead, and 4: Housed */ int state[4]={scatter,scatter,scatter,scatter}; while(1){ titleScreen(height,width,ghosts,&pacman,state); score=0; lives=3; win=0; for(i=0;i<=3;i++) loop[i]=0; //reset the game resetBoard(); gfx_wait(); /* This is the gameplay loop, will repeat every time a life is lost */ while(lives>0){ gfx_clear(); /* Initialize pacman's location */ pacman.x=pacman.prevX=7; pacman.y=pacman.prevY=12; pacman.orientation=right; /* Initialize ghost's locations */ for(i=blinky;i<=clyde;i++){state[i]=scatter;} ghosts[blinky].x=7; ghosts[blinky].prevX=8; ghosts[blinky].y=ghosts[blinky].prevY=6; ghosts[blinky].orientation=left; ghosts[pinky].x=7; ghosts[pinky].prevX=7; ghosts[pinky].y=7; ghosts[pinky].prevY=8; ghosts[pinky].orientation=up; ghosts[inky].x=ghosts[inky].prevX=6; ghosts[inky].y=7; ghosts[inky].prevY=8; ghosts[inky].orientation=right; ghosts[clyde].x=ghosts[clyde].prevX=8; ghosts[clyde].y=7; ghosts[clyde].prevY=8; ghosts[clyde].orientation=left; /* These two statements draw pacman and the board to begin the program */ drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,2,score); drawPacman(xtopleft+radius*pacman.x+radius/2,ytopleft+radius*pacman.y+radius/2,pacman.orientation,0); for(i=blinky;i<=clyde;i++){ drawGhost(xtopleft+radius*ghosts[i].x+radius/2,ytopleft+radius*ghosts[i].y+radius/2,i,ghosts[i].orientation,state,frightenLoop[i]); } /* This loop is the gameplay after all initialization */ while(1){ /*if(gfx_event_waiting()){prevMovement=movement;*/ movement=gfx_wait();//} /* This block updates pacman position, checks for death * then updates ghosts' positions, then checks for death again */ movePacman(&pacman,ghosts,movement,xtopleft,ytopleft,boardHeight,boardWidth,active,state,&score,frightenLoop); if(checkDeath(&pacman,ghosts,xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,state,&score,newScore,frightenLoop,loop[0])){ //pacman's death? for(i=0;i<=3;i++) loop[i]=0; //reset the game lives--; //decrease the lives printf("LIVES: %i\n",lives); break; } targetGhosts(ghosts,&pacman,xtopleft,ytopleft,boardHeight,boardWidth,active,state); if(checkDeath(&pacman,ghosts,xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,state,&score,newScore,frightenLoop,loop[0])){ //pacman's death? for(i=0;i<=3;i++) loop[i]=0; //reset the game lives--; //decrease the lives printf("LIVES: %i\n",lives); break; } ghostState(loop,state,frightenLoop); active=activeGhosts(ghosts,loop); /* The next function animates the motion of all of the objects (pacman and ghosts */ animateMotion(xtopleft,ytopleft,boardHeight,boardWidth,&pacman,ghosts,height,width,lives,state,score,newScore,frightenLoop,loop[0]); /* The case to exit the loop is winning, when there are no dots left */ if(dotsNumber()==0){ //The player got all the dots, they won the game win=1; break; } } if(lives<=0){ gfx_clear(); printf("\n\nGAME OVER\n\n"); drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,0,score); if(tolower(gfx_wait())=='n'){ return 0; }//This will start the entire game over including the title screen else break;} else if(win){ printf("\n\nWINNER!\n\n"); drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,win,score); if(tolower(gfx_wait())=='n'){ return 0; }//This will end the game else break;} } } }
int title_screen(const char *commands[100], int *f, double noteinfo[2][1000], char output[1000]){ int xsize=1250; int ysize=1000; int xpos; int ypos; int height=400; int width=(xsize-50)/16; int i,j; char input[20]; char initial[1000]; char c; gfx_open(xsize, ysize, "Digital Piano"); quit_button(); draw_title(100); draw_name(50); draw_name2(50); draw_button(295,600,70,310); draw_button(645,600,70,310); button_label(60); button_label2(60); while (1){ c=gfx_wait(); xpos=gfx_xpos(); ypos=gfx_ypos(); //user clicks the quit button if (xpos>=1110 && xpos<=1210 && ypos>=850 && ypos<=890){ return 0; } //user clicks free play button if (xpos>=295 && xpos<=605 && ypos>=600 && ypos<=670){ gfx_clear(); piano_graphic(commands, f); } //user clicks load file button if (xpos>=645 && xpos<=955 && ypos>=600 && ypos<=670){ terminal_message(); printf("Please enter the name of the file, including the extension.\nThe file content should follow the same format as the examples in lab 8:\n"); scanf("%s", input); //scans file name into input FILE *music=fopen(input, "r"); if ((music=fopen(input, "r")) == NULL){ //returns error if file not found puts("File could not be opened"); return 0; } else{ //scans the file into output for (j=0; j<1000; j++){ fscanf(music, "%c", &output[j]); if (output[j]=='X'){ break; } } } piano2(noteinfo, output); //fork to play sound while lighting up keys if (fork()){ system("play sound.wav"); } else{ gfx_clear(); draw_piano(width, height); draw_arrow(50, f); gfx_color(255,255,255); draw_box(); octave_label(30); quit_button(); gfx_flush(); key_animation(noteinfo, f); return 0; } } } }
MAIN_ENV #endif #include "specific.h" int main( int argc, /* arg count */ char * argv[] /* arg vector */ ){ static char * context = "main(winnow)"; int2D matrix; /* matrix of values */ bool2D mask; /* mask on values */ int nr, nc, nrM, ncM; /* sizes */ pt1D pt; /* resulting point vector */ int npt; /* number of points to keep */ char * infnMat = NULL; /* input matrix file name */ char * infnMask = NULL; /* input mask file name */ char * outfn = NULL; /* output file name */ int argd = 1; /* argument index */ /* arguments */ #if NUMA MAIN_INITENV(,32000000) #endif while (argd < argc){ CHECK(argv[argd][0] == '-', fail(context, "bad argument", "index", "%d", argd, NULL)); switch(argv[argd][1]){ case 'N' : npt = arg_int(context, argc, argv, argd+1, argv[argd]); argd += 2; break; #if GRAPHICS case 'g' : gfx_open(app_winnow, arg_gfxCtrl(context, argc, argv, argd+1, argv[argd])); argd += 2; break; #endif #if MIMD case 'p' : DataDist = arg_dataDist(context, argc, argv, argd+1, argv[argd]); ParWidth = arg_int(context, argc, argv, argd+2, argv[argd]); argd += 3; break; #endif case 'i' : infnMat = arg_str(context, argc, argv, argd+1, argv[argd]); infnMask = arg_str(context, argc, argv, argd+2, argv[argd]); argd += 3; break; case 'o' : outfn = arg_str(context, argc, argv, argd+1, argv[argd]); argd += 2; break; case 'u' : io_init(FALSE); argd += 1; break; default : fail(context, "unknown flag", "flag", "%s", argv[argd], NULL); break; } } /* setup */ #if MIMD sch_init(DataDist); #endif CHECK(npt > 0, fail(context, "non-positive number of points requested", "number of points", "%d", npt, NULL)); io_rdInt2D(context, infnMat, matrix, &nr, &nc); io_rdBool2D(context, infnMask, mask, &nrM, &ncM); CHECK((nr == nrM) && (nc == ncM), fail(context, "matrix/mask size mismatch", "matrix file", "%s", infnMat, "mask file", "%s", infnMask, NULL)); /* run */ winnow(matrix, mask, nr, nc, pt, npt); /* takedown */ io_wrPt1D(context, outfn, pt, npt); #if GRAPHICS gfx_close(); #endif #if IEEE ieee_retrospective(stderr); #endif #if NUMA MAIN_END; #endif return 0; }