int endGame(int score, int highScore, int width, int height) { highScore = presentEndScreen(score, highScore, width, height); while (1) { //check click and location if(gfx_wait()== 1) if (gfx_xpos() > width/2-79 && gfx_xpos() < width/2-79+158 && gfx_ypos() > height/2+96 && gfx_ypos() < height/2+96+28) break; } return highScore; }
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(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 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; } } } }
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(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 () { 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) { 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; }