A Pen by Ilia
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 - 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 );
});
Developer | Ilia |
Username | iliadraznin |
Uploaded | August 04, 2022 |
Rating | 3 |
Size | 2,567 Kb |
Views | 34,408 |
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!
Name | Size |
Dynamic SVG creation | 5,075 Kb |
Canvas drawing app | 5,828 Kb |
Map Controls | 3,721 Kb |
Reproducing content box from RSI | 2,998 Kb |
CSS3 Working Clock | 5,889 Kb |
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!
Name | Username | Size |
Improved Page Flipping Effect | Usaphp | 5,201 Kb |
JQuery AJAX reddit Exercise | Btholt | 1,777 Kb |
Calendar | Miroot | 2,033 Kb |
Atom | Bhlaird | 1,932 Kb |
IbrahimJabbari-Effect14 | Ibrahimjabbari | 1,919 Kb |
Spilled Paint | Darrylhuffman | 3,894 Kb |
A Different Type of Gallery | DonPage | 2,950 Kb |
Tile Animation Thing | Frxnz | 4,332 Kb |
Polo, the flying squirrel | Agbales | 2,445 Kb |
Personal Website Redesign v2.0 | DevItWithDavid | 5,168 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!