Search code examples
swi-prologxpce

Depicting a list of objects in XPCE


I want to make an animation in XPCE, consisting of an arbitrary number of moving circles. The circles are given in a Prolog list, containing for each circle its coordinates, radius, and colour. Hence, the list looks like this: [[[1,2],20,red],[[40,2],15,green],...] I can of course generate a circle, name it and colour it as follows:

new(@p,picture).
send(@p,display,new(@ci,circle(20)),point(1,2)).
send(@ci,fill_pattern,colour(red)).

But what do I do when I want to represent the whole list? I would somehow need dynamic names, but things like

send(@p,display,new(@X,circle(20)),point(1,2)).

where X is some identifier specified earlier are not accepted.


Solution

  • Something like that ?

    t1 :-
        L =  [[[1,2],20,red],[[40,2],15,green]] ,
         new(D,picture),
        maplist(my_display(D), L),
        send(D, open).
    
    my_display(D, [[X,Y], R, Colour]) :-
        new(C, circle(R)),
        send(C, fill_pattern, colour(Colour)),
        send(D, display, C, point(X,Y)).