Unit Plot; Interface uses ViewPort, Color, Basic, Graph; type tPoint = object x,y: Real; end; tPlot = object cRegionLL, cRegionUR: tPoint; {which region to display} cWindow00, cWindowDim: tPoint; {window position on the screen} procedure SetRegion( px1, px2, py1, py2: Real ); {minimal and maximal x, minimal and maximal y} procedure SetWindow( px0, py0, pxd, pyd: Real ); {coordinates of lower left corner + width and height of a window} procedure Axis( pColor: tColor ); {draw axis} procedure Line( px1, py1, px2, py2: Real; pColor: tColor ); {private} function _VirtualToReal( px, py: Real; var pXOut, pYOut: Real ): Boolean; {true if point is inside selected region} end; Implementation procedure tPlot.SetRegion( px1, px2, py1, py2: Real ); begin cRegionLL.x := px1; cRegionLL.y := py1; cRegionUR.x := px2; cRegionUR.y := py2; end; procedure tPlot.SetWindow( px0, py0, pxd, pyd: Real ); begin cWindow00.x := px0; cWindow00.y := py0; cWindowDim.x := pxd; cWindowDim.y := pyd; end; procedure tPlot.Axis( pColor: tColor ); var sLabel: String; p1, p2: tPoint; begin with Scr do begin move( cWindow00, p1, sizeof( p1 ) ); move( cWindow00, p2, sizeof( p2 ) ); p2.x := p2.x + cWindowDim.x; p2.y := p2.y + cWindowDim.y; line( p1.x-0.5, p1.y, p2.x, p1.y, pColor ); line( p1.x, p1.y-0.5, p1.x, p2.y, pColor ); line( p2.x, p1.y-0.5, p2.x, p1.y, pColor ); line( p1.x-0.5, p2.y, p1.x, p2.y, pColor ); TextFg( pColor.cData[1] ); sLabel := RealToStr( cRegionLL.x, 4 ); CellWriteXY( p1.x+0.5, p1.y-0.5, sLabel ); sLabel := RealToStr( cRegionLL.y, 4 ); CellWriteXY( p1.x+0.5, p1.y+CellY, sLabel ); sLabel := RealToStr( cRegionUR.x, 4 ); CellWriteXY( p2.x-length(sLabel)*CellX, p1.y-0.5, sLabel ); sLabel := RealToStr( cRegionUR.y, 4 ); CellWriteXY( p1.x+0.5, p2.y, sLabel ); { line( cWindow00.x+cWindowDim.x, cWindow00.y, cWindow00.x+cWindowDim.x, cWindow00.y+cWindowDim.y, pColor ); line( cWindow00.x, cWindow00.y+cWindowDim.y, cWindow00.x+cWindowDim.x, cWindow00.y+cWindowDim.y, pColor ); TextFg( Red ); sLabel := '[' + RealToStr( cRegionLL.x, 4 ) + ',' + RealToStr( cRegionLL.y, 4 ) + ']'; CellWriteXY( cWindow00.x, cWindow00.y+CellY, sLabel ); CellWriteXY( cWindow00.x+cWindowDim.x, cWindow00.y-0.5, RealToStr( cRegionUR.x, 4 ) ); CellWriteXY( cWindow00.x, cWindow00.y+cWindowDim.y, RealToStr( cRegionUR.y, 4 ) ); sLabel := '[' + RealToStr( cRegionUR.x, 4 ) + ',' + RealToStr( cRegionUR.y, 4 ) + ']'; CellWriteXY( cWindow00.x+cWindowDim.x-length(sLabel)*CellX, cWindow00.y+cWindowDim.y-0.5, sLabel ); } end; end; procedure tPlot.Line( px1, py1, px2, py2: Real; pColor: tColor ); var x1, y1, x2, y2: Real; begin if _VirtualToReal( px1, py1, x1, y1 ) and _VirtualToReal( px2, py2, x2, y2 ) then Scr.Line( x1, y1, x2, y2, pColor ); end; function tPlot._VirtualToReal( px, py: Real; var pXOut, pYOut: Real ): Boolean; begin if (px >= cRegionLL.x) and (px <= cRegionUR.x) and (py >= cRegionLL.y) and (py <= cRegionUR.y) then begin pXOut := ( cWindow00.x+(px-cRegionLL.x)/(cRegionUR.x-cRegionLL.x) *(cWindowDim.x) ); pYOut := ( cWindow00.y+(py-cRegionLL.y)/(cRegionUR.y-cRegionLL.y) *(cWindowDim.y) ); _VirtualToReal := True; end else _VirtualToReal := False; end; begin end.