Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.58 KB | None | 0 0
  1. ?-
  2.     G_People := 200,
  3.     G_Speed := 2,
  4.     G_Ill := 100,
  5.  
  6.     G_X := 600,
  7.     G_Y := 400,
  8.     G_F := 50,
  9.  
  10.     array(x, G_People, 100),
  11.     array(y, G_People, 100),
  12.     array(xs, G_People, 100),
  13.     array(ys, G_People, 100),
  14.     array(ill, G_People, 0),
  15.     init_people,
  16.     ill(0) := 1,
  17.  
  18.     window(title("Pandemia"), size(G_X+2*G_F+20, G_Y+2*G_F+50),
  19.           class(win_func), paint_indirectly).
  20.  
  21. win_func(init):-
  22.     G_Timer := set_timer(_, 0.1, time_func).
  23.  
  24. win_func(paint):-
  25.     pen(2, rgb(0,0,0)),
  26.     line(G_F, G_F,
  27.         G_F, G_Y+G_F,
  28.         G_X+G_F, G_Y+G_F,
  29.         G_X+G_F, G_F,
  30.         G_F, G_F),
  31.     for(I, 0, G_People-1),
  32.         color(I, Color),
  33.         pen(4, Color),
  34.         line(x(I), y(I), x(I), y(I)),
  35.     fail.
  36.  
  37. time_func(end):-
  38.     update_window(_),
  39.     for(I, 0, G_People-1),
  40.         x(I) := x(I) + xs(I),
  41.         y(I) := y(I) + ys(I),
  42.         correct(I),
  43.         ill(I)>0,
  44.             infect(I),
  45.     fail.
  46.  
  47. infect(I):-
  48.     for(J, 0, G_People-1),
  49.         x(I)=:=x(J),
  50.         y(I)=:=y(J),
  51.         ill(J):=1,
  52.     fail.
  53.  
  54. color(I, Color):-
  55.     (ill(I)=:=0 ->
  56.         Color := rgb(0,0,0)
  57.     else (ill(I)=:= -1 ->
  58.         Color := rgb(0,255,255)
  59.     else
  60.         Color := rgb(255,0,0)
  61.     )).
  62.  
  63. correct(I):-
  64.     (x(I)<G_F -> x(I):= x(I) - xs(I), xs(I) := -1*xs(I)), fail.
  65. correct(I):-
  66.     (y(I)<G_F -> y(I):= y(I) - ys(I), ys(I) := -1*ys(I)), fail.
  67. correct(I):-
  68.     (x(I)>G_F+G_X -> x(I):= x(I) - xs(I), xs(I) := -1*xs(I)), fail.
  69. correct(I):-
  70.     (y(I)>G_F+G_Y -> y(I):= y(I) - ys(I), ys(I) := -1*ys(I)).
  71.  
  72. init_people:-
  73.     for(I, 0, G_People-1),
  74.         x(I) := G_F+random(G_X),
  75.         y(I) := G_F+random(G_Y),
  76.     init_speed(I),
  77.     fail.
  78. init_people.
  79.  
  80. init_speed(I):-
  81.     xs(I) := random(2*G_Speed)-G_Speed,
  82.     ys(I) := random(2*G_Speed)-G_Speed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement