When writing an answer to the recent question Prolog Constraint Processing : Packing Squares I wanted to visualize the answers that Prolog + clpfd gave me.
To do that I wrote some dirty Prolog code for emitting suitable ImageMagick commands by using Prolog builtin "predicates" format/2
and write/1
, like so:
drawBoxesWithIM_at_pix(Sizes,Positions,P) :-
Colors = ["#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff"],
write(' -strokewidth 2 -stroke white'),
nth1(N,Positions,Xb+Yb),
nth1(N,Sizes, Wb*Hb),
nth1(N,Colors, Color),
format(' -draw "fill ~sb0 roundrectangle ~d,~d ~d,~d ~d,~d"',
[Color, Xb*P+3,Yb*P+3, (Xb+Wb)*P-3,(Yb+Hb)*P-3, P/2,P/2]),
false.
drawBoxesWithIM_at_pix(_,_,_).
The quick hack worked well, however I feel the code I wrote feels bloated and somewhat dirty... I would like to find a more declarative alternative for doing 2D visualizations like these. I feel like SVG could be a good choice.
Now, SVG is based on XML and several Prolog systems offer libraries for handling XML as a part of their standard libraries.
Are there Prolog libraries for SVG? Or other suitable 2D/(3D) data-visualization frameworks/tools with Prolog bindings?
What reasonable approaches do you see? Thank you in advance!