(**********************************************************************

    :Program.  	 R2Test.mod
    :Contents.	 Testmodule for MathLibR2
    :Author.   	 Nicolas Benezan [bne]
    :Address.    Postwiesenstr. 2, D7000 Stuttgart 60
    :Phone.      711/333679
    :Copyright.  Public Domain
    :Language. 	 Modula-2
    :Translator. M2Amiga AMSoft
    :Imports.	 MathLibR2, IntuiStruct [bne]
    :ModHistory. V1.0 [bne] 16.07.88 (Demo Amok#4)
    
**********************************************************************)

MODULE R2Test;

FROM MathLibR2	IMPORT Vector2,Matrix2,Add2,Trans2,Mmul2,Scalar,Invert2;
FROM IntuiStruct IMPORT StructScreen,StructWindow;
FROM Graphics	IMPORT RastPortPtr,Draw,Move,SetDrMd,SetAPen,ViewModes,
		ViewModeSet,jam1,WaitTOF,RectFill;
FROM Exec	IMPORT WaitPort;
FROM Intuition	IMPORT ScreenPtr,WindowPtr,ScreenFlags,ScreenFlagSet,
		WindowFlags,WindowFlagSet,IDCMPFlags,IDCMPFlagSet,
                customScreen,stdScreenHeight,NewScreen,NewWindow,
                OpenScreen,OpenWindow,CloseScreen,CloseWindow;
FROM Arts	IMPORT Assert;
FROM SYSTEM	IMPORT ADR;
FROM MathTrans	IMPORT Sin,Cos;

CONST	Ox=160;
	Oy=122;
	phi=0.05;
        grow=1.005;

VAR	Screen:ScreenPtr;
	Window:WindowPtr;
        MyScreen:NewScreen;
        MyWindow:NewWindow;
        RastPort:RastPortPtr;
        Point:ARRAY [1..4] OF Vector2;
        Matrix:Matrix2;
        Vector:Vector2;
        n,m:INTEGER;

PROCEDURE Round(X:Scalar):INTEGER;
BEGIN
  RETURN INTEGER(X+0.5);
END Round;

PROCEDURE DeleteSquare;
VAR	n:INTEGER;
BEGIN
  SetAPen(RastPort,0);
  RectFill(RastPort,2,10,317,242);
END DeleteSquare;

PROCEDURE DrawSquare;
VAR	n:INTEGER;
BEGIN
  SetAPen(RastPort,1);
  Move(RastPort,Round(Point[4].x)+Ox,Round(Point[4].y)+Oy);
  FOR n:=1 TO 4 DO
    Draw(RastPort,Round(Point[n].x)+Ox,Round(Point[n].y)+Oy);
  END;
END DrawSquare;

BEGIN
  StructScreen(MyScreen,1,0,1,ViewModeSet{},customScreen,ADR("R² Test"));
  Screen:=OpenScreen(MyScreen);
  Assert(Screen#NIL,ADR("Screen klemmt"));
  StructWindow(MyWindow,0,12,320,244,-1,-1,IDCMPFlagSet{closeWindow},
  	WindowFlagSet{windowClose,simpleRefresh,noCareRefresh,backDrop},
        NIL,Screen,customScreen);
  Window:=OpenWindow(MyWindow);
  Assert(Window#NIL,ADR("Window klemmt"));
  RastPort:=Window^.rPort;
  SetDrMd(RastPort,jam1);
  Point[1].x:=-50.0;	(* Quadrat *)
  Point[1].y:=-50.0;
  Point[2].x:=-50.0;
  Point[2].y:=50.0;
  Point[3].x:=50.0;
  Point[3].y:=50.0;
  Point[4].x:=50.0;
  Point[4].y:=-50.0;
  Matrix[1,1]:=Cos(phi)*grow; (* Drehmatrix + zentr. Streckung um "grow" *)
  Matrix[1,2]:=-Sin(phi)*grow;
  Matrix[2,1]:=Sin(phi)*grow;
  Matrix[2,2]:=Cos(phi)*grow;
  DrawSquare;
  FOR n:=1 TO 200 DO
    FOR m:=1 TO 4 DO
      Trans2(Matrix,Point[m],Point[m]); (* 200 mal vorwärts *)
    END;
    WaitTOF;
    DeleteSquare;
    DrawSquare;
  END;
  IF Invert2(Matrix) THEN END; (* Umkehrung *)
  Mmul2(Matrix,Matrix,Matrix); (* Abbildung verdoppeln *)
  FOR n:=1 TO 100 DO
    FOR m:=1 TO 4 DO
      Trans2(Matrix,Point[m],Point[m]); (* 100 mal doppelt rückwärts *)
    END;
    WaitTOF;
    DeleteSquare;
    DrawSquare;
  END;
  WaitPort(Window^.userPort);
  CloseWindow(Window);
  CloseScreen(Screen);
END R2Test.
