tag:blogger.com,1999:blog-699020937694156193.post8717818637166445154..comments2023-04-16T09:55:15.867-04:00Comments on Shiny Things: Erlang Boids Simulation DesignJim Menardhttp://www.blogger.com/profile/16242400565135394692noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-699020937694156193.post-52452474377209854172007-08-17T15:53:00.000-04:002007-08-17T15:53:00.000-04:00Tom, a boid is a record. The flock spawns multiple...Tom, a boid is a record. The flock spawns multiple boid processes, each of which receives a boid record with simple initialized values. The boid move/1 method can return a new record value (see the "after" clause below). Here are the boid module's make_boid/0 and run/1 methods (AARRGGHH; comments don't allow the pre tag):<BR/><BR/>make_boid() -><BR/> #boid{<BR/> position = [random:uniform(?WORLD_SIZE), <BR/> random:uniform(?WORLD_SIZE), <BR/> random:uniform(?WORLD_SIZE)]<BR/> }.<BR/><BR/>run(Boid) -><BR/> receive<BR/> {From, position_and_vector} -><BR/> #boid{position = P, vector = V} = Boid,<BR/> From ! {self(), [P, V]},<BR/> run(Boid);<BR/> cancel -><BR/> io:format("boid ~p cancelled~n", [self()]), % DEBUG<BR/> void<BR/> after <BR/> ?MOVE_FREQ_MSECS -><BR/>%% io:format("boid ~p moving~n", [self()]), % DEBUG<BR/> B = move(Boid),<BR/> draw(B),<BR/> run(B)<BR/> end.Jim Menardhttps://www.blogger.com/profile/16242400565135394692noreply@blogger.comtag:blogger.com,1999:blog-699020937694156193.post-44160670180506694262007-08-17T15:34:00.000-04:002007-08-17T15:34:00.000-04:00Jim, How do you keep track of each Boid's state? ...Jim, How do you keep track of each Boid's state? I am new to Erlang and this one has me stumped.<BR/><BR/>Thanks<BR/><BR/>TomAnonymousnoreply@blogger.com