% -*- Prolog -*-
%
% Images from the GLog paper.
%
% $Id: image.pro,v 1.4 2002/03/10 13:33:02 peteg Exp $

:- op(450, xf,  flipped).
:- op(450, xf,  rotated).
:- op(475, xfx, ratio).
:- op(500, xfy, beside).
:- op(500, xfy, above).

%main :-
%	image(Image),
%	gplot(Image),
%	write("Press a key."), nl,
%	read(X),
%	fail.
%main.

draw :-
	image(Image),
	gplot(Image), !.

%draw :-
%	image(Image),
%	gplot(Image),
%	read(X),
%	fail.

image(Fish_cycle) :-
	Left_fish = [(1, 1) - (1/8, 3/5) - (1, 1/8) - (3/4, 0) - (1, 0),
		(1/8, 3/5) - (1, 4/5)],
	Right_fish = Left_fish flipped,
	Up_fish = Left_fish beside Right_fish,
	Side_fish = Up_fish rotated,

	U = Up_fish,
	L = Side_fish,
	D = L rotated,
	R = D rotated,
	matrix([[U, L, L],
	        [U,[], D],
		[R, R, D]], Fish_cycle).

matrix(LL, Mat) :-
	col(LL, M, Mat).

col([L], 1, P) :-
	row(L, N, P).
col([L|LL], M + 1, P above PP ratio 1 / M) :-
	row(L, N, P),
	col(LL, M, PP).

row([X], 1, X).
row([X|L], N + 1, X beside P ratio 1 / N) :-
	row(L, N, P).

image(Food_chain) :-
%	writerr("food chain"),
	Left_fish = [(1, 1) - (1/8, 3/5) - (1, 1/8) - (3/4, 0) - (1, 0),
		(1/8, 3/5) - (1, 4/5)],
	Right_fish = Left_fish flipped,
	Up_fish = Left_fish beside Right_fish,
	Side_fish = Up_fish rotated,

	Thin_fish = ([] beside Up_fish ratio 1/2) beside [] ratio 3,

	Food_chain = P above P,
	P = Food_chain beside Side_fish.


image(FishLimit) :-
	Left_fish = [(1, 1) - (1/8, 3/5) - (1, 1/8) - (3/4, 0) - (1, 0),
		(1/8, 3/5) - (1, 4/5)],
	Right_fish = Left_fish flipped,
	Up_fish = Left_fish beside Right_fish,
	Side_fish = Up_fish rotated,

	FishLimit = (FishLimit beside Side_fish)
                     above (FishLimit beside Side_fish).

%image(Image) :-
%	unify(S,
%		line(point(1/4, 1/4), point(1/4, 3/4), point(3/4, 3/4),
%		point(3/4, 1/4), point(1/4, 1/4))),
%	unify(Image, beside(S, S, 1/3)).

%image(Htree_line) :-
%	htree(line, Htree_line).

%htree(Tree, H) :-
%	element(Type, Width, P),
%	H = [P, S flipped beside S],
%	S = [] beside H rotated ratio Width.

%element(line, 0, (1/2, 1/2)-(1/2, 1)).

%%%%%%%%%%%%%%

% Build the database for the applet.
build :-
	serialize("image.ser").
