Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body style=background-color:#333;overflow:hidden;margin:0>
<canvas id=a style=display:block;width:100vw;height:100vh>
<script>d=document;b=d.body;c=a.getContext('2d')</script>

              
            
!

CSS

              
                /* 
Game of Wolves, Sheeps and Grass
================================

1) a blank cell which is adjacent to grass will be replaced by grass 
2) a grass cell which is adjacent to a sheep will be replaced by a sheep
3) a sheep will be replaced by a wolf if a wolf is adjacent to it. 
4) if a sheep has no grass adjacent to it, it will be replaced by a blank cell
5) if a wolf has no sheep adjacent to it, it also will be replaced by a blank cell
6) if a wolf has a shepherd adjacent to it, it will be replaced by a blank cell
7) In else cases, no replacement takes place.

*) Chances are, that the wolf/sheep isn't hungry, or the grass doesn't grow
*/
              
            
!

JS

              
                // Configuration: pick values between 0 and 1
grassGrowthRate=0.3
sheepHungriness=0.5
wolfHungriness =0.5
// ----- Sprite size: try 32, 64, 8, ...
spriteSize=96
//------
R=Math.random
w=a.width=2*1920
h=a.height=2*1024
W=w/spriteSize|0
H=h/spriteSize|0
for(M=[],m=W*H;m--;)M[m]=R()*4|0
M[(R()*H|0)*W+R()*W|0]=4
m=function(x,y){return y<0||x<0||x>=W||y>=H?0:M[y*W+x]}
N=function(x,y,z){
	return (m((x-1),(y-1))===z?1:0)+(m(x,(y-1))===z?1:0) 
         +(m((x+1),(y-1))===z?1:0)+(m((x-1),y)===z?1:0)
         +(m((x+1),y)===z?1:0)+(m((x-1),(y+1))===z?1:0)
         +(m(x,(y+1))===z?1:0)+(m((x+1),(y+1))===z?1:0)
}
P=function(x,y){
	if(m(x,y)==0&&N(x,y,1)&&R()<grassGrowthRate)return 1 // (1)
	if(m(x,y)==1&&N(x,y,2)>0&&R()<sheepHungriness)return 2 // (2)
	if(m(x,y)==2){ // (3) && (4)
		if(N(x,y,1)==0)return 0
		if(N(x,y,3)>0&&R()<wolfHungriness)return 3
	}
	if(m(x,y)==3)if(N(x,y,2)==0||N(x,y,4)>0)return 0 // (5) && (6)
	return m(x,y) // (7)
}
E=function(u,f,i,j,k){
	for(k=j=u.length;j--;)
		i=new Image(),
		i.src='https://assets-cdn.github.com/images/icons/emoji/unicode/1f4'+u[j]+'.png',
		i.onload=function(){if(!--k)f(u)},
		u[j]=i
}
E([11,'3a',68],function(I,i,k,x,y){
	G=document.createElement('canvas')
	G.width=G.height=64
	g=G.getContext('2d')
	g.fillStyle='rgba(0,255,0,0.02)'
	I.splice(0,0,new Image(spriteSize, spriteSize))
  I[0].src=G.toDataURL()
  for(i=5e3;i--;)g.fillRect(R()*spriteSize,R()*spriteSize,4,4)
	I.splice(1,0,new Image(spriteSize,spriteSize))
	I[1].src=G.toDataURL()
	function L(){
		c.fillStyle='rgba(51,51,51,0.9)'
		c.fillRect(0,0,w,h)
		for(y=H;y--;)
			for(x=W;x--;)
				c.drawImage(I[m(x,y)],x*spriteSize,y*spriteSize, spriteSize, spriteSize)
		window.setTimeout(function(){
			O=[]
			for(y=H;y--;)
				for(x=W;x--;)
					O[y*W+x]=P(x,y)
			M=O
			requestAnimationFrame(L)
		},100)
	}
  k=2,I[0].onload=I[1].onload=function(){if(!--k)L()}
})


              
            
!
999px

Console