Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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>
<script type="x-shader/x-vertex" id="birdVert">

            attribute float startFrameId;

            uniform float iGlobalTime;
            uniform vec2 iResolution;
            uniform vec2 iMouse;

            varying vec2 vUV;
            varying mat2 vUVRot;
            varying float vFrameId;

            void main()
            {
                vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );

                vec2 vel = 2.0 * ( iMouse / iResolution - vec2( 0.5 ) );
                vUV = vec2( vel.x * 0.5 + 0.5, vel.y * 0.5 + 0.5 );
                vUV = floor( vUV * 11.0 ) / 11.0;
                float gridRotation = atan( vUV.y - 0.5, vUV.x - 0.5 );
                vUV += 0.5 / 11.0;

                float rotation = atan( vel.y, vel.x ) - gridRotation;
                float s = sin( rotation );
                float c = cos( rotation );
                vUVRot = mat2( c, -s, s, c );

                gl_PointSize = 64.0;

                vFrameId = floor( mod( startFrameId + iGlobalTime, 9.0 ) );
                gl_Position = projectionMatrix * mvPosition;
            }
        </script>
 <script type="x-shader/x-fragment" id="birdFrag">
            uniform sampler2D texturesBird[ 9 ];

            varying vec2 vUV;
            varying mat2 vUVRot;
            varying vec2 vMouse;
            varying float vFrameId;

            void main()
            {
                vec2 uv = 0.9 * vec2( 1.0 / 11.0 ) * ( gl_PointCoord - 0.5 ) * vUVRot + vUV;
                int id = int( vFrameId );

                vec4 col;
                if ( id == 0 ) { col = texture2D( texturesBird[ 0 ], uv ); }
                else if ( id == 1 ) { col = texture2D( texturesBird[ 1 ], uv ); }
                else if ( id == 2 ) { col = texture2D( texturesBird[ 2 ], uv ); }
                else if ( id == 3 ) { col = texture2D( texturesBird[ 3 ], uv ); }
                else if ( id == 4 ) { col = texture2D( texturesBird[ 4 ], uv ); }
                else if ( id == 5 ) { col = texture2D( texturesBird[ 5 ], uv ); }
                else if ( id == 6 ) { col = texture2D( texturesBird[ 6 ], uv ); }
                else if ( id == 7 ) { col = texture2D( texturesBird[ 7 ], uv ); }
                else if ( id == 8 ) { col = texture2D( texturesBird[ 8 ], uv ); }

                gl_FragColor = col;
            }
        </script>
</body>
              
            
!

CSS

              
                * {
	margin: 0;
	padding: 0;
}
              
            
!

JS

              
                // Grid of Birds
//
// Created by XORXOR, 2016
// Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)

var renderer, camera, scene;

var birdTextures = [];
var uniforms;
var startTime;

init();

function init()
{
	var container = document.createElement( 'div' );
	document.body.appendChild( container );

	loader = new THREE.TextureLoader();
	birdTextures[ 0 ] = loader.load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/crow-00.png' );
	birdTextures[ 1 ] = loader.load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/crow-01.png' );
	birdTextures[ 2 ] = loader.load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/crow-02.png' );
	birdTextures[ 3 ] = loader.load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/crow-03.png' );
	birdTextures[ 4 ] = loader.load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/crow-04.png' );
	birdTextures[ 5 ] = loader.load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/crow-05.png' );
	birdTextures[ 6 ] = loader.load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/crow-06.png' );
	birdTextures[ 7 ] = loader.load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/crow-07.png' );
	birdTextures[ 8 ] = loader.load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/crow-08.png' );
	for ( var i = 0; i <= 8; i++ )
	{
		birdTextures[ i ].flipY = false;
	}

	startTime = Date.now();

	scene = new THREE.Scene();

	renderer = new THREE.WebGLRenderer( { antialias: true } );
	renderer.setSize( window.innerWidth, window.innerHeight );
	renderer.setClearColor( 0xffffff );
	container.appendChild( renderer.domElement );

	onWindowResize();

	window.addEventListener( 'resize', onWindowResize, false );
	window.addEventListener( 'mousemove', mouseMove );

	render();
}

function addBirds()
{
	var oldBirds = scene.getObjectByName( "birds" );
	scene.remove( oldBirds );

	var width = window.innerWidth;
	var height = window.innerHeight;

	var size = 64.0;
	var wNum = Math.floor( width / size ) + 1;
	var hNum = Math.floor( height / size ) + 1;

	var numBirds = wNum * hNum;

	geometry = new THREE.BufferGeometry();
	var positions = new Float32Array( numBirds * 3 );
	var startFrameIds = new Float32Array( numBirds );

	var yp = size * 0.5;
	for ( var y = 0, i = 0, i3 = 0; y < hNum; y++ )
	{
		var xp = size * 0.5;
		for ( var x = 0; x < wNum; x++, i++, i3 += 3 )
		{
			positions[ i3 + 0 ] = xp;
			positions[ i3 + 1 ] = yp;
			positions[ i3 + 2 ] = 0.0;
			startFrameIds[ i ] = ( x + y ) % 9.0;

			xp += size;
		}
		yp += size;
	}

	geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
	geometry.addAttribute( 'startFrameId', new THREE.BufferAttribute( startFrameIds, 1 ) );

	uniforms = { texturesBird: { value: birdTextures },
				 iGlobalTime: { type: "f", value: 0.0 },
				 iResolution: { type: "v2", value: new THREE.Vector2() },
				 iMouse: { type: "v2", value: new THREE.Vector2() } };

	var shaderMaterial = new THREE.ShaderMaterial(
		{
			uniforms: uniforms,
			vertexShader: document.getElementById( 'birdVert' ).textContent,
			fragmentShader: document.getElementById( 'birdFrag' ).textContent,
			depthTest: false,
			transparent: true
		} );

	particles = new THREE.Points( geometry, shaderMaterial );
	particles.name = "birds";
	scene.add( particles );
}

function render()
{
	var currentTime = Date.now();
	uniforms.iGlobalTime.value = ( currentTime - startTime ) * 0.01;

	requestAnimationFrame( render );
	renderer.render( scene, camera );
}

function onWindowResize()
{
	addBirds();

	uniforms.iResolution.value.x = window.innerWidth;
	uniforms.iResolution.value.y = window.innerHeight;

	camera = new THREE.OrthographicCamera( 0.0, window.innerWidth,
										   window.innerHeight, 0.0, 1.0, 1000.0 );
	camera.position.set( 0.0, 0.0, 5.0 );
	renderer.setSize( window.innerWidth, window.innerHeight );
}

function mouseMove( event )
{
	uniforms.iMouse.value.x = event.clientX;
	uniforms.iMouse.value.y = window.innerHeight - event.clientY;
}
              
            
!
999px

Console