Exemple #1
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;
}
Exemple #2
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; 
}
Exemple #3
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; 

}
Exemple #4
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;
    }*/
 }
}
Exemple #5
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();
	}
}
Exemple #6
0
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);
		}
	}
}
Exemple #8
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;
}
Exemple #9
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;
}
Exemple #10
0
void flyship(void)
{
 double x, y;
 double theta;
 char c;
 int i, go, x1ship, x2ship, y1ship, y2ship;	
 int score[2];
 score[0]=0;
 score[1]=3;
 char str[100];
 go=0;		//will tell drawship function if forward button is held down so flames can display
 int iterate=0;	//counts iterations of loop to determine when to move asteroids
 x=350;
 y=350;		//initial conditions
 theta=0;
 //the 2d array roids will contain 32 elements, one for each potential asteroid
 //and each element will have four numbers for the asteroids' properties
 double astr[32][5];	
 double shots[32][5]; //2d array for the shots out of the ship and its properties
 initialize(astr);
 initialize(shots);
 drawship(x, y, theta, go);
 double speed=0;
 while(1){
        if(gfx_event_waiting()) {
    		
		c=gfx_wait();
                if (score[1]==0 || c=='q') {
          	//this will run when lives are 0 and display the score
			gfx_clear();
			sprintf(str, "Score: %i   Press q to exit game", score[0], score[1]);
        		gfx_text(250, 350, str);
			c=gfx_wait();				
			if(c=='q'){		
				break;
                	}
		}

		if(c=='d'){
      			theta=theta-PI/20;
			  //this will rotate the ship
		} 
		if(c=='a'){
			theta=theta+PI/20;
		}
		if(c=='w'){
			speed=speed+1;			//moves ship forward
			if (speed>5){
				speed=5;
			}
			go=1;			//will tell drawship function that ship is moving
		
		}
		if(c=='o') {
			shoot(shots, theta, x, y);
                }

		if(x>700){
		        x=1;
		} else if(x<0){
        		x=699;
 		} else if(y>700){      //this keeps the ship from flying off the screen
        		y=1;
		} else if(y<0){
        		y=699;
 		}
	}	
	gfx_clear();
	usleep(10000);
	x1ship= x+20*cos(theta+4*PI/3);		//these variables create a sort of box around the ship, which is later used to check the ship's coordinates for collisions
	y1ship= y;
	x2ship= x+20*cos(theta+5*PI/3);
	y2ship= y-20*sin(theta);
	move_shots(shots);
	destroy(astr, shots, score);	//checks whether an asteroid should be destroyed
	move_asteroids(astr, shots, x1ship, y1ship, x2ship, y2ship, &x, &y, &speed, &theta, score);
	x=x+speed*cos(theta+PI/2);	//iterates coordinates of ship based on changes to theta and speed
        y=y-speed*sin(theta+PI/2);
	drawship(x, y, theta, go);
	if(go>=1){
		go=go-1;	//keeps go at 1 so it stops when stop pressing forward button
	}
	if(speed>.025){
                speed=speed-.025;
	
        }
	iterate++; 
 	sprintf(str, "Score: %d Lives: %d", score[0], score[1]);
        gfx_text(20, 680, str);

	}
}
Exemple #11
0
int startGame(Pipe* lead, Pipe* trail, int scrWidth, int scrHeight) {

	int loop = 1; 
    int score = 0;
    double birdX = 150, birdY = 275, birdR = 12, birdV = 0, t = .05;
    int flap = 0;
   //#1 - to see game over screen make this while (loop < 5) and uncomment #2
	while (loop) {
        //if bird touches the drawpipe loop = 2

		gfx_clear();
        
        
        //draw background
        drawBackground(scrWidth, scrHeight);
        
        //check for loss
        if ((lead->leadingX-3 <= birdX+16 && lead->trailingX+3 >= birdX-16) &&
            (lead->topHeight >= birdY-16 || lead->bottomHeight <= birdY-16+24)) 
            break;
        if (birdY-16+24 >= scrHeight)
            break;
        
        flap = drawBird(birdX, birdY, birdR, flap);
        updateBird(&birdY, &birdV, &t, birdY, birdV, t);

        if(gfx_event_waiting()){
            char c = gfx_wait();
            if(c == ' ') birdV = -40;
        }
		
        //draw leading pipe
		drawPipe(lead, scrWidth, scrHeight);
        updatePipe(lead);

        //increase the score upon passing through a pair of pipes
        if(lead->trailingX == birdX){
            score++;
        }

        if (lead->trailingX < scrWidth/2) {
            drawPipe(trail, scrWidth, scrHeight);
            updatePipe(trail);
        }
        if (lead->trailingX <= 0) {
            //swap the leader
            Pipe *temp = lead;
            lead = trail;
            trail = temp;
            initializePipe(trail, scrWidth, scrHeight);
        }
   
        //print the score on the top of the screen
        printScore(score, scrWidth);

		gfx_flush(); 
        usleep(10000);
        t+=.001;
		//loop++ #2  -- to see end screen uncomment this and above
	}

    return score;

}
Exemple #12
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;
}
Exemple #13
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;
}