Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ?-
- G_People := 200,
- G_Speed := 2,
- G_Ill := 100,
- G_X := 600,
- G_Y := 400,
- G_F := 50,
- array(x, G_People, 100),
- array(y, G_People, 100),
- array(xs, G_People, 100),
- array(ys, G_People, 100),
- array(ill, G_People, 0),
- init_people,
- ill(0) := 1,
- window(title("Pandemia"), size(G_X+2*G_F+20, G_Y+2*G_F+50),
- class(win_func), paint_indirectly).
- win_func(init):-
- G_Timer := set_timer(_, 0.1, time_func).
- win_func(paint):-
- pen(2, rgb(0,0,0)),
- line(G_F, G_F,
- G_F, G_Y+G_F,
- G_X+G_F, G_Y+G_F,
- G_X+G_F, G_F,
- G_F, G_F),
- for(I, 0, G_People-1),
- color(I, Color),
- pen(4, Color),
- line(x(I), y(I), x(I), y(I)),
- fail.
- time_func(end):-
- update_window(_),
- for(I, 0, G_People-1),
- x(I) := x(I) + xs(I),
- y(I) := y(I) + ys(I),
- correct(I),
- ill(I)>0,
- infect(I),
- fail.
- infect(I):-
- for(J, 0, G_People-1),
- x(I)=:=x(J),
- y(I)=:=y(J),
- ill(J):=1,
- fail.
- color(I, Color):-
- (ill(I)=:=0 ->
- Color := rgb(0,0,0)
- else (ill(I)=:= -1 ->
- Color := rgb(0,255,255)
- else
- Color := rgb(255,0,0)
- )).
- correct(I):-
- (x(I)<G_F -> x(I):= x(I) - xs(I), xs(I) := -1*xs(I)), fail.
- correct(I):-
- (y(I)<G_F -> y(I):= y(I) - ys(I), ys(I) := -1*ys(I)), fail.
- correct(I):-
- (x(I)>G_F+G_X -> x(I):= x(I) - xs(I), xs(I) := -1*xs(I)), fail.
- correct(I):-
- (y(I)>G_F+G_Y -> y(I):= y(I) - ys(I), ys(I) := -1*ys(I)).
- init_people:-
- for(I, 0, G_People-1),
- x(I) := G_F+random(G_X),
- y(I) := G_F+random(G_Y),
- init_speed(I),
- fail.
- init_people.
- init_speed(I):-
- xs(I) := random(2*G_Speed)-G_Speed,
- ys(I) := random(2*G_Speed)-G_Speed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement