Tiling Subdivision
How do I make an tiling subdivision?
A little experiment ported from Flash (http://wonderfl.net/c/hkJh) and rebuilt from scratch.. What is a tiling subdivision? How do you make a tiling subdivision? This script and codes were developed by Francesco Trillini on 01 September 2022, Thursday.
Tiling Subdivision - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Tiling Subdivision</title> <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 { margin: 0px; overflow: hidden;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <body></body> <script src='http://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Tiling Subdivision - Script Codes CSS Codes
body { margin: 0px; overflow: hidden;
}
Tiling Subdivision - Script Codes JS Codes
/* * Copyright MIT © <2013> <Francesco Trillini> * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
var self = window;
;(function(self) { var canvas, context, map = [], emptyPos = 0, FPS = 60; // Dat GUI default values var randomness = 50, light = false, pause = reset = false; // RGB light var rgb = 0; /* * Settings. */ var Settings = function() { this.randomness = 50; this.light = false; this.pause = this.replay = this.reset = false; this.changeRandomness = function(value) { randomness = value; }; this.enableLight = function(value) { !light ? light = true : light = false; }; this.pause = function(value) { !pause ? pause = true : pause = false; }; this.reset = function(value) { onResize(); }; }; /* * Init. */ function init() { var settings = new Settings(); var GUI = new dat.GUI(); // Dat GUI main GUI.add(settings, 'randomness').min(1).max(50).onChange(settings.changeRandomness); GUI.add(settings, 'light').onChange(settings.enableLight); GUI.add(settings, 'pause'); GUI.add(settings, 'reset'); var body = document.querySelector('body'); canvas = document.createElement('canvas'); canvas.width = innerWidth; canvas.height = innerHeight; canvas.style.background = '-webkit-radial-gradient(#b2ffd6, #add8e6)'; canvas.style.background = '-moz-radial-gradient(#b2ffd6, #add8e6)'; canvas.style.background = '-ms-radial-gradient(#b2ffd6, #add8e6)'; canvas.style.background = '-o-radial-gradient(#b2ffd6, #add8e6)'; canvas.style.background = 'radial-gradient(#b2ffd6, #add8e6)'; canvas.style.position = 'absolute'; canvas.style.top = 0; canvas.style.bottom = 0; canvas.style.left = 0; canvas.style.right = 0; canvas.style.zIndex = -1; body.appendChild(canvas); // Browser supports canvas? if(!!(capable)) { context = canvas.getContext('2d'); window.onresize = onResize; subdivision(); } else { console.error("Sorry, your browser doesn't support canvas."); } } /* * Check if browser supports canvas element. */ function capable() { return canvas.getContext && canvas.getContext('2d'); } /* * On resize window event. */ function onResize() { map = [], emptyPos = 0, pause = false; canvas.width = window.innerWidth; canvas.height = window.innerHeight; } /* * Subdivision logic. */ function subdivision() { if(light) rgb += (255 - rgb) * 0.1; if(!light) rgb += (0 - rgb) * 0.02; if(!pause) { var geometry = Math.round(innerWidth / 9.75), position = -1, emptyWidth = 0; for(var index = emptyPos; index < emptyPos + 2000; index++) { // Initialize the map if(!map[index] && position === -1) { position = index; emptyWidth++; } else if(emptyWidth >= Math.round(randomness)) break; else if(!map[index] && !(index % geometry === 0 && index != emptyPos)) emptyWidth++; else if(position !== -1) break; } var width, height, currentPos; // Random blocks size width = parseInt(Math.random() * emptyWidth) + 1; height = parseInt(Math.random() * emptyWidth) + 1; currentPos = position; // Iterate over each block, and increase the position for(var y = 0; y < height; y++) { for(var x = 0; x < width; x++) { map[currentPos] = 1; currentPos++; } currentPos += geometry - width; } emptyPos = position + width; var x = position % geometry * 10; var y = position === 0 ? 0 : parseInt(position / geometry) * 10; // Reset automatically when it's out of screen y >= canvas.height ? onResize() : null; } // Render context.strokeStyle = 'rgb' + '(' + Math.round(rgb) + ', ' + Math.round(rgb) + ', ' + Math.round(rgb) + ')'; context.lineWidth = 2; context.rect(x, y, width * 10, height * 10); context.stroke(); requestAnimFrame(subdivision); } /* * Request new frame by Paul Irish. * 60 FPS. */ window.requestAnimFrame = (function() { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000 / FPS); }; })(); window.addEventListener ? window.addEventListener('load', init, false) : window.onload = init;
})(self);
Developer | Francesco Trillini |
Username | Francext |
Uploaded | September 01, 2022 |
Rating | 4 |
Size | 3,937 Kb |
Views | 32,384 |
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 |
TweetLove | 6,715 Kb |
Concentrics | 4,301 Kb |
Lines | 4,499 Kb |
Typo | 4,738 Kb |
Interactive Bezier Doodle | 4,749 Kb |
Abstract Audio Visualizer | 8,048 Kb |
Molecules | 4,760 Kb |
Spirograph | 3,893 Kb |
Music Player Concept | 381,176 Kb |
Waviness | 4,500 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 |
Custom checkbox example | Capelo | 3,495 Kb |
GrcJS | Vino6 | 2,047 Kb |
Background-blend-mode Test | 0x04 | 4,744 Kb |
Filtre ile Arama Kutusu - Search Box with Filter | AyhanALTINOK | 3,448 Kb |
Video Player Custom Controls | EleftheriaBatsou | 3,665 Kb |
Kudos Please | TimPietrusky | 6,624 Kb |
Pruebas de d3.js | Juanmanuelcarnerero | 2,485 Kb |
Sequence.js - Sliding Horizontal Parallax | Maheshc | 4,537 Kb |
Font stack | Adrianjacob | 1,868 Kb |
Cut and Paste Roll Link | BottomlineInteractive | 2,546 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!