Fur

Size
2,938 Kb
Views
6,072

How do I make an fur?

Some fun trying to make some hair with the canvas. Runs surprisingly well for how many it's drawing!. What is a fur? How do you make a fur? This script and codes were developed by Darryl Huffman on 07 January 2023, Saturday.

Fur Previews

Fur - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Fur</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
<script src='https://codepen.io/darrylhuffman/pen/zogYQW.js'></script> <script src="js/index.js"></script>
</body>
</html>

Fur - Script Codes CSS Codes

html, body { height: 100%; width: 100%; margin: 0px; padding: 0px; overflow: hidden; background-color: #a7e091;
}
html canvas, body canvas { position: absolute; top: 0px; bottom: 0px; left: 0px; right: 0px; width: 100%; height: 100%;
}

Fur - Script Codes JS Codes

var container = 'body';
var size = {	x: $(container).width(),	y: $(container).height()
};
var color = [157,208,136];
var resolution_scale = 1;
var bunchSize = 20;
var perlinSpread = 50;
var hairdist = 20;
var exS = 4;
var canvas = $('<canvas/>').attr({width: size.x * resolution_scale, height: size.y * resolution_scale}).appendTo(container), context = canvas.get(0).getContext("2d");
var startTime = new Date().getTime();
var currentTime = 0;
var wind = [];
function initWind(){	for(var x = 0; x <= size.x / bunchSize + exS; x++){	wind.push([]);	for(var y = 0; y <= size.y / bunchSize + exS; y++){	wind[x].push([]);	}	}
}
initWind();
function updateWind(){	for(var x = 0; x <= size.x / bunchSize + exS; x++){	for(var y = 0; y <= size.y / bunchSize + exS; y++){	wind[x][y] = noise.simplex3((currentTime + x) / perlinSpread, (currentTime + y) / perlinSpread, currentTime * 1.25);	}	}
}
var hairs = [];
var hair = function(position, shape, shade){	this.position = position;	this.drawShape = shape;	this.shade = shade;	this.draw = function(){	var windr = wind[Math.floor(this.position.x/bunchSize)][Math.floor(this.position.y/bunchSize)];	if(!windr){	windr = 0;	}	context.save();	context.translate((this.position.x - hairdist*2) * resolution_scale, (this.position.y - hairdist*2) * resolution_scale);	context.rotate(windr * (Math.PI/2));	this.light = Math.floor(40 * (1 + windr)) + this.shade;	this.drawShape(this.light);	context.restore();	}	this.id = hairs.length;	hairs.push(this);
}
window.requestFrame = (function(){	return window.requestAnimationFrame ||	window.webkitRequestAnimationFrame ||	window.mozRequestAnimationFrame ||	function( callback ){	window.setTimeout(callback, 1000 / 60);	};
})();
function hairShape(light){	context.fillStyle = 'rgb('+(color[0]+light)+','+(color[1]+light)+','+(color[2]+light)+')';	context.fillRect(0,80 * resolution_scale,2 * resolution_scale,-80 * resolution_scale);
}
for(var x = 0; x < size.x/hairdist + exS; x++){	for(var y = 0; y < size.y/hairdist + exS; y++){	new hair({x: x*hairdist+Math.floor(Math.random() * hairdist), y: y*hairdist+Math.floor(Math.random() * hairdist)}, hairShape, Math.floor(Math.random() * 30));	}
}
function render(){	var now = new Date().getTime();	currentTime = (now - startTime) / 10000;	context.clearRect(0,0,size.x * resolution_scale,size.y * resolution_scale);	updateWind();	for(var i = 0; i <= hairs.length; i++){	if(hairs[i]){	hairs[i].draw();	}	}	requestFrame(render);
}
render();
Fur - Script Codes
Fur - Script Codes
Home Page Home
Developer Darryl Huffman
Username darrylhuffman
Uploaded January 07, 2023
Rating 4.5
Size 2,938 Kb
Views 6,072
Do you need developer help for Fur?

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!

Darryl Huffman (darrylhuffman) Script Codes
Create amazing Facebook ads 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!