A Pen by Ilia

Developer
Size
2,567 Kb
Views
34,408

How do I make an a pen by ilia?

Attempting to code conway's game of life in javavscript and canvas.http://en.wikipedia.org/wiki/Conway's_Game_of_Life. What is a a pen by ilia? How do you make a a pen by ilia? This script and codes were developed by Ilia on 04 August 2022, Thursday.

A Pen by Ilia Previews

A Pen by Ilia - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>A Pen by Ilia</title> <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ body { background:#343536; padding:10px }
#canvas { display:block; margin:auto; background:#222 } </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <canvas id="canvas" width="480" height="360"></canvas> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

A Pen by Ilia - Script Codes CSS Codes

body { background:#343536; padding:10px }
#canvas { display:block; margin:auto; background:#222 }

A Pen by Ilia - Script Codes JS Codes

$(function() { var canvas = $('#canvas'), ctx = canvas[0].getContext('2d'), mod = 4, width = (canvas.attr('width') / mod), height = (canvas.attr('height') / mod), x, y, cells = new Array(width), liveColor = '#eee', deadColor = '#222', lifeCount = 1; // populate array w/ random live/dead cells for (x = 0; x < width; x++) { cells[x] = new Array(height); for (y = 0; y < height; y++) { var dead = Math.random() < .9; cells[x][y] = dead; ctx.fillStyle = dead ? deadColor : liveColor; ctx.fillRect(x*mod, y*mod, mod, mod); } } function lifeCycle() { for (x = 0; x < width; x++) { for (y = 0; y < height; y++) { var liveSiblings = numberOfLiveSiblings(x, y), alive = cells[x][y] ? liveSiblings == 2 || liveSiblings == 3 : liveSiblings == 3; cells[x][y] = alive; ctx.fillStyle = alive ? liveColor : deadColor; ctx.fillRect(x*mod, y*mod, mod, mod); } } lifeCount++; } function numberOfLiveSiblings(a, b) { var count = 0; /************************* a-1, b-1 | a, b-1 | a+1, b-1 a-1, b | | a+1, b a-1, b+1 | a, b+1 | a+1, b+1 *************************/ count += a-1 >= 0 && b-1 >= 0 && cells[a-1][b-1] ? 1 : 0; count += a-1 >= 0 && cells[a-1][b] ? 1 : 0; count += a-1 >= 0 && b+1 < height && cells[a-1][b+1] ? 1 : 0; count += b-1 >= 0 && cells[a][b-1] ? 1 : 0; count += b+1 < height && cells[a][b+1] ? 1 : 0; count += a+1 < width && b-1 >= 0 && cells[a+1][b-1] ? 1 : 0; count += a+1 < width && cells[a+1][b] ? 1 : 0; count += a+1 < width && b+1 < height && cells[a+1][b+1] ? 1 : 0; return count; } setInterval( lifeCycle, 200 );
});
A Pen by Ilia - Script Codes
A Pen by Ilia - Script Codes
Home Page Home
Developer Ilia
Username iliadraznin
Uploaded August 04, 2022
Rating 3
Size 2,567 Kb
Views 34,408
Do you need developer help for A Pen by Ilia?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Ilia (iliadraznin) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!