Infection

Post your nifty GP projects here!

Moderator: MSandro

Post Reply
bromagosa
Posts: 33
Joined: Sep 15th, '15, 07:11

Infection

Post by bromagosa » Sep 29th, '15, 09:41

Joan Güell, a coworker of mine here at the Citilab -who is a biologist-, has built a simple bacterial infection simulation in GP.

It's an example I love, we used to teach it in Scratch all the time because it can be improved a lot, and kids love adding features and "genetically modifying" bacteria!

* You can easily add resistance to bacteria by just counting how many times a particular bacteria has been infected and using that when deciding whether it should get infected upon contact with other infected bacteria.
* You can make bacteria breed on contact. If you've done the previous, it's fun to try different possible outcomes for offspring.
* You can graph the amount of ill/healthy/dead bacteria and see how initial conditions affect the population.
Attachments
infection.gpp
(9.96 KiB) Downloaded 300 times

mguzdial
Posts: 70
Joined: Sep 15th, '15, 11:21

Re: Infection

Post by mguzdial » Sep 29th, '15, 12:04

Super cool -- thanks for sharing it!

Question from someone still digging into GP: You trigger updates on receiving "step." How did you know that a "step" message is sent? Is there a list somewhere? I've seen "init" too, and "go," of course.

bromagosa
Posts: 33
Joined: Sep 15th, '15, 07:11

Re: Infection

Post by bromagosa » Sep 29th, '15, 13:08

Thanks, Mark!

The message is sent manually, you can broadcast any message with any arbitrary name by using the [broadcast [message] >] block, which is also variadic and allows you to send data along with the message name, or to specify who you send it to.

These are not like Smalltalk messages though, they are similar in that objects can handle them or ignore them, but they are not (usually) directed to a particular instance, but broadcast to the whole system instead and intercepted only by whoever needs to handle them.

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: Infection

Post by JohnM » Sep 29th, '15, 15:04

There are two special messages sent by GP itself:

go - broadcast when the "go" button is pressed
initialize - invoked on a newly created instance to allow it to initialize itself

Note that initialize is invoked synchronously to allow a new instance to finish initializing itself before it gets added to the stage. That means that an initialize script shouldn't contain a infinite loop or anything that takes a long time to run. See the Dots project for an example of using initialize.

mguzdial
Posts: 70
Joined: Sep 15th, '15, 11:21

Re: Infection

Post by mguzdial » Oct 4th, '15, 00:13

Thank you both! That helps a lot!

Post Reply