0

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.

false
  • 10,264
  • 13
  • 101
  • 209
MirrorMan
  • 13
  • 3

1 Answers1

1

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)).
joel76
  • 5,565
  • 1
  • 18
  • 22
  • Yes, that seems to do it! Thank you, I'm neither experienced in Prolog nor in programming in general and wasn't aware of the 'maplist' command. I'm sure it will come in handy. :-) – MirrorMan Jul 10 '12 at 21:21