Министерство образования и науки РФ
Костромской Государственный Технологический Университет
Кафедра Информационных технологий
Пояснительная записка к курсовому проекту
«Разработка графического редактора»
Руководитель
к.т.н., доц. Исаева М.В.
Выполнила
Студентка группы 09-ИС-4
Гончарова А.С
Кострома 2010
Содержание:
Введение . . . . . . . . . . . . . . . . . . . . . . 3
Назначение и область применения . . . . . . . . . . . 3
Технические характеристики . . . . . . . . . . . . . 3
Постановка задачи на разработку программы . . . . . . . . . 3
Описание применяемых математических методов . . . . . . . 3
Алгоритм функционирования процедуры заполнения
ответной матрицы. . . . . . . . . . . . . . . . . . 3
3.4.Функциональная схема . . . . . . . . . . . . . . . . . . . . 9
3.5. Описание и обоснование выбора метода организации данных . . 9
3.6. Описание и обоснование выбора состава технических и
программных средств . . . . . . . . . . . . . . . . . . . 10
Ожидаемые технико-экономические показатели . . . . . 10
Источники, использованные при разработке . . . . . . . 10
Заключение . . . . . . . . . . . . . . . . . . . . 10
Приложение 1. Тесты.
Введение
Наименование программы - «Графический редактор». Основание разработки - техническое задание.
Назначение и область применения
Назначение программы – рисование элементарных геометрических фигур, их заливка цветом.
Технические характеристики
3.1. Постановка задачи на разработку
Разработать алгоритм программы, осуществляющий:
Подключение графического модуля и мыши;
Следующие компоненты программы:
Меню фигур, состоящее из изображений кнопок с названиями фигур (Line, Triangle, Square, Rectangle, Circle, Ellipse);
Палитра из 15 цветов;
Поле для рисования;
Графа параметров фигур (Size Panel);
Кнопка очистки экрана;
Справка.
Рисование контура фигуры заданным цветом;
Заливка фигуры заданным цветом;
Очистка поля рисования;
Выход из программы при нажатии на клавишу «Esc»;
3.2 Описание применяемых математических методов. Тело программы.
Tело программы содержит два цикла repeat … until. Первый отвечает за демонстрацию заставки перед программой и заканчивает своё выполнение при нажатии любой клавиши на клавиатуре. Второй содержит в себе цикл while … do, отслеживающий нажатия левой кнопкой мыши. Внутри этого цикла несколько вложенных циклов if … then, выполнение который запускается при попадании координат указателя мыши в определённый диапазон. Эти циклы отвечают за запоминание текущей фигуры, текущего цвета, ввод и запоминание параметров фигуры, запоминание координат фигуры, очистку экрана.
3.3. Алгоритм функционирования тела программы
Program redaktor;
{$M 65520,0,655350}
Uses Crt,Graph,mm;
Var D,M,X1,X2,Y1,Y2,i,X,Y,j:integer; {D - draver, M - graf. regim}
Xx1,Xx2,Xx3,Yy1,Yy2,Yy3:integer;
mouse_ok,flag_shape,flag_color,flag_digits,flag_koord,flag_clear,flag_kontyr:boolean;
stop,line_control,flag_line,help_flag:boolean;
Button:byte;
max_dlina,code,line_count,kk:integer;
A_str,B_str,C_str:string[3];
A,B,C,A1,A2,B1,B2,color,shape_spliter{,znach,spliter}:integer;
count,MouseX,MouseY:word;
fon,cl,color_tmp,color_tmp2,tr_count,col,xx:integer;
sina,cosa:real;
dlina:integer;
digit:string[1];
s:string[10];
help:text;
help_str,stroka:string;
Begin
ClrScr;
A:=1;
B:=1;
C:=1;
DetectGraph(D,M); {testiryet aparatyry i opredeljaet max dopystimie draiver i regim}
If {D=-2 then Writeln('Videoadapter ne naiden') } graphResult<>0 then halt
else InitGraph(D,M,'F:\kursach\redactor\egavga.bgi');
{iniciiryet perevod vidioadaptera v vidioregim}
repeat
SetColor(8);
OutTextXY(5,5,'Production from Sasha Goncharova, ver 1.0');
SetColor(7);
OutTextXY(210,370,'press any key to enter...');
OutTextXY(213,382,'or press ESC to exit');
SetColor(12);
OutTextXY(210,200, 'G R A P H I C E D I T O R');
SetColor(4);
Rectangle(195,180,440,220);
Rectangle(185,170,450,230);
SetColor(10);
Rectangle(190,175,445,225);
Until KeyPressed;
draw_screen;
podkl_mouse(mouse_ok, button);
show_mouse;
get_mouse(button,mousex,mousey);
knop_mouse(button,count,mousex,mousey);
get_mouse(button,mousex,mousey);
Assign(help, 'h:\kursach\redactor\h1.txt');
REPEAT
get_mouse(button,mousex,mousey);
If button=1 then
Begin
A_str:='';
B_str:='';
C_str:='';
If (MouseX>80) and(MouseY>360) and(MouseX<180) and (MouseY<375) then
Begin
hide_mouse;
SetColor(7);
OutTextXY(200,360, 'Vvedite parametry cherez probel.');
OutTextXY(200,375, 'Kazhdyi parametr dolzhen byt zapisan');
OutTextXY(200,390, 'v vide XX, naprimer, "32","07","10".');
OutTextXY(200,405, 'Posle okonchaniya vvoda nazhmite Enter.');
OutTextXY(200,420, 'Vse parametry po ymolchaniy ravni 1.');
case shape_spliter of
1: max_dlina:=2;
2: max_dlina:=8;
3: max_dlina:=2;
4: max_dlina:=5;
5: max_dlina:=2;
6: max_dlina:=5;
end;
stroka:='';
dlina:=0;
If dlina<max_dlina then
repeat
case ReadKey of
#8: Begin
if dlina>0 then
Begin
SetFillStyle(1,0);
Bar(85+7*(dlina-1), 361, 85+7*(dlina), 374);
dlina:=dlina-1;
s:=stroka;
stroka:='';
For i:=1 to dlina do
stroka:=stroka+s[i];
End;
End;
#32: Begin
If (dlina=2) or (dlina=5) and (dlina<>8) then
Begin
OutTextXY(85+7*dlina, 365, ' ');
stroka:=stroka+' ';
dlina:=dlina+1;
End;
End;
#48: Begin
If (dlina<>2) and (dlina<>5) and (dlina<>8) then
Begin
OutTextXY(85+7*dlina, 365, '0');
stroka:=stroka+'0';
dlina:=dlina+1;
End;
End;
#49: Begin
If (dlina<>2) and (dlina<>5) and (dlina<>8) then
Begin
OutTextXY(85+7*dlina, 365, '1');
stroka:=stroka+'1';
dlina:=dlina+1;
End;
End;
#50: Begin
If (dlina<>2) and (dlina<>5) and (dlina<>8) then
Begin
OutTextXY(85+7*dlina, 365, '2');
stroka:=stroka+'2';
dlina:=dlina+1;
End;
End;
#51: Begin
If (dlina<>2) and (dlina<>5) and (dlina<>8) then
Begin
OutTextXY(85+7*dlina, 365, '3');
stroka:=stroka+'3';
dlina:=dlina+1;
End;
End;
#52: Begin
If (dlina<>2) and (dlina<>5) and (dlina<>8) then
Begin
OutTextXY(85+7*dlina, 365, '4');
stroka:=stroka+'4';
dlina:=dlina+1;
End;
End;
#53: Begin
If (dlina<>2) and (dlina<>5) and (dlina<>8) then
Begin
OutTextXY(85+7*dlina, 365, '5');
stroka:=stroka+'5';
dlina:=dlina+1;
End;
End;
#54: Begin
If (dlina<>2) and (dlina<>5) and (dlina<>8) then
Begin
OutTextXY(85+7*dlina, 365, '6');
stroka:=stroka+'6';
dlina:=dlina+1;
End;
End;
#55: Begin
If (dlina<>2) and (dlina<>5) and (dlina<>8) then
Begin
OutTextXY(85+7*dlina, 365, '7');
stroka:=stroka+'7';
dlina:=dlina+1;
End;
End;
#56: Begin
If (dlina<>2) and (dlina<>5) and (dlina<>8) then
Begin
OutTextXY(85+7*dlina, 365, '8');
stroka:=stroka+'8';
dlina:=dlina+1;
End;
End;
#57: Begin
If (dlina<>2) and (dlina<>5) and (dlina<>8) then
Begin
OutTextXY(85+7*dlina, 365, '9');
stroka:=stroka+'9';
dlina:=dlina+1;
End;
End;
#13: dlina:=max_dlina+1;
End;
until dlina=max_dlina+1;
show_mouse;
code:=0;
For i:=1 to max_dlina do
Begin
If (stroka[i]<>' ') and (i<=2) then
A_str:=A_str+stroka[i];
If (stroka[i]<>' ') and (i>=4) and (i<6) then
B_str:=B_str+stroka[i];
If (stroka[i]<>' ') and (i>=7) and (i<9) then
C_str:=C_str+stroka[i];
End;
If (A_str='') or (A_str='0') or (A_str='00') then A:=1
else Val(A_str,A,code);
If (B_str='') or (B_str='0') or (B_str='00') then B:=1
else Val(B_str,B,code);
If (C_str='') or (C_str='0') or (C_str='00') then C:=1
else Val(C_str,C,code);
End;
If (MouseX>GetMaxX-130) and(MouseY>GetMaxY-120) and(MouseX<GetMaxX-70) and (MouseY<GetMaxY-100) then
Begin
flag_color:=false;
flag_shape:=false;
flag_koord:=false;
flag_kontyr:=false;
stop:=false;
flag_clear:=true;
draw_screen;
End;
If (MouseX>5) and (MouseX<GetMaxX-10) and (MouseY>90) and (MouseY<320) then
Begin
draw_shape;
draw_color;
draw_bottom;
X1:=5;
X2:=GetMaxX-10;
Y1:=100;
Y2:=320;
SetColor(15);
Rectangle(X1,Y1,X2,Y2);
SetFillStyle(1,0);
Bar(0,100,4,320);
Bar(GetMaxX-9,100,GetMaxX,320);
If (flag_color=true) and (flag_shape=true) then
Begin
flag_koord:=true;
If shape_spliter=1 then
If line_count=0 then
Begin
A2:=MouseX;
B2:=MouseY;
End
Else
Begin
A1:=A2;
B1:=B2;
A2:=MouseX; {center figyri}
B2:=MouseY;
End
Else
Begin
A1:=MouseX; {center figyri}
B1:=MouseY;
End;
End;
If (shape_spliter=2) then
If (A+B<C) or (A+C<B) or (B+C<A) then
Begin
SetFillStyle(1,0);
Bar(81,361,179,374);
A:=1;
B:=1;
C:=1;
End;
line_count:=line_count+1;
End;
{SHAPES}
If (MouseX>GetMaxX-180) and (MouseX<GetMaxX-10) and (MouseY>5) and (MouseY<88) then
Begin
If help_flag=true then draw_field;
help_flag:=false;
fon:=0;
tr_count:=0;
line_count:=0;
stop:=false;
flag_clear:=false;
draw_shape;
flag_shape:=true;
flag_kontyr:=false;
flag_koord:=false;
line_control:=false;
color_tmp:=0;
kk:=0;
If (MouseY>5) and (MouseY<18) then {LINE}
shape_spliter:=1;
If (MouseY>19) and (MouseY<32) then {TRIANGLE}
shape_spliter:=2;
If (MouseY>33) and (MouseY<46) then {SQUARE}
shape_spliter:=3;
If (MouseY>47) and (MouseY<60) then {RECTANGLE}
shape_spliter:=4;
If (MouseY>61) and (MouseY<74) then {CIRCLE}
shape_spliter:=5;
If (MouseY>75) and (MouseY<88) then {ELLIPSE}
shape_spliter:=6;
END;
{PALITRA}
If (MouseX>15) and (MouseX<304) and (MouseY>35) and (MouseY<60) then
BEGIN
If help_flag=true then draw_field;
help_flag:=false;
line_count:=0;
If flag_kontyr=true then stop:=true;
color_tmp:=color;
flag_clear:=false;
draw_color;
flag_color:=true;
line_control:=true;
If (MouseX>15) and (MouseX<32) then color:=1;
If (MouseX>33) and (MouseX<50) then color:=2;
If (MouseX>51) and (MouseX<68) then color:=3;
If (MouseX>69) and (MouseX<86) then color:=4;
If (MouseX>87) and (MouseX<104) then color:=5;
If (MouseX>105) and (MouseX<122) then color:=6;
If (MouseX>123) and (MouseX<140) then color:=7;
If (MouseX>141) and (MouseX<158) then color:=8;
If (MouseX>159) and (MouseX<176) then color:=9;
If (MouseX>177) and (MouseX<194) then color:=10;
If (MouseX>195) and (MouseX<212) then color:=11;
If (MouseX>213) and (MouseX<230) then color:=12;
If (MouseX>231) and (MouseX<248) then color:=13;
If (MouseX>249) and (MouseX<266) then color:=14;
If (MouseX>267) and (MouseX<285) then color:=15;
End;
If (flag_shape=true) and (flag_kontyr=false) and (flag_koord=true) and (flag_color=true) then
Begin
hide_mouse;
stop:=false;
SetLineStyle(0, 0, NormWidth);
SetColor(color);
case shape_spliter of
1: Begin
If line_count>1 then
Begin
Line(A1,B1,A2,B2);
Xx1:=A1;
Xx2:=A2;
Yy1:=B1;
Yy2:=B2;
End
End;
2: Begin
color_tmp:=color;
X1:=A1-(A div 10);
X2:=X1+A;
Y1:=B1+(B div 10);
cosa:=cos((B*B+C*C-A*A)/(2*B*C));
sina:=(1-sqr(cosa));
Line(X1,Y1,X2,Y1);
Line(X1,Y1,X1+B*round(sina),Y1+B*round(cosa));
Line(X1+B*round(sina),Y1+B*round(cosa),X2,Y1);
Xx1:=A1-(A div 10);
Yy1:=B1+(B div 10);
Xx2:=X1+B*round(sina);
Yy2:=Y1+B*round(cosa);
Xx3:=X1+A;
Yy3:=Y1;
col:=color;
End;
3: Begin
X1:=A1-(A div 4);
X2:=X1+A;
Y1:=B1-(A div 4);
Y2:=Y1+A;
rectangle(X1,Y1,X2,Y2);
Xx1:=A1-(A div 4);
Xx2:=X1+A;
Yy1:=B1-(A div 4);
Yy2:=Y1+A;
End;
4: Begin
X1:=A1-(A div 4);
X2:=X1+A;
Y1:=B1-(B div 4);
Y2:=Y1+B;
rectangle(X1,Y1,X2,Y2);
Xx1:=A1-(A div 4);
Xx2:=X1+A;
Yy1:=B1-(B div 4);
Yy2:=Y1+B;
End;
5: Begin
Circle(A1,B1,A);
Xx1:=A1;
Yy1:=B1;
col:=color;
End;
6: Begin
Ellipse(A1,B1,0,360,A,B);
Xx1:=A1;
Yy1:=B1;
col:=color;
End;
End;
If shape_spliter<>1 then flag_kontyr:=true;
show_mouse;
end;
If (flag_kontyr=true) and (flag_koord=true) and (stop=true) then
Begin
hide_mouse;
case shape_spliter of
{ 1: Line(Xx1,Yy1,Xx2,Yy2);}
2: Begin
If (A+B>C) and (A+C>B) and (B+C>A) then
Begin
Setcolor(color);
For xx:=Xx1+1 to Xx3-1 do
Line(xx,Yy1+1,Xx2, Yy2-1);
SetColor(col);
Line(Xx1,Yy1,Xx3,Yy3);
Line(Xx1,Yy1,Xx2,Yy2);
Line(Xx2,Yy2,Xx3,Yy3);
SetColor(color);
End;
End;
3: Begin
If (A1>Xx1+1) and (A1<Xx2-1) And (B1>Yy1+1) and (B1<Yy2-1) then
Begin
setfillstyle(1,color);
Bar(Xx1+1,Yy1+1,Xx2-1,yY2-1);
End;
End;
4: Begin
If (A1>Xx1+1) and (A1<Xx2-1) And (B1>Yy1+1) and (B1<Yy2-1) then
Begin
setfillstyle(1,color);
Bar(Xx1+1,Yy1+1,Xx2-1,yY2-1);
End;
End;
5: Begin
If sqr(A1-Xx1)+sqr(B1-Yy1)<=sqr(A) then
Begin
SetColor(col);
setfillstyle(1,color);
FillEllipse(Xx1,Yy1,A,A);
End;
End;
6: Begin
If (4*sqr(A1)/sqr(A)+4*sqr(B1)/sqr(B)<=1) then
Begin
SetColor(col);
setfillstyle(1,color);
FillEllipse(Xx1,Yy1,A,B);
End;
End;
End;
show_mouse;
stop:=true;
End;
If (MouseX>GetMaxX-130) and (MouseY>GetMaxY-98) and (MouseX<GetMaxX-70) and (MouseY<GetMaxY-78) then
Begin
draw_field;
X1:=5;
Y1:=105;
SetColor(15);
Reset(help);
{ For j:=1 to 7 do
Readln(help,help_str); }
For i:=1 to 19 do
Begin
ReadLn(help,help_str);
OutTextXY(X1,Y1, help_str);
Y1:=Y1+10;
End;
repeat
until button=1;
help_flag:=true;
Close(help);
End;
End;
Until KeyPressed and (Readkey=#27);
End.
Блок-схема:
1
1
1
2
2
3
4
5
6
1
2
3
4
5
6
1
2
3
4
5
6
1
2
3
4
5
6
1
2
3
4
5
6
1
2
3
4
5
6
1
2
5
6
1
2
5
6
1
2
6
1
2
6
1
2
6
3
1
2
6
3
1
2
6
1
2
6
1
2
6
3
1
2
6
3
1
2
6
3
1
2
6
3
1
2
6
3
1
2
6
3
1
2
6
3
1
2
6
3
1
2
6
3
1
2
6
3
1
2
6
1
2
2
3
2
6
1
6
2
1
6