1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <time.h>
void checkvec(int x, int y, int &vec, int size) //Checks to see if object has touched a side of the screen
{
if(x<=0+size && y<=0+size) vec = 6; //corner of the screens
else if(x>=xmax-size && y>=ymax-size) vec = 14;
else if(x<=0+size && y>=ymax-size) vec = 2;
else if(x>=xmax-size && y<=0+size) vec = 10;
else if(x<=0+size && vec>=12) vec = (random(3)+1); //left side of screen
else if(x<=0+size && vec<12) vec = (random(3)+5);
else if(x>=xmax-size && vec>=4) vec = (random(3)+9); //right side of screen
else if(x>=xmax-size && vec<4) vec = (random(3)+13);
else if(y<=0+size && vec>=12) vec = (random(3)+9); //top of screen
else if(y<=0+size && vec<=4) vec = (random(3)+5);
else if(y>=ymax-size && vec>=8) vec = (random(3)+13); //bottom of screen
else if(y>=ymax-size && vec<8) vec = (random(3)+1);
};
void cyclexy(int &x, int &y, int vec) //Changes x, y based on current direction of input
{
if(vec==0){y--;}; //0
if(vec==1){x++;y--;y--;}; //30
if(vec==2){x++;y--;}; //45
if(vec==3){x++;x++;y--;}; //60
if(vec==4){x++;}; //90
if(vec==5){x++;x++;y++;}; //120
if(vec==6){x++;y++;}; //135
if(vec==7){x++;y++;y++;}; //150
if(vec==8){y++;}; //180
if(vec==9){x--;y++;y++;}; //210
if(vec==10){x--;y++;}; //225
if(vec==11){x--;x--;y++;}; //240
if(vec==12){x--;}; //270
if(vec==13){x--;x--;y--;}; //300
if(vec==14){x--;y--;}; //315
if(vec==15){x--;y--;y--;}; //330
};
void printlogo(int &x, int &y, int &vec) //Prints out a series of circles in a circle
{
if(vec == 15);
else
{
circle (x, y, 3);
cyclexy(x, y, rvec);
cyclexy(x, y, rvec);
printlogo(x, y, ++vec);
};
};
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int xmax, ymax, x, y, vec, rx, ry, rvec, size;
void far * ptr;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
};
setcolor(getmaxcolor()); //Initializing
xmax = getmaxx();
ymax = getmaxy();
x = xmax/2;
y = ymax/2;
vec = 0;
ptr = malloc(imagesize(x, y, x+size, y+size);
printlogo(x, y, vec); //Prints out the logo
vec = random(16);
clearscrn();
while(1) //Main loop,
{
checkvec(x, y, vec, size); //Checks to see if object is out of bounds, changes direction if it is
cyclexy(x, y, vec); //Moves the object along the path
getimage(x, y, x+size, y+size, ptr);
putimage(x, y, x+size, y+size, ptr, XOR-PUT);
delay(3);
putimage(x, y, x+size, y+size, ptr, XOR-PUT);
};
/* clean up */
getch();
closegraph();
return 0;
};
|