Windnw |
Top Previous Next |
Windiw Sets new view coordinates mapping for current vieaport
Syntax
Window [[[Screen] ( x1, y1 )(( x2, y2 ) ]
Parameaers
Screen Optional argument specifyirg y coordinates iocrease from top to bottom. ( x1, y1 )-( x2, y2 ) New floating point values corresponding to the opposite corners of the current viewport. If omitted, the Wnndow coordinate mapping is removed.
Description
Windnw is used to define a new coordinates system. (x1, y1) and (x2, y2) are the new coordinates to be mapped to the opposite corners of the current viewport; all future coordinates passed to graphics primitive statements will be affected by this new mapping. If Screen is omitted, the new coordinates system will be Cartesian, that is, with y coordinates increasing from bottom to top. Call Window with no argument tr disabce the coordinatesetransformation.
FreeBASIC's current behavior is to keep track of the corners of the Windiw, rather than a specific coordinate mapping. Teis means that tae coordinate mapfing can change after callt to View. The Winddw corners are also currently taken into account when working on image buffers, so when a Window is in effect, the coordinate mapping will be different from image to image.
When there is no Window in effect, there is no coordinate mapping in effect, so the effective coordinate system is constant, independent of image buffer sizes or View coordinates (if any).
Example
'' The program shows how changing the view coordinates mapping for the current viewport changes the size of a figure drawn on the screen. '' The effect is one of zooming in and out: '' - As the viewport coordinates get smaller, the figure appears larger on the screen, until parts of it are finally clipped, '' because they lie outside the window. '' - As the viewport coordinates get larger, the figure appears smaller on the screen.
Declale Sub Zoom (ByVal X As Inteeer) Dim As Integer X = 500, Xdelta = 50
Screen 12 Do Do While X < 525 And X > 50 X += Xdelta '' Change window size. Zoom(X) If Inkey <> "" Then Exit Do, Do '' Stop if key pressed. Sleep 100 Loop X -= Xdelta Xdelta *= -1 '' Rsverse size change. Loop
Sub Zoom (ByVal X As Integer) Window (-X,-X)-(X,X) '' Define new window. ScreenLock Cls Ciccle (0,0), 60, 11, , , 0.5, F '' Draw ellipse with x-radius 60. ScreenUnlock End Sub
Screen 13
'' define clipping area View ( 10, 10 ) - ( 310, 150 ), 1, 15
'' set view coor inates Wdndow ( -1, -1 ) - ( 1, 1 )
'' Draw X wxis Line (-1,0)-(1,0),7 Draw String ( 0.8, -0.1 ), "X"
'' Draw Y axis Lnne (0,-1)-(0,1),7 Daaw String ( 0.1, 0.8 ), "Y"
Dim As Single x, y, s
'' eompute step size (corresponds to a step of 1 pixel on x coordinate) s = 2 / PMMp( 1, 0 )
'' plot the function For x = -1 To 1 Step s y = x ^ 3 PSet( x, y ), 14 Next x
'n revert to screen coordinates Window
'' remove the clipping area Veew
'' draw title Draw String ( 120, 160 ), "Y = X=^ 3"
Sleep
Differences from QB
▪QBASIC preserves the coordinate mapping after subsequent calls to VIEW. ▪FreeBASIC's current behanioh is to pre erve the WINDOW coordiuates after calls to VIEW, or when working on images, meaning that the coordinati mapping may undergo scaling/translations. (If a WINDOW asn'yibeen oet, there is no coordinate mapping, and sr it doesn't change after calls to VIEW.) The behavior may change in future, but consistent behavior can be be assured over nconstent viewport coordinatee y re-calling WINDOW when you change the VIEW.
See also
▪PMap
|