AnyKey`щик
Регистрация: 22.12.2006
Сообщений: 5
Написано 0 полезных сообщений (для 0 пользователей)
|
График и ввод функции
Привет программисты!
Помогите  Рисую график, но нужно вводить функцию. Т.е. она не должна быть задана в коде, а юзер должен сам её вводить. Покажите как?! И ещё.. посмотрите чуть чуть на код проги, подправьте, а то я ньюби совсем. Вот смотрел на прогу http://midp.dev.juga.ru/ и облизывался

program graph;
var
x1,x2:real;
y1,y2:real;
ff:real;
okCommand:command;
nameField,nameField2,d:integer;
userName,a:string;
m:real;
label_id:integer;
choiceGroupID: integer;
repa: integer;
choiceGroupID2: integer;
par, lin, sin, gep, sq, par2: integer;
igrat, about, vyhod, help, hist : integer;
exit, exit1, play, clicked : command;
function f(x:real): real;
begin
if choiceIsSelected
(choiceGroupID, par) then
begin
f:=x*x;
end;
if choiceIsSelected
(choiceGroupID, par2) then
begin
f:=x*x*x;
end;
if choiceIsSelected
(choiceGroupID, sq) then
begin
f:=sqrt(x);
end;
if choiceIsSelected
(choiceGroupID, gep) then
begin
f:=2/x;
end;
if choiceIsSelected
(choiceGroupID, lin) then
begin
f:=2*x+5;
end;
if choiceIsSelected
(choiceGroupID, sin) then
begin
f:=x;
end;
end;
procedure GrOfFunc;
var
x:real;
y:real;
dx:real;
l,b:real;
w,h:real;
x0,y0:real;
i:integer;
cm:command;
begin
l:=getWidth div 2;
b:=getHeight div 2;
h:=getHeight div 2;
w:=getWidth;
if choiceIsSelected
(choiceGroupID, sq) then
x1:=0;
else
x1:=-9;
x2:=9;
dx:=0.1;
setcolor(0,0,0);
x0:=getWidth div 2;
y0:=b;
DrawLine(trunc(x0-w), trunc(y0), trunc(x0+w), trunc(y0));
DrawLine(trunc(l), trunc(b-h), trunc(l), trunc(b+h));
setColor(255, 0, 0);
x:=x1;
if m=0 then m:=1;
repeat
y:=f(x);
DrawLine(trunc(x0+x*m), trunc(y0-y*m), trunc(x0+(x+dx)*m), trunc(y0-f(x+dx)*m));
setColor(255, 255, 255);
fillRect(0, 0, 50, 23);
setColor(255, 0, 0);
drawtext(IntegerToString(trunc(x*m)),1,0);
drawtext(IntegerToString(trunc(y*m)),1,11);
//delay(d*1000);
x:=x+dx;
repaint;
until (x>=x2);
end;
procedure form;forward;
Procedure paint;
begin
if not choiceIsSelected
(choiceGroupID2, repa) then
begin
setColor(255, 255, 255);
fillRect(0, 0, 200, 200);
end;
if formGetText(nameField)='' then m:=1 else
begin
m:=stringToReal(formGetText(nameField), 10);
d:=StringToInteger(formGetText(nameField2));
end;
ShowCanvas;
GrOfFunc;
while
getKeyClicked = KE_NONE do
begin
setColor(255, 0, 0);
drawtext('Press any',3,getHeight-20);
repaint;
end;
form;
end;
procedure menu; forward;
procedure form;
begin
ClearForm;
showForm;
choiceGroupID := formAddChoice('Выберите функцию', CH_EXCLUSIVE);
par := choiceAppendString(choiceGroupID, 'Y=X^2');
par2 := choiceAppendString(choiceGroupID, 'Y=X^3');
lin := choiceAppendString(choiceGroupID, 'Y=2*X+5');
sin := choiceAppendString(choiceGroupID, 'Y=X');
gep := choiceAppendString(choiceGroupID, 'Y=2/X');
sq := choiceAppendString(choiceGroupID, 'Y=sqrt(X)');
nameField := formAddTextField('Масштаб(X,Y*)', '', 2, TF_NUMERIC);
nameField2 := formAddTextField('Задержка(sec)', '', 1, TF_NUMERIC);
choiceGroupID2 := formAddChoice('Накладка', CH_MULTIPLE);
repa := choiceAppendString(choiceGroupID2, 'Да');
okCommand := createCommand('OK', CM_OK, 1);
addCommand(okCommand);
play := CreateCommand('Назад', CM_BACK, 1);
AddCommand(play);
clicked := getClickedCommand;
repeat
//delay(100);
clicked := getClickedCommand;
until (clicked = play) or (clicked = okCommand);
if clicked = play then menu;
paint;
end;
procedure ab;
begin
clearform;
showform;
{!}
play := CreateCommand('Назад', CM_BACK, 2);
AddCommand(play);
repeat
//delay(100);
until GetClickedCommand <> EmptyCommand;
end;
procedure pomosh;
begin
clearform;
showForm;
{!}
play := CreateCommand('Назад', CM_BACK, 2);
AddCommand(play);
repeat
//delay(100);
until GetClickedCommand <> EmptyCommand;
end;
procedure vers;
begin
clearform;
showForm;
{!}
play := CreateCommand('Назад', CM_BACK, 2);
AddCommand(play);
repeat
//delay(100);
until GetClickedCommand <> EmptyCommand;
end;
procedure menu;
begin
ShowMenu('График функции.', CH_IMPLICIT);
igrat := MenuAppendString('График');
about := MenuAppendString('Аффтар');
help := MenuAppendString('Помощь');
hist := MenuAppendString('История');
vyhod := MenuAppendString('Выход');
play := CreateCommand('OK', CM_SCREEN , 1);
AddCommand(play);
exit := CreateCommand('Выход', CM_EXIT, 2);
AddCommand(exit);
repeat
//delay(100);
clicked := getClickedCommand;
until (clicked = play) or (clicked = exit);
if clicked = exit then halt;
showCanvas;
if menuGetSelectedIndex = igrat then form;
if menuGetSelectedIndex = about then ab;
if menuGetSelectedIndex = vyhod then halt;
if menuGetSelectedIndex = hist then vers;
if menuGetSelectedIndex = help then pomosh;
menu;
end;
begin
menu;
while (getClickedCommand <> okCommand) do
begin
while
getKeyClicked = KE_NONE do
begin end;
end;
end.
|