-
Notifications
You must be signed in to change notification settings - Fork 0
/
colours_to_image.pl
51 lines (39 loc) · 1.51 KB
/
colours_to_image.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
% realism, ironism
% creates an image from names of colours
% [[white,white,red,white,white],[white,red,yellow,red,white],[red,yellow,blue,yellow,red],[white,red,yellow,red,white],[white,white,red,white,white]]
% [[red,white],[white,red]]
:-include('../listprologinterpreter/la_strings.pl').
%:-include('../listprologinterpreter/la_strings.pl').
colours_to_image :-
writeln("Enter pixel colours for image as e.g. \"[[red,yellow],[yellow,red]]\"."),
read_string(user_input, "\n", "\r", _, Input),
term_to_atom(Grid,Input),
length(Grid,Y),
Grid=[Row|_],
length(Row,X),
findall(Pixel_RGB2,(member(Line,Grid),findall([R," ",G," ",B,"\n"],(member(Pixel_colour,Line),colour(Pixel_colour,[R,G,B])),Pixel_RGB2)),Grid2),
%trace,
%writeln1(Grid31),
maplist(append,[Grid2],[Grid32]),
maplist(append,[Grid32],[Grid3]),
%maplist(append,[[Grid33]],[Grid34]),
%maplist(append,[[Grid34]],[Grid3]),
%trace,
maplist(append,[[["P3","\n",X," ",Y,"\n","255","\n"],Grid3,["\n"]]],[Grid31]),
concat_list(Grid31,Grid4),
writeln("Enter file name, ending with \".ppm\"."),
read_string(user_input, "\n", "\r", _, File),
%term_to_atom(Grid4,D85),
string_atom(D85,Grid4),
(open_s(File,write,Stream2),
write(Stream2,D85),
close(Stream2)),!.
colour(red, [255, 0, 0]).
colour(black, [0, 0, 0]).
colour(white, [255, 255, 255]).
colour(yellow, [255, 255, 0]).
colour(green, [0, 255, 0]).
colour(blue, [0, 0, 255]).
colour(purple, [128, 0, 128]).
colour(orange, [255, 128, 0]).
colour(brown, [128, 64, 0]).