; Viewport Example ; ---------------- Graphics 640,480,0,2 SetBuffer BackBuffer() SeedRnd MilliSecs() ; Bouncing balls that roam the whole screen Dim bx#(7),by#(7),vx#(7),vy#(7) For i=0 To 7 bx(i)=Rnd(0,600) by(i)=Rnd(40,440) vx(i)=Rnd(2,4) vy(i)=Rnd(2,4) Next port=1 While Not KeyDown(1) ; Space toggles the clipping viewport on and off If KeyHit(57) Then port=1-port ; Full-screen viewport first so Cls wipes everything Viewport 0,0,640,480 Cls ; Show where the clipping window sits Color 80,80,80 Rect 158,118,324,244,0 ; Restrict all following drawing to a 320x240 window If port Then Viewport 160,120,320,240 ; The balls still move everywhere, but drawing is clipped when on For i=0 To 7 bx(i)=bx(i)+vx(i) by(i)=by(i)+vy(i) If bx(i)<0 Or bx(i)>604 Then vx(i)=-vx(i) If by(i)<0 Or by(i)>444 Then vy(i)=-vy(i) Color 60+i*24,180,255-i*24 Oval bx(i),by(i),36,36,1 Next ; Back to full screen so the overlay is never clipped Viewport 0,0,640,480 Color 255,255,255 Text 0,0,"Space: toggle clipping Esc: exit" If port Then Text 0,20,"Viewport 160,120,320,240 - drawing is clipped to the grey box" Else Text 0,20,"Viewport 0,0,640,480 - full screen, no clipping" EndIf Flip Wend End