Ejemplo n.º 1
0
void drawBackground(int width, int height) {
    
    //draw clouds
    gfx_color(255, 255, 255);
    int i;
    for (i = 0; i<10; i++) {
        gfx_fill_circle(i*width/8, height - height/10, 50);
    }
    for (i = 0; i<3; i++) {
      gfx_fill_circle(i*width/3, height - height/7, 40);
  	}
    
    gfx_fill_circle(width*3/4+10, height - height/6+10, 45); 
    gfx_fill_circle(width*2/9-5, height - height/7, 45); 
    
    //draw buildings
    
    for (i = 0; i<5; i++) {
        //outlines
        gfx_color(200, 207, 201);
        gfx_rectangle(-30+i*width/4-1, height-60-1, 22, 60);
        gfx_rectangle(-30+i*width/4+20-1, height-55-1, 22, 55);
        gfx_rectangle(-30+i*width/4+25-1, height-45-1, 27, 45);
        gfx_rectangle(-30+i*width/4+30-1, height-75-1, 32, 75);
        gfx_rectangle(-30+i*width/4+30-1, height-80-1, 15, 80);
        gfx_rectangle(-30+i*width/4+50-1, height-62-1, 22, 62);
        gfx_rectangle(-30+i*width/4+55-1, height-55-1, 27, 55);
        //fills
        gfx_color(218, 227, 219);
        gfx_fill_rectangle(-30+i*width/4, height-60, 20, 60);
        gfx_fill_rectangle(-30+i*width/4+20, height-55, 20, 55);
        gfx_fill_rectangle(-30+i*width/4+25, height-45, 25, 45);
        gfx_fill_rectangle(-30+i*width/4+30, height-75, 30, 75);
        gfx_fill_rectangle(-30+i*width/4+30, height-80, 15, 80);
        gfx_fill_rectangle(-30+i*width/4+50, height-62, 20, 62);
        gfx_fill_rectangle(-30+i*width/4+55, height-55, 25, 55);
   
    }
    
    //draw greenery
    for (i = 0; i<10; i++) {
        gfx_color(107, 179, 118);
        gfx_circle(i*width/8, height - 5, 30);
        gfx_color(153, 224, 163);
        gfx_fill_circle(i*width/8, height - 5, 30);
    }
    for (i = 0; i<6; i++) {
        gfx_fill_circle(i*width/6, height - 5, 25);
    }
    for (i = 0; i<10; i++) {
        gfx_color(107, 179, 118);
        gfx_circle(i*width/8+20, height - 5, 24);
        gfx_color(153, 224, 163);
        gfx_fill_circle(i*width/8+20, height - 5, 24);
    }
   
    //draw base rectangle to cover outlines
    gfx_fill_rectangle(0, height-15, width, 15);
        
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
void move_asteroids(double astr[][5], double shots[][5], int x1ship, int y1ship, int x2ship, int y2ship, double *x, double *y, double *speed, double *theta, int score[])
{
 int i;
 double j;
 asteroids(astr);
 for(i=0; i<32; i++){
	if(astr[i][3]!=0){
		astr[i][0]=astr[i][0]+astr[i][4]*cos(astr[i][2]); 	//iterates asteroid coordinates
		astr[i][1]=astr[i][1]-astr[i][4]*sin(astr[i][2]);
		for(j=0; j<2*PI; j=j+PI/50){
			//the line below checks whether ship has collided with an asteroid
			if((astr[i][0]+astr[i][3]*cos(j))<=x1ship && (astr[i][1]-astr[i][3]*sin(j))<=y1ship && (astr[i][0]+astr[i][3]*cos(j+PI))>=x2ship && (astr[i][1]-astr[i][3]*sin(j+PI))>=y2ship){
				*speed=0;
				*theta=0;	//resets theta and speed
				
				death(astr, shots, x, y, score);
			}
		}
		if(astr[i][0]>=740){
                        astr[i][0]=1;
                } else if(astr[i][0]<=-40){
                        astr[i][0]=699;
                } else if(astr[i][1]>=740){      //this keeps the ship from flying off the screen
                        astr[i][1]=1;
                } else if(astr[i][1]<=-40){
                        astr[i][1]=699;
                }
		gfx_color(0, 170, 255);
		gfx_circle(astr[i][0], astr[i][1], astr[i][3]);
	 	gfx_color(255, 255, 255);
	}
 }
}
Ejemplo n.º 5
0
void draw_lives(int lives)
{
	int l, i;
 
	gfx_color(255,255,0); //yellow

	for (l=0; l<lives; l++)
    	for(i=0; i<10; i++)
        	gfx_circle(20+l*30,630,i);
       	 
} //end draw_lives
Ejemplo n.º 6
0
int drawBird(double x, double y, double r, int flap){
	
    //body
    gfx_color(255,255,0);
    //gfx_fill_circle(x,y,r);
	gfx_fill_arc(x-16, y-16, 29, 24, 0, 360 );
    gfx_color(0,0,0);
    gfx_arc(x-16, y-16, 29, 24, 0, 360); 
    
    //eye ball
    gfx_color(255,255,255);
    gfx_fill_circle(x+7,y-7,(0.50)*r+1);

	//wings
    if(flap<=5){
        gfx_fill_arc(x-18,y-11,12, 6, 0, 360);
        gfx_color(0,0,0);
        gfx_arc(x-18,y-12,11, 6, 0, 360);
        flap++;
    }
    else if( (flap>=5)&&(flap<=10) ){
        gfx_fill_arc(x-18,y-7, 12, 6, 0, 360);
        gfx_color(0,0,0);
        gfx_arc(x-18,y-7, 12, 6, 0, 360);
        flap++;     
    }
    else{
        gfx_fill_arc(x-18,y-5,12, 6, 0, 360);
        gfx_color(0,0,0);
        gfx_arc(x-18,y-5,12, 6, 0, 360);
        flap--;
    }
    
    //pupil
    gfx_fill_rectangle(x+9,y-8,2,4);
    gfx_circle(x+7,y-7,(0.50)*r+1);

	//lips
    gfx_color(255,128,0);
    gfx_fill_arc(x+1, y-1, 16, 4, 0, 360); 
	gfx_fill_arc(x+1, y+3, 14, 3, 0 ,360); 

    gfx_color(0,0,0);
    gfx_arc(x+1, y+3, 14, 3, 0, 360);
    gfx_arc(x+1, y-1, 16, 4, 0, 360);  

    gfx_color(255,128,0);
    gfx_fill_rectangle(x+1,y+0,4,6);

    return flap;

}
Ejemplo n.º 7
0
void drawPerson(){

	//make body - half circle
	gfx_color(204, 0, 102);
	gfx_circle(250, 550, 100);
	usleep(500);

	//make head
	gfx_color(255, 255, 0);
	gfx_circle(250, 400, 50);
	usleep(500);
	//make face
	gfx_point(225, 400); //eye
	usleep(500);
	gfx_point(275, 400); //eye
	usleep(500);

	//make arms
	gfx_line(200, 460, 150, 370);
	gfx_line(300, 460, 350, 370);

	usleep(500);
}
Ejemplo n.º 8
0
void circularLace(int xcenter,int ycenter, int radius){
  if(radius<=1) return; 			//check for base case
  
  int newRadius=ceil(radius/3.);//scaling factor for the radius is 3
  gfx_circle(xcenter,ycenter,newRadius);		//drawing step
  
  //everything else is the recursive step
  int xpoints[6],ypoints[6],i;
  for(i=0;i<6;i++){
    xpoints[i]=xcenter+newRadius*cos(i*60*M_PI/180);//finds new x center points and stores it into xpoints[i]
    ypoints[i]=ycenter+newRadius*sin(i*60*M_PI/180);//finds new y center points and stores it into ypoints[i]
    circularLace(xpoints[i],ypoints[i],newRadius);//recursive step
  }
}
Ejemplo n.º 9
0
void move_shots(double shots[][5])
{
 int i, j;
 for(i=0; i<30; i++){
        if(shots[i][3]!=0){
                shots[i][0]=shots[i][0]+6*cos(shots[i][2]+PI/2);  //shots fired at angle ship is at
                shots[i][1]=shots[i][1]-6*sin(shots[i][2]+PI/2);
                if(shots[i][0]>=700){
                        shots[i][3]=0;
                } else if(shots[i][0]<=0){
                        shots[i][3]=0;
                } else if(shots[i][1]>=700){     //this kills shots when they leave the screen
                        shots[i][3]=0;
                } else if(shots[i][1]<=0){
                        shots[i][3]=0;
                }
                gfx_color(0,255,0);
                gfx_circle(shots[i][0], shots[i][1], shots[i][3]);
        	gfx_color(255,255, 255);
	}
 }
 gfx_flush();
}
Ejemplo n.º 10
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;
	   }	
	}
}
Ejemplo n.º 11
0
void background(int w,int h,int level)
{  
	int wnum=50,wseg=w/wnum,hnum=100,hseg=h/hnum,i,ic; //define parameters
   
	gfx_clear_color(0,0,0);
	gfx_clear();
	gfx_color(255,255,255); //white
 	gfx_text(w/2, h-20, "Use arrow keys to navigate frog safely to a lilly pad. Do not get hit by a car or fall in the water.");
 	gfx_text(w/4,h-20,"LEVEL: ");
 	gfx_text(w/4+50,h-20,num2str(level));
 
	gfx_color(20,0,150); //blue color
	gfx_fill_rectangle(0,0,w,h/2); //draws water
    
	gfx_color(20,150,0); //green color
	gfx_fill_rectangle(0,0,w,hseg); //draws top green border
    
	for(i=0;i<6;i++) //draws lily pads
    	for(ic=1;ic<(3*hseg);ic++) //increment radius to fill circle
        	gfx_circle((i*8+5)*wseg,5*hseg,ic);
       	 
	for(i=0;i<wnum;i++){ //draws pad details
    	if((i+2)%4!=0)
        	gfx_fill_rectangle(wseg*i*2,hseg,2*wseg,hseg);
       	 
    	if((i+1)%8<4){
        	switch((i+2)%4){
            	case 1:
                	gfx_fill_rectangle(wseg*i,2*hseg,wseg,hseg);
                	gfx_fill_rectangle(wseg*i,4*hseg,wseg,2*hseg);
                	break;
            	case 2:
                	gfx_fill_rectangle(wseg*i,3*hseg,wseg,2*hseg);
                	gfx_fill_rectangle(wseg*i,6*hseg,wseg,1*hseg);
                	break;
            	case 3:
                	gfx_fill_rectangle(wseg*i,2*hseg,wseg,2*hseg);
                	gfx_fill_rectangle(wseg*i,5*hseg,wseg,2*hseg);
                	break;
            	case 0:
                	gfx_fill_rectangle(wseg*i,2*hseg,wseg,hseg);
                	gfx_fill_rectangle(wseg*i,4*hseg,wseg,2*hseg);
                	break;
        	} //end switch((i+2)%4)
    	} //end if((i+1)%8<4)
   	 
    	switch(i%8){ //draw middle grass
            	case 0:
            	case 1:
            	case 3:
            	case 6:
                	gfx_fill_rectangle(wseg*i,(h/2)-(4*hseg),wseg,5*hseg);
                	break;
            	case 2:
            	case 7:
                	gfx_fill_rectangle(wseg*i,(h/2)-(5*hseg),wseg,7*hseg);
                	break;
            	case 4:
                	gfx_fill_rectangle(wseg*i,(h/2)-(4*hseg),wseg,6*hseg);
                	break;
            	case 5:
                	gfx_fill_rectangle(wseg*i,(h/2)-(5*hseg),wseg,6*hseg);
                	break;
        	} //end switch((i+2)%4)
       	 
    	switch(i%8){ //draw bottom grass
        	case 0:
        	case 1:
        	case 3:
        	case 6:
            	gfx_fill_rectangle(wseg*i,h-(18*hseg),wseg,5*hseg);
            	break;
        	case 2:
        	case 7:
            	gfx_fill_rectangle(wseg*i,h-(19*hseg),wseg,7*hseg);
            	break;
        	case 4:
            	gfx_fill_rectangle(wseg*i,h-(18*hseg),wseg,6*hseg);
            	break;
        	case 5:
            	gfx_fill_rectangle(wseg*i,h-(19*hseg),wseg,6*hseg);
            	break;
    	} //end switch((i+2)%4)
   	 
	} //end for(i=0;i<wnum;i++)
    
	gfx_color(150,75,0); //brown color
	for(i=0;i<wnum;i++){ //draws grass details
    	switch(i%8){ //draw middle grass details
            	case 0:
            	case 1: break;
            	case 3:
            	case 6:
                	gfx_fill_rectangle(wseg*i,(h/2)-(2*hseg),wseg,hseg);
                	break;
            	case 2:
            	case 7:
                	gfx_fill_rectangle(wseg*i,(h/2)-(4*hseg),wseg,hseg);
                	break;
            	case 4:
                	gfx_fill_rectangle(wseg*i,(h/2)-(3*hseg),wseg,hseg);
                	break;
            	case 5:
                	gfx_fill_rectangle(wseg*i,(h/2)-hseg,wseg,hseg);
                	break;
        	} //end switch((i+2)%4)
       	 
        	switch(i%8){ //draw bottom grass details
            	case 0:
            	case 1: break;
            	case 3:
            	case 6:
                	gfx_fill_rectangle(wseg*i,h-(16*hseg),wseg,hseg);
                	break;
            	case 2:
            	case 7:
                	gfx_fill_rectangle(wseg*i,h-(18*hseg),wseg,hseg);
                	break;
            	case 4:
                	gfx_fill_rectangle(wseg*i,h-(17*hseg),wseg,hseg);
                	gfx_fill_rectangle(wseg*i,h-(14*hseg),wseg,hseg);
                	break;
            	case 5:
                	gfx_fill_rectangle(wseg*i,h-(15*hseg),wseg,hseg);
                	break;
        	} //end switch((i+2)%4)
       	 
	} //end for(i=0;i<wnum;i++)
    
} //end background
Ejemplo n.º 12
0
void drawfrog(int col,int row,int boardw,int boardh,char direction)
{
	int xp=boardw*col+boardw/2,yp=boardh*row+boardh/2,i,inr=boardh/2-10,outr=boardh/2-5,eyer=5,xleye,yleye,xreye,yreye;
	double theta=PI/4;
    
	gfx_color(255,255,0); //yellow
	for(i=1;i<inr;i++)
    	gfx_circle(xp,yp,i); //draws frog stomach
   	 
	gfx_color(150,255,50); //green
	for(i=inr;i<=outr;i++)
    	gfx_circle(xp,yp,i); //draws frog
   	 
	gfx_color(255,0,255); //magenta
	switch(direction){ //draws frog eyes in direction of movement
    	case 'Q': //left
        	xleye=xp-outr*cos(theta); //x center of left eye
        	yleye=yp+outr*sin(theta); //y center of left eye
        	xreye=xp-outr*cos(theta); //x center of right eye
        	yreye=yp-outr*sin(theta); //y center of right eye
       	 
        	for(i=1;i<eyer;i++){
            	gfx_circle(xleye,yleye,i);
            	gfx_circle(xreye,yreye,i);
        	} //end for(i=1;i<eyer;i++)
        	break;
   	 
    	case 'R': //up
        	xleye=xp-outr*cos(theta); //x center of left eye
        	yleye=yp-outr*sin(theta); //y center of left eye
        	xreye=xp+outr*cos(theta); //x center of right eye
        	yreye=yp-outr*sin(theta); //y center of right eye
       	 
        	for(i=1;i<eyer;i++){
            	gfx_circle(xleye,yleye,i);
            	gfx_circle(xreye,yreye,i);
        	} //end for(i=1;i<eyer;i++)
        	break;
       	 
    	case 'S': //right
        	xleye=xp+outr*cos(theta); //x center of left eye
        	yleye=yp-outr*sin(theta); //y center of left eye
        	xreye=xp+outr*cos(theta); //x center of right eye
        	yreye=yp+outr*sin(theta); //y center of right eye
       	 
        	for(i=1;i<eyer;i++){
            	gfx_circle(xleye,yleye,i);
            	gfx_circle(xreye,yreye,i);
        	} //end for(i=1;i<eyer;i++)
        	break;
   	 
    	case 'T': //down
        	xleye=xp+outr*cos(theta); //x center of left eye
        	yleye=yp+outr*sin(theta); //y center of left eye
        	xreye=xp-outr*cos(theta); //x center of right eye
        	yreye=yp+outr*sin(theta); //y center of right eye
       	 
        	for(i=1;i<eyer;i++){
            	gfx_circle(xleye,yleye,i);
            	gfx_circle(xreye,yreye,i);
        	} //end for(i=1;i<eyer;i++)
   	 
        	break;
	} //end switch(direction)
} //end drawfrog
Ejemplo n.º 13
0
void drawAsteroid(int xCir, int yCir, int rCir, int rC, int gC, int bC)
{
	gfx_color(rC,gC,bC);
	gfx_circle(xCir,yCir,rCir);
}
Ejemplo n.º 14
0
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;
}
Ejemplo n.º 15
0
int presentEndScreen (int score, int highScore, int width, int height) {

    //present end screen
    gfx_color(255, 255, 255);
    gfx_changefont("-*-helvetica-bold-r-*-*-*-250-90-90-p-*-iso8859-1");
    gfx_text(width/2-88, 150, "GAME OVER");
    
    //draw score block
    gfx_color(0,0,0);
    gfx_fill_rectangle(50, 180, width-100, 164);
    gfx_color(237, 206, 111);
    gfx_fill_rectangle(54, 184, width-108, 156);
    gfx_color(209, 181, 98);
    gfx_fill_rectangle(61, 191, width-122, 142);
    gfx_color(245, 228, 176);
    gfx_fill_rectangle(62, 192, width-124, 140);
    
    //labels
    gfx_color(209, 181, 98);
    gfx_changefont("-*-helvetica-bold-r-*-*-*-160-85-85-p-*-iso8859-1");
    gfx_text(width/2-110, height/2-50, "MEDAL");
    gfx_text(width/2+50, height/2-50, "SCORE");
    gfx_text(width/2+65, height/2+8, "BEST");
    
    if (score > highScore) {
        highScore = score;
        //print new best label
        gfx_color(250, 0, 46);
        gfx_fill_rectangle(width/2+14, height/2-9, 46, 20);
        gfx_color(255, 255, 255);
        gfx_text (width/2+15, height/2+8, "NEW");
    }
    
    //scores
    gfx_changefont("-*-helvetica-bold-r-*-*-*-200-90-90-p-*-iso8859-1");
    char scoreStr[5], highScoreStr[5];
    sprintf(scoreStr, "%d", score);
    sprintf(highScoreStr, "%d", highScore);
    gfx_color(255, 255, 255);
    gfx_text(width/2+100, height/2-25, scoreStr);
    gfx_text(width/2+100, height/2+33, highScoreStr);
    
    
    //medals
    int red, green, blue;
    if (score > 40) {
        //platinum
        red = 245;
        green = 245;
        blue = 245;
    }
    else if (score > 30) {
        //gold
        red = 250;
        green = 239;
        blue = 82;
    }
    else if (score > 20) {
        //silver
        red = 214;
        green = 214;
        blue = 214;
    }
    else {
        //bronze
        red = 242;
        green = 152;
        blue = 87;
    }
    gfx_color(red, green, blue);
    gfx_fill_circle(width/2-80, height/2, 28);
    
    //medal bird
    int birdX = 105;
    int birdY = 264;
    
    //draw the bird    
    gfx_color(red, green, blue);
    gfx_fill_arc(birdX, birdY, 29, 24, 0, 360);
    
    gfx_color(red-60,green-20,blue);
    gfx_arc(birdX, birdY, 29, 24, 0, 360);
    
    gfx_color(red, green, blue);
    gfx_fill_circle(birdX+23,birdY+9,(0.50)*12+1);
    
    gfx_color(red-60,green-20,blue);
    gfx_circle(birdX+23,birdY+9,(0.50)*12+1);
    
    gfx_color(red, green, blue);
    gfx_fill_arc(birdX-2,birdY+4,11, 6, 0, 360);
    
    gfx_color(red-60,green-20,blue);
    gfx_arc(birdX-2,birdY+4,11, 6, 0, 360);
    
    gfx_color(red, green, blue);
    gfx_fill_arc(birdX+17, birdY+19, 14, 3, 0, 360);
    
    gfx_color(red-60,green-20,blue);
    gfx_arc(birdX+17, birdY+19, 14, 3, 0, 360);
    
    gfx_color(red, green, blue);
    gfx_fill_arc(birdX+17, birdY+15, 16, 4, 0, 360);
    
    gfx_color(red-60, green-20,blue);
    gfx_arc(birdX+17, birdY+15, 16, 4, 0, 360);
    
    gfx_color(red, green, blue);
    gfx_fill_rectangle(birdX+25,birdY+8, 2, 4);
    
    gfx_color(red-60,green-20,blue);
    gfx_rectangle(birdX+25,birdY+8, 2, 4);   
    
    //play again button
    gfx_color(0, 0, 0);
    gfx_fill_rectangle(width/2-79, height/2+96, 158, 28);
    gfx_color(255, 255, 255);
    gfx_fill_rectangle(width/2-77, height/2+98, 154, 24);
    gfx_color(250, 0, 46);
    gfx_fill_rectangle(width/2-75, height/2+100, 150, 20);
    gfx_color(255, 255, 255);
    gfx_changefont("-*-helvetica-bold-r-*-*-*-120-75-75-p-*-iso8859-1");
    gfx_text(width/2-38, height/2+115, "PLAY AGAIN");
    
	return highScore; 

}