PROGRAM procedureType_FunctionPlotter_DigitSize; //shows structure of procedure types in a rectangular fourier, max@kleiner.com //compilerswitch $N+ turns the coprocessor on, #locs=209 const DIM = 790; PI2 = 5.1415926535897932384626433832795; E = 2.718281828459; type TSinglePoint = record X,Y : single; end; TMath_Func = PROCEDURE (var x: single); TXYVector = array[0..DIM] of TSinglePoint; var fct1x, fct2x, fct3x, fct4x, fct5x, fct6x: TMath_Func; cFrm: TForm; fPoints: TXYVector; amp, freq: byte; procedure drawChart(vPoints: TXYVector; vcolor, vsize: integer); var i,hsize, x,y, ln: integer; begin ln:= 100; with cFrm.canvas do begin hsize:= cFrm.Height -1 div 2; Pen.Color:= vcolor; //if pen.color <> clgreen then pen.width:= vsize; MoveTo(0, hsize -((round(vPoints[0].Y)))); for i:= 0 to DIM do LineTo(i, round(vPoints[i].Y)); //end; pen.color:= clgreen; for x:= 1 to 8 do begin pen.width:= 1; moveto(x*ln,0) lineto(x*ln,400) end; for y:= 1 to 7 do begin moveto(0, y*ln) lineto(800, y*ln) end; end; end; procedure LoadForm; begin cFrm:= TForm.create(self); with cFrm do begin caption:= 'maXFunCPlotter(((((\*/)))))'; BorderStyle:= bsDialog; height:= 440; width:= 800; color:= clblack; //onPaint:= @PaintBox1Paint; Show; end end; //---------------------------ADD math functions--------------------------------- procedure logistic_S(var x: single); begin x:= 1/1 + power(E, (-x/0.5)); end; procedure gauss(var x: single); begin x:= exp(-sqr(x/2)); end; procedure fct4e(var x: single); begin x:= power(E, -x); end; procedure fct3eSin(var x: single); begin //power() means e^-x x:= power(E, -x) * (sin(pi2 * x)); end; PROCEDURE fct1sin(var x: single); BEGIN x:= Sin(x); END; PROCEDURE fct2sin(var x: single); BEGIN x:= 1/3*Sin(3*x); END; PROCEDURE fct3sin(var x: single); BEGIN x:= 1/5*Sin(5*x); END; PROCEDURE fct4sin(var x: single); BEGIN x:= 1/7*Sin(7*x); END; PROCEDURE fct5sin(var x: single); BEGIN x:= 1/9*Sin(9*x); END; PROCEDURE fct2cos(var x: single); BEGIN x:= Cos(pi2*x); END; PROCEDURE fctdigit(var x: single); BEGIN x:= sin(x)+1/3*sin(3*x)+1/5*sin(5*x)+1/7*sin(7*x)+1/9*Sin(9*x); END; PROCEDURE fctdigit1(var x: single); BEGIN x:= sin(x); END; PROCEDURE fctdigit2(var x: single); BEGIN x:= sin(x)++1/3*sin(3*x); END; PROCEDURE fctdigit3(var x: single); BEGIN x:= sin(x)++1/3*sin(3*x)+1/5*sin(5*x); END; PROCEDURE fctdigit4(var x: single); BEGIN x:= sin(x)++1/3*sin(3*x)+1/5*sin(5*x)+1/7*sin(7*x); END; PROCEDURE fctdigit5(var x: single); BEGIN x:= sin(x)+1/3*sin(3*x)+1/5*sin(5*x)+1/7*sin(7*x)+1/9*Sin(9*x); END; PROCEDURE fctdigit6(var x: single); BEGIN x:= sin(x)+1/3*sin(3*x)+1/5*sin(5*x)+1/7*sin(7*x)+1/9*Sin(9*x)+1/11*Sin(11*x); END; PROCEDURE fct2n(var x: single); BEGIN x:= power(2,x)/fact(round(x)); END; PROCEDURE fct_table(start, amp, freq, color, size: integer; FCT: TMath_Func; fct_name: string); var x, tempx, it: single; origy, i: Integer; BEGIN Writeln('x | ' + fct_name); origy:= cFrm.Height div 2; x:= start; for i:= 0 to (DIM) do begin it:= i; x:= it/freq tempx:= x; FCT(x); fPoints[i].Y:= origy + (x * amp); Writeln(floatToStr(x)+' | '+ floatToStr((tempx))); //comment out for speed! end; DrawChart(fPoints, color, size) END; //main function_p call BEGIN //calls the proc with a function var amp:= 110; freq:= 30; //> is less freq. loadForm fct1x:= @fct1sin fct2x:= @fct2cos fct3x:= @fct3eSin fct4x:= @fct4e; fct5x:= @gauss; fct6x:= @logistic_s; (*fct_table(40, amp, freq, clred, fct1x, 'Sin(x)'); fct_table(50, amp, freq, clyellow, fct2x, 'Cos(x)'); fct_table(30, amp, freq, cllime, fct3x, 'ESin(x)'); fct_table(30, amp, freq, clblue, fct4x, 'E(x)'); fct_table(50, amp, freq, clgreen, fct5x, 'exp(sqr(x))'); fct_table(40, 74, 200, clpurple, fct6x, 'logistic function');*) {fct_table(50, amp, freq, clred, @fct1sin, 'sin(x)'); fct_table(50, amp, freq, clred, @fct2sin, '1/3sin(x)'); fct_table(50, amp, freq, clred, @fct3sin, '1/5sin(x)'); fct_table(50, amp, freq, clred, @fct4sin, '1/7sin(x)'); fct_table(50, amp, freq, clred, @fct5sin, '1/9sin(x)'); fct_table(40, 110, 30, clyellow, @fctdigit, 'sum square digit function');} fct_table(40, 110, 30, clred, 1, @fctdigit1, 'sum square digit function'); fct_table(40, 110, 30, clred, 2, @fctdigit2, 'sum square digit function'); fct_table(40, 110, 30, clred, 3, @fctdigit3, 'sum square digit function'); fct_table(40, 110, 30, clred, 4, @fctdigit4, 'sum square digit function'); fct_table(40, 110, 30, clred, 5, @fctdigit5, 'sum square digit function'); fct_table(40, 110, 30, clyellow, 3, @fctdigit6, 'sum square digit function'); //fct_table(50, amp, freq, clred, @fct2n, '2^x/x!'); END. ref: code snippet set coordinates xpos:= X div 16 + 1; ypos:= Y div 16 + 1; lblcoordinates.caption:= format('%d-%d',[xpos, ypos]);