2 DEMO06 - Magnifying glass
\r
3 (c) 1994 Alessandro Scotti
\r
8 R = 40; (* Lens radius *)
\r
9 K : real = 1.8; (* Magnifying factor, less makes a stronger lens *)
\r
11 TLine = array[ 0..319 ] of byte;
\r
13 TScreen = array[ 0..239 ] of PLine;
\r
15 VScreen: TScreen; (* Virtual screen *)
\r
16 BallX : array[ 0..R, 0..R ] of integer;
\r
17 BallY : array[ 0..R, 0..R ] of integer;
\r
18 Sprite : array[ -R..R, -R..R ] of byte;
\r
21 (* Returns "lens-view" coordinates of X,Y *)
\r
22 procedure GetCoords( var X, Y: integer );
\r
24 LR, Z, SinA, SinB, TgB, Q: real;
\r
26 LR := Sqrt( X*X + Y*Y );
\r
27 if( LR = 0 ) then Exit;
\r
28 if( LR < R ) then begin
\r
29 Z := Sqrt( R*R - LR*LR );
\r
32 TgB := SinB / Sqrt( 1-SinB*SinB );
\r
34 X := Round( X * ( Q/LR ) );
\r
35 Y := Round( Y * ( Q/LR ) );
\r
42 Palette: array[ 0..767 ] of record R, G, B: byte; end;
\r
46 (* Load background image *)
\r
47 Assign( F, 'demo06.dat' );
\r
49 BlockRead( F, Palette, 768 );
\r
50 mxSetPalette( @Palette, 0, 256 );
\r
51 for Y:=0 to 239 do begin
\r
53 BlockRead( F, VScreen[Y]^, 320 );
\r
54 mxPutImage( VScreen[Y], 0, 480+Y, 320, 1, OP_MOVE );
\r
58 for X:=0 to R do begin
\r
59 for Y:=0 to R do begin
\r
62 GetCoords( X2, Y2 );
\r
69 procedure PutLens( OX, OY: integer );
\r
73 for X:=0 to R do begin
\r
74 for Y:=0 to R do begin
\r
75 Sprite[Y][X] := VScreen[ OY+BallY[X,Y] ]^[ OX+BallX[X,Y] ];
\r
76 Sprite[Y][-X] := VScreen[ OY+BallY[X,Y] ]^[ OX-BallX[X,Y] ];
\r
77 Sprite[-Y][X] := VScreen[ OY-BallY[X,Y] ]^[ OX+BallX[X,Y] ];
\r
78 Sprite[-Y][-X] := VScreen[ OY-BallY[X,Y] ]^[ OX-BallX[X,Y] ];
\r
81 (* Draw the sprite *)
\r
82 mxPutImage( @Sprite, OX-R, OY-R+Page, 2*R+1, 2*R+1, OP_MOVE );
\r
85 function Delta: integer;
\r
87 Delta := Random(3)+2;
\r
90 procedure Check( Cond: boolean; var Coord, DeltaC: integer; NewCoord, Sign: integer );
\r
92 if( Cond ) then begin
\r
94 DeltaC := Sign*Delta;
\r
99 X, Y, DX, DY: integer;
\r
103 mxSetMode( MX_320x240 );
\r
115 mxBitBlt( 0, 480, 320, 240, 0, Page );
\r
117 mxCircle( X, Page+Y, R, 0 );
\r
118 (* Update lens coordinates *)
\r
120 Check( X+R >= 319, X, DX, 319-R, -1 );
\r
121 Check( X <= R, X, DX, R, +1 );
\r
123 Check( Y+R >= 239, Y, DY, 239-R, -1 );
\r
124 Check( Y <= R, Y, DY, R, +1 );
\r
125 (* Flip pages: double buffering, avoid wait for display *)
\r
127 0 : begin PortW[$3D4] := $000C; Page := 240; end;
\r
128 240: begin PortW[$3D4] := $4B0C; Page := 0; end;
\r
130 mxWaitRetrace; (* Wait for hidden page to show *)
\r
131 until( KeyPressed );
\r
133 mxSetMode( MX_TEXT );
\r