FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DRAWING

Test Feedback demo using two GWorlds


My post earlier today got me thinking about feedback. This demo creates a feedback loop between two gWorlds using two rects of slightly different size and position. This is a dynamic animation effect achieved with very little programming effort. I hope you enjoy it and that it doesn't waste too much of your time :-)

Joe Lertola

'Feedback demo by Joe Lertola
COMPILE 0,_caseinsensitive
DIM gkeys(7)
END GLOBALS
_WinWd@0
_WinHt=300
_bitDepth=32
'-----------
LOCAL FN buildGWorld(rectPtr&,depth)
  DIM t,l,b,r
  t;8 = rectPtr&
  QDErr = FN NEWGWORLD(theWorld&,depth,#@t,0,0,0)
  LONG IF QDErr : t$ = "Insufficient memory for GWorld"
    CALL PARAMTEXT(t$,"","","") : ctrl%=FN NOTEALERT(128,0)
  END IF
END FN = theWorld&
'-----------
LOCAL FN disposeGWorld(theWorld&)
  LONG IF theWorld&
    CALL DISPOSEGWORLD(theWorld&)
  END IF
END FN
'-----------
CLEAR LOCAL
  DIM rect;8, rect2;8
LOCAL FN FeedBack
  WINDOW 2, "", (10,30)-(10+_WinWd, 105), _dialogFrame
  PRINT "Press Arrow keys to move left, right, up or down"
  PRINT "Press Option key to zoom in"
  PRINT "Press Command key to zoom out"
  PRINT "Press Control key to re set to random boarder"
  PRINT "Press Mouse button to exit"
  WINDOW 1, "", (10,125)-(10+_WinWd,125+_WinHt), _dialogFrame
  CALL SETRECT(rect, 0,0,_WinWd, _WinHt)
  rect2;8=@rect
  W1&=FN buildGWorld(@rect,_bitDepth)
  W2&=FN buildGWorld(@rect,_bitDepth)
  LONG IF W1& AND W2&
    CALL GETGWORLD(currPort&,currDevice&)
    mapHand& = FN GETGWORLDPIXMAP(W1&)
    locked = FN LOCKPIXELS(mapHand&)
    pixMapAdr&=FN GETPIXBASEADDR(mapHand&)
'Setup: get random image into gWorld
    remainderOfDivide = _WinWd MOD 4
    wdNum=_WinWd+4-remainderOfDivide
    bytesToMove&=wdNum*_WinHt*(_bitDepth/8)
    adr&=0
    BLOCKMOVE adr&, pixMapAdr&, bytesToMove&
    CALL COPYBITS(#W1&+2,#W2&+2,rect.top%,rect.top%,_srcCopy,0)
    CALL INSETRECT(rect2, 2,2)
    DO
'The feedback is created by copying back and
'fourth between two gWorlds with rects that
'are slightly offset and a different size
      CALL COPYBITS(#W2&+2,#W1&+2,rect.top%,rect2.top%,_srcCopy,0)
      CALL COPYBITS(#W1&+2,#W2&+2,rect.top%,rect.top%,_srcCopy,0)
      CALL COPYBITS(#W1&+2,#currPort&+2,rect.top%,rect.top%,_srcCopy,0)
      CALL GETKEYS(gkeys(0))
      adder=1
'control the size and offset with keyboard keys
      SELECT
        CASE gkeys(7)=8 : CALL OFFSETRECT(rect2,-1,0)'left arrow
        CASE gkeys(7)=16 : CALL OFFSETRECT(rect2,1,0)'right arrow
        CASE gkeys(7)=32 : CALL OFFSETRECT(rect2,0,1)'down arrow
        CASE gkeys(7)=64 : CALL OFFSETRECT(rect2,0,-1)'up arrow
        CASE gkeys(3)=4 : CALL INSETRECT(rect2, 1,1)'option key down
        CASE gkeys(3)=-32768 : CALL INSETRECT(rect2, -1,-1)'command key down
        CASE gkeys(3)=8 'option key down
          BLOCKMOVE adr&, pixMapAdr&, bytesToMove&
      END SELECT
    UNTIL FN BUTTON
  END IF
  FN disposeGWorld(W1&)
  FN disposeGWorld(W2&)
END FN
'-----------
FN FeedBack