MODULE Fractal;

	IMPORT appl, graf, VDI, v;

	CONST
		Xreso = 100;
		Yreso = 100;

	VAR
		Handle: SHORTINT;


	PROCEDURE InitVDI;
		TYPE
			tIn = ARRAY [0..10] OF SHORTINT;
		VAR
			dmy: SHORTINT;
			In : tIn;
			Out : ARRAY[0..127] OF SHORTINT;
	BEGIN
		Handle := graf.handle (dmy, dmy, dmy, dmy);
		In := tIn{1 BY 10, 2};
		v.opnvwk (In, Handle, Out);
		v.hidec (Handle);
		v.clrwk (Handle);
	END InitVDI;


	PROCEDURE ExitVDI;
	BEGIN
		v.showc (Handle, FALSE);
		v.clsvwk(Handle);
	END ExitVDI;


	PROCEDURE Draw (Realmin, Realmax, Imagmin, Imagmax: LONGREAL; Maxzahl: CARDINAL);
		TYPE
			tPoint = ARRAY [0..0] OF VDI.tPoint;
		VAR
			Realdelta, Imagdelta: LONGREAL;
			Realconst, Imagconst: LONGREAL;
			Realzahl, Imagzahl: LONGREAL;
			Realquad, Imagquad: LONGREAL;
			Xkoor, Ykoor, Zaehler: SHORTCARD;
			Point: tPoint;
	BEGIN
		Realdelta := (Realmax-Realmin)/FLOAT (Xreso);
		Imagdelta := (Imagmax-Imagmin)/FLOAT (Yreso);
		Imagconst := Imagmin + Imagdelta;

		FOR Ykoor := 0 TO Yreso DO
			Imagconst := Imagconst + Imagdelta;
			Realconst := Realmin - Realdelta;
			FOR Xkoor := 0 TO Xreso DO
				Realconst := Realconst + Realdelta;
				Realzahl := Realconst;
				Imagzahl := Imagconst;
				Zaehler := Maxzahl;
				LOOP
					Realquad := Realzahl * Realzahl;
					Imagquad := Imagzahl * Imagzahl;
					IF Realquad + Imagquad > 4.0 THEN EXIT END;
					Imagzahl := Realzahl * Imagzahl * 2.0 + Imagconst;
					Realzahl := Realquad - Imagquad + Realconst;
					Zaehler := Zaehler - 1;
					IF Zaehler = 0 THEN EXIT END;
				END;
				IF (Zaehler MOD 2) = 0 THEN
					Point := tPoint{{Xkoor, Ykoor}};
					v.pmarker (Handle, 1, Point);
				END;
			END;
		END;
	END Draw;

BEGIN
	IF appl.init () >= 0 THEN
		InitVDI;
		Draw (-2.0, 1.2, -1.25, 1.25, 23);
		ExitVDI;
		appl.exit
	END;
END Fractal. 
		
	
	