previous

page 3

next

Next we create a seed function which will randomly fill half the cells.
So we'll need my library yet again.

seed.js in functions.js
function seed() {
klear();
for (var i=0;i<1600;i++) {
if (Random(2)==1) g_squares[i]=1;
}
}

And here's index.html. Note the extra line at the bottom so we can test our work so far.

<html>
<head>
<title>Life</title>
<link rel='stylesheet' href='styles.css'>
<script src='library.js'></script>
<script src='squares.js'></script>
<script src='globals.js'></script>
<script src='functions.js'></script>
</head>
<body>
<script>squares(); klear(); draw();</script>
<script>seed(); draw();</script>
</body>
</html>
previous
next