_TITLE "Pandemic Sim & Particles Demo" 'OldMoses' mod of b+ mod Fellippe's 2020-07-23 ' ref 2020-07-22 https://www.qb64.org/forum/index.php?topic=2839.msg121033#msg121033
_DELAY .25 ' give time for screen to load
CONST objSize
= 5 'the size of all our objects is constant
x
AS SINGLE ' screen location x coordinate y
AS SINGLE ' screen location y coordinate xv
AS SINGLE ' velocity parallel to x axis, this is the x component of the movement vector yv
AS SINGLE ' velocity parallel to y axis, this is the y component of the movement vector state
AS _BYTE ' healthy = 1, infected = 2, 3 = immune
restart:
generate
infected
= _CEIL(RND * UBOUND(o
)) ' pick a random cell use _CEIL to round up, don't want 0 infectedo(infected).state = 2 ' infect it
move
spread
show
SUB generate
'individuals o(i).state = 1 'healthy
o
(i
).health
= INT(RND * 90) + 10 o(i).sick = 0
o(i).dead = 3
o(i).x = o(i).x + o(i).xv
IF o
(i
).x
< 0 OR o
(i
).x
> _WIDTH THEN o
(i
).xv
= o
(i
).xv
* -1 ' change direction when out of bounds o(i).y = o(i).y + o(i).yv
IF o
(i
).y
< 0 OR o
(i
).y
> _HEIGHT THEN o
(i
).yv
= o
(i
).yv
* -1 ' change direction when out of bounds virulence% = 90 ' INT(RND * 90) + 1
o(i).health = o(i).health - virulence%
IF virulence%
> o
(i
).health
THEN o
(i
).dead
= o
(i
).dead
- 1 o(i).sick = o(i).sick + 1
o(i).state = 3
FOR i
= 1 TO UBOUND(o
) - 1 ' compare every cell to every other if too close and infected then all around are IF _HYPOT(o
(j
).x
- o
(i
).x
, o
(j
).y
- o
(i
).y
) < objSize
* 2 THEN 'check distance 2 cells touching IF o
(i
).state
<> 3 OR o
(j
).state
<> 3 THEN IF o
(i
).state
= 2 OR o
(j
).state
= 2 THEN o
(i
).state
= 2: o
(j
).state
= 2 ' set both to infected ' note: just setting both states to infected is faster than ckecking and changing only the healthy
FOR r
= 0 TO objSize
STEP .25 'Ken's way to circle fill without extra subroutine CIRCLE (o
(i
).x
, o
(i
).y
), r
, c
(o
(i
).state
)