Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
8
Добавлен:
29.03.2015
Размер:
3.84 Кб
Скачать
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>

int maxx = 560;
int maxy = 450;
int x0, y0, c;
int f1x, f1y, f1c;
int f2x1, f2y1, f2x2, f2y2, f2c;
int f3x, f3y, f3r, f3c;
int f4x1, f4y1, f4x2, f4y2, f4c;
int f5x1, f5y1, f5x2, f5y2, f5c;
int f6x, f6y, f6r, f6c;
int f7x, f7y, f7rx, f7ry, f7c;
int f8x, f8y, f8rx, f8ry, f8c;
int bdot, brect, bcirc, bline, bfrect, bfcirc, bellip, bfellip;


void drawletters(int x0, int y0, int c)
{
	setcolor(c);

	line(x0, y0, x0, y0+30);
	line(x0, y0, x0 + 20, y0);
	arc(x0+8, y0+20, 230, 135, 10);

	ellipse(x0+40, y0+15, 45, 315, 10, 15);

	line(x0+60, y0, x0+60, y0+30);
	arc(x0+65, y0+5, 230, 135, 7);
	arc(x0+67, y0+20, 230, 135, 10);
}

void redraw(int p)
{
	if (bdot) putpixel(f1x, f1y, p?f1c:0);
	setcolor(p?f2c:0);
	if (brect) rectangle(f2x1, f2y1, f2x2, f2y2);
	setcolor(p?f3c:0);
	if (bcirc) circle(f3x, f3y, f3r);
	setcolor(p?f4c:0);
	if (bline) line(f4x1, f4y1, f4x2, f4y2);
	setfillstyle(SOLID_FILL, p?f5c:0);
	if (bfrect) bar(f5x1, f5y1, f5x2, f5y2);
	setcolor(p?f6c:0);
	setfillstyle(SOLID_FILL, p?f6c:0);
	if (bfcirc) pieslice(f6x, f6y, 0, 360, f6r);
	setcolor(p?f7c:0);
	if (bellip) ellipse(f7x, f7y, 0, 360, f7rx, f7ry);
	setcolor(p?f8c:0);
	setfillstyle(SOLID_FILL, p?f8c:0);
	if (bfellip) fillellipse(f8x, f8y, f8rx, f8ry);
	drawletters(x0,y0, p?c:0);
}

int main(int argc, char* argv[])
{
	time_t t;
	time(&t);
	srand((unsigned) time(&t));
	srand(random(RAND_MAX));

	int driver = VGA;
	int mode = VGAHI;

	initgraph(&driver, &mode, "");

	x0 = random(maxx);
	y0 = random(maxy);
	c = random (8)+8;
	redraw(1);

	int key = 0;
	while (key != 27) {
		key = getch();
		if (key == 0) key = getch();
		switch(key) {
			case 75:
				redraw(0);
				x0-=5;
				if (x0<0) x0=0;
				redraw(1);
				break;
			case 77:
				redraw(0);
				x0+=5;
				if (x0>maxx) x0=maxx;
				redraw(1);
				break;
			case 72:
				redraw(0);
				y0-=5;
				if (y0<0) y0=0;
				redraw(1);
				break;
			case 80:
				redraw(0);
				y0+=5;
				if (y0>maxy) y0=maxy;
				redraw(1);
				break;
			case 32:
				c = random(8)+8;
				redraw(1);
				break;
			case 59:
				redraw(0);
				bdot = !bdot;
				f1x = random(640);
				f1y = random(480);
				f1c = random(8)+8;
				redraw(1);
				break;
			case 60:
				redraw(0);
				brect = !brect;
				f2x1 = random(640);
				f2y1 = random(480);
				f2x2 = random(640);
				f2y2 = random(480);
				f2c = random(8)+8;
				redraw(1);
				break;
			case 61:
				redraw(0);
				bcirc = !bcirc;
				f3x = random(640-100)+50;
				f3y = random(480-100)+50;
				f3r = random(50);
				f3c = random(8)+8;
				redraw(1);
				break;
			case 62:
				redraw(0);
				bline = !bline;
				f4x1 = random(640);
				f4y1 = random(480);
				f4x2 = random(640);
				f4y2 = random(480);
				f4c = random(8)+8;
				redraw(1);
				break;
			case 63:
				redraw(0);
				bfrect = !bfrect;
				f5x1 = random(640);
				f5y1 = random(480);
				f5x2 = random(640);
				f5y2 = random(480);
				f5c = random(8)+8;
				redraw(1);
				break;
			case 64:
				redraw(0);
				bfcirc = !bfcirc;
				f6x = random(640-100)+50;
				f6y = random(480-100)+50;
				f6r = random(50);
				f6c = random(8)+8;
				redraw(1);
				break;
			case 65:
				redraw(0);
				bellip = !bellip;
				f7x = random(640-100)+50;
				f7y = random(480-100)+50;
				f7rx = random(50);
				f7ry = random(50);
				f7c = random(8)+8;
				redraw(1);
				break;
			case 66:
				redraw(0);
				bfellip = !bfellip;
				f8x = random(640-100)+50;
				f8y = random(480-100)+50;
				f8rx = random(50);
				f8ry = random(50);
				f8c = random(8)+8;
				redraw(1);
				break;
		}
	}
	closegraph();

	return 0;
}


Соседние файлы в папке l3