Grid of Birds

Developer
Size
3,512 Kb
Views
8,096

How do I make an grid of birds?

Created by XORXOR, 2016 Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0). What is a grid of birds? How do you make a grid of birds? This script and codes were developed by XORXOR on 27 January 2023, Friday.

Grid of Birds Previews

Grid of Birds - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Grid of Birds</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <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> <script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/r79/three.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Grid of Birds - Script Codes CSS Codes

* {	margin: 0;	padding: 0;
}

Grid of Birds - Script Codes JS Codes

// 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;
}
Grid of Birds - Script Codes
Grid of Birds - Script Codes
Home Page Home
Developer XORXOR
Username xorxor_hu
Uploaded January 27, 2023
Rating 3.5
Size 3,512 Kb
Views 8,096
Do you need developer help for Grid of Birds?

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!

XORXOR (xorxor_hu) Script Codes
Create amazing captions 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!