Ever Wonder how they ZOOM IN and ZOOM OUT the graphics in the AUTOCAD ??
Here is the example :-
zoom-inkey-Move.zip
The Source code in FreeBASIC is as such ;
SCREEN 9 '640x350 EGA
CLS
COLOR 12
XA = 320: YA = 175:
XSCALE = 50: YSCALE = 50 'zoom factor e.g. 50 pixels = 1 unit
LINE (0, 175)-(639, 175) 'draw y-axis
LINE (320, 0)-(320, 349) 'draw x-axis
Xmove = 10
DO
A$ = INKEY$
IF A$ = CHR$(122) OR A$ = CHR$(90) THEN ' Zoom in Z
XSCALE = XSCALE + 5: YSCALE = YSCALE + 5:
CLS
END IF
IF A$ = CHR$(120) OR A$ = CHR$(88) THEN ' Zoom Out X
XSCALE = XSCALE - 5: YSCALE = YSCALE - 5
LOCATE 20, 5: PRINT XSCALE, YSCALE
IF XSCALE < 5 THEN XSCALE = 5: IF YSCALE < 5 THEN YSCALE = 5
CLS
END IF
IF UCASE$(RIGHT$(A$, 1)) = "M" THEN XA = XA - 5: CLS ' Move Right
IF UCASE$(RIGHT$(A$, 1)) = "K" THEN XA = XA + 5: CLS ' Move Left
IF UCASE$(RIGHT$(A$, 1)) = "H" THEN YA = YA + 5: CLS ' Move Up
IF UCASE$(RIGHT$(A$, 1)) = "P" THEN YA = YA - 5: CLS ' Move Down
LINE (INT(XSCALE*(-Xmove/2)+XA),INT(YA-YSCALE))-(INT(XSCALE*(Xmove/2)+XA),INT(YA+YSCALE)),4,B 'Draw Box
LINE (0, YA)-(639, YA) 'draw y-axis
LINE (XA, 0)-(XA, 349) 'draw x-axis
COLOR 13
FOR X = -Xmove TO Xmove STEP .001
'a loop to graph from -10 to +10 by increments of .001
Y = (3 * X) + 2 'linear equation y=mx +b m=3 b=2
PSET (INT(XSCALE * X + XA), INT(YA - (YSCALE * Y)))
Y = SIN(X) 'wave equation
PSET (INT(XSCALE * X + XA), INT(YA - (YSCALE * Y)))
NEXT X
LOCATE 24, 5:
PRINT "Press ARROW keys to Move RIGHT , LEFT , UP and DOWN"
LOCATE 23, 5:
PRINT "Press Z to ZOOM IN , Press X to ZOOM OUT , Esc to Quit"
LOCATE 22, 5: PRINT "XSCALE :"; XSCALE, "YSCALE :"; YSCALE
LOCATE 21, 5: PRINT "KEY PRESS", A$
LOOP UNTIL A$ = CHR$(27)
END
No comments:
Post a Comment