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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
(* Virtual Pascal 2.1 *)
program Fonction;
{&PMTYPE PM}
(* Courbe représentative d'une fonction numérique *)
uses Windows, OWindows, Couleurs;
type
tFonction = function(const x: single): single;
function F(const x: single): single;
begin
F := 2 * Cos(x) * x;
end;
type
pFenetre = ^tFenetre;
tFenetre = object(tWindow)
pinceauFond: hBrush;
constructor Init(aParent: pWindowsObject; aTitle: pChar);
procedure GetWindowClass(var aWndClass: tWndClass); virtual;
procedure TraceCourbe(aDC: hDC; aFonction: tFonction; aCouleur: tColorRef);
procedure Paint(paintDC: hDC; var paintInfo: tPaintStruct); virtual;
procedure WMKeyDown(var aMsg: tMessage); virtual wm_First + wm_keyDown;
procedure WMLButtonDown(var Msg : tMessage); virtual wm_First + wm_LButtonDown;
destructor Done; virtual;
end;
tProgramme = object(tApplication)
procedure InitMainWindow; virtual;
end;
constructor tFenetre.Init(aParent: pWindowsObject; aTitle: pChar);
var
i: LongInt;
begin
tWindow.Init(aParent, aTitle);
attr.style := ws_Popup or ws_Visible;
attr.x := (GetSystemMetrics(sm_CXScreen) - 512) div 2;
attr.y := (GetSystemMetrics(sm_CYScreen) - 512) div 2;
attr.w := 512;
attr.h := 512;
pinceauFond := CreateSolidBrush(DarkSlateGray);
end;
procedure tFenetre.GetWindowClass(var aWndClass: tWndClass);
begin
tWindow.GetWindowClass(aWndClass);
aWndClass.hbrBackground := pinceauFond;
end;
procedure tFenetre.TraceCourbe(aDC: hDC; aFonction: tFonction; aCouleur: tColorRef);
var
x, y: single;
xEcran, yEcran: longInt;
begin
x := -7.0;
while x < +7.0 do
begin
////////////////////////////////////////////////////////////////////////////////
y := aFonction(x);
////////////////////////////////////////////////////////////////////////////////
if Abs(y) < 7.0 then
begin
xEcran := Round(+32 * x + 256);
yEcran := Round(-32 * y + 256);
SetPixel(aDC, xEcran, yEcran, aCouleur);
end;
////////////////////////////////////////////////////////////////////////////////
x := x + 0.02;
////////////////////////////////////////////////////////////////////////////////
end;
end;
procedure tFenetre.Paint(paintDC: hDC; var paintInfo: tPaintStruct);
var
ancienCrayon, crayon : hPen;
begin
////////////////////////////////////////////////////////////////////////////////
crayon := CreatePen(ps_Solid, 1, FernGreen);
ancienCrayon := SelectObject(paintDC, crayon);
////////////////////////////////////////////////////////////////////////////////
MoveTo(paintDC, 256, 32);
LineTo(paintDC, 256, 480);
MoveTo(paintDC, 32, 256);
LineTo(paintDC, 480, 256);
MoveTo(paintDC, 254, 224);
LineTo(paintDC, 259, 224);
MoveTo(paintDC, 288, 254);
LineTo(paintDC, 288, 259);
////////////////////////////////////////////////////////////////////////////////
SelectObject(paintDC, ancienCrayon);
DeleteObject(crayon);
////////////////////////////////////////////////////////////////////////////////
TraceCourbe(paintDC, F, WhiteSmoke);
////////////////////////////////////////////////////////////////////////////////
end;
procedure tFenetre.WMKeyDown (var aMsg: tMessage);
begin
CloseWindow;
end;
procedure tFenetre.WMLButtonDown (var Msg : tMessage);
begin
CloseWindow;
end;
destructor tFenetre.Done;
begin
DeleteObject(pinceauFond);
tWindow.Done;
end;
procedure tProgramme.InitMainWindow;
begin
MainWindow := New(pFenetre, Init(nil, 'Fonction'));
end;
var
prog: tProgramme;
begin
prog.Init('fonction');
prog.Run;
prog.Done;
end. |
Partager