Image:
Author: swiss.assault Group: Default Filesize: 150.26 kB Date added: 2010-05-22 Rating: 6.5 Downloads: 730 Views: 1167 Comments: 4 Ratings: 4 Times favored: 0 Made with: Algodoo before v1.8.5 Tags:
|
Hi,
first, if you don't know Conway's "game of life" check out this page:
http://www.bitstorm.org/gameoflife/
Choose "Glider" from the drop down list there and press "next" several times.
Keys: [Enter] (don't hold it for too long!) to advance to the next generation.
If you want to make your own game of life scene, just delete the existing one and copy the living or dead cell from the left to generate a new matrix.
Make sure that no external laser is pointing towards the matrix.
How it works
Variables:
immortal = next state; true = alive, false = dead
collideWater = current state; true = alive, false = dead
friction = number of lasers that hit the block.
e.laser.color == [1, 1, 0, 1]: Yellow laser (always on)
e.laser.color == [0, 1, 0, 1]: Green laser (switched on by enter key)
color = [0, 1, 0, 0.5]: Cell is alive (green, transparent 50%)
color = [0, 0, 0, 1]: Cell is dead (black, opaque)
Code:
(e)=>{......e.laser.color == [0, 1, 0, 1] ? {
........................collideWater = immortal;
........................collideWater ? {
..............................color = [0, 1, 0, 0.5]
..........................................} : {
..............................color = [0, 0, 0, 1]
........................}
............} : {
........................e.laser.color == [1, 1, 0, 1] ? {
..............................friction = friction - 8;
..............................((friction == 2 && collideWater) || friction == 3) ? {
....................................immortal = true
..............................} : {
....................................immortal = false
..............................};
..............................friction = 0
........................} : {
..............................friction = friction + 1
........................}
............}
}
Explanation:
Check if laser color is yellow:
......Laser is yellow:
............- the current state (collideWater) is updated from the next state (immortal).
............- update the cell color depending on whether it is alive or not.
......Laser is not yellow: Check if the laser color is green:
............- Laser is green:
..................- substract 8 from number of lasers that hit the block because the 8 lasers that belong to the cell also hit the block.
..................- check the game of life rules:
........................- 2 lasers hit and cell is alive or 3 lasers hit:
..............................next state is 'alive'.
........................- else:
..............................next state is 'dead'.
............- Laser is not green: add 1 to the number of lasers that hit the block.
Greetings,
swiss |