' ROT_3.LST
' Rotate graphic by any angle
' -----
' Create graphic
DEFFILL 1,3,8
PBOX 1,1,208,48
DEFTEXT 1,0,0,26
TEXT 13,36,"GFA - Basic"
'
' Offset from top left
x%=1
y%=1
' width and height
w%=208
h%=48
' rotation angle in degrre (trig.)
rot%=45
'
' Save Graphic
GET x%,y%,x%+w%-1,y%+h%-1,s$
s%=V:s$+6
'
' Byte length of graphic in GET format (filled to word)
xb%=((w%+15) DIV 16)*2
'
' Destination is always the screen
'
ALERT 2,"Rotate graphic in GFA BASIC,|or GFA ASSEMBLER (accurate),|or GFA ASSEMBLER (fast)?",1,"BASIC|accurate|fast",question%
'
' Rotate in GFA BASIC
IF question%=1
  t=TIMER
  ' Address for intermediate storage, same as
  ' bottom left corner of screen
  dh%=XBIOS(2)+80*399
  '
  ' Starting values for destination area coordinates:
  s=SINQ(rot%)
  c=COSQ(rot%)
  ' Step width
  step=2/3
  ' display rotated graphic in middle
  xm%=320-((h%-1)*s+(w%-1)*c)/2+0.5
  ym%=200-((h%-1)*c-(w%-1)*s)/2+0.5
  ' Hide mouse (quicker)
  HIDEM
  ' Set strip at bottom of picture, calculate polar coordinates
  ' Display rotation point on screen
  ' IF test necessary as clipping impossible
  FOR y0=0 TO h%-1+step STEP step
    BMOVE s%+INT(y0)*xb%,dh%,xb%
    yh=ym%+y0*c+0.5
    xh=xm%+y0*s+0.5
    FOR x0=0 TO w%-1+step STEP step
      yk%=yh-x0*s
      IF yk%<399
        xk%=xh+x0*c
        IF yk%>=0 AND xk%>=0 AND xk%<=639
          PSET xk%,yk%,PTST(x0,399)
        ENDIF
      ENDIF
    NEXT x0
  NEXT y0
  '
  ' erase bottom line on screen
  COLOR 0
  LINE 0,399,639,399
  COLOR 1
  SHOWM
ENDIF
'
' Rotate in GFA ASSEMBLER
IF question%>1
  t=TIMER
  '
  ' ROT_A1.INL, Length: 1112 Bytes
  INLINE ass_1%,1112
  '
  ' ROT_A2.INL, Length: 1112 Bytes
  INLINE ass_2%,1112
  '
  ' Call assembler program, with
  sadr%=s%              ! Address of source bitmap       must be even!!
  sb%=xb%               ! Width of bitmap in bytes       must be even!!
  x0%=0                 ! Starting point x coordinate in q
  y0%=0                 ! Starting point y coordinate in q
  w%=w%                 ! Width of section
  h%=h%                 ! Height of section
  x1%=320               ! Destination coordinate x
  y1%=200               ! Destination coordinate y
  tadr%=XBIOS(2)        ! Address of destination bitmap  must be even!!
  tb%=80                ! Width of bitmap in bytes       must be even!!
  phi%=rot%*182        ! Angle between 0 and 65535
  '
  IF question%=2
    VOID C:ass_1%(L:sadr%,sb%,x0%,y0%,w%,h%,L:tadr%,tb%,x1%,y1%,phi%)
  ELSE
    VOID C:ass_2%(L:sadr%,sb%,x0%,y0%,w%,h%,L:tadr%,tb%,x1%,y1%,phi%)
  ENDIF
ENDIF
'
tt=(TIMER-t)/200
t$=STR$(tt)
'
IF question%=1
  ALERT 1,"Rotating graphic |in GFA BASIC takes|"+t$+" seconds.",1," OK ",d%
ELSE
  ALERT 1,"Rotating graphic|in GFA ASSEMBLER takes|"+t$+" seconds.",1," OK ",d%
ENDIF
EDIT
