Fractal trees <svg>

Developer
Size
2,416 Kb
Views
8,096

How do I make an fractal trees <svg>?

<svg> fractal trees rendered using different angles. What is a fractal trees <svg>? How do you make a fractal trees <svg>? This script and codes were developed by Mirjamsk on 26 January 2023, Thursday.

Fractal trees <svg> Previews

Fractal trees <svg> - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Fractal trees <svg></title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1500" height="320"> <defs id="defs"> <g id="stem"> <line x1="0" y1="0" x2="0" y2="-1"/> </g> <g id="0"><use xlink:href="#stem"/></g> </defs> <g transform="translate(130, 320) scale(100)"> <use id="15deg" xlink:href=""/> </g> <g transform="translate(440, 320) scale(95)"> <use id="25deg" xlink:href=""/> </g> <g transform="translate(800, 320) scale(90)"> <use id="35deg" xlink:href=""/> </g>
</svg> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Fractal trees <svg> - Script Codes CSS Codes

line { stroke: black; stroke-width: .06; }

Fractal trees <svg> - Script Codes JS Codes

var xlinkns = "http://www.w3.org/1999/xlink";
// makes SVG object <type>
function SVG(type){ return document.createElementNS('http://www.w3.org/2000/svg', type);
}
function makeTree(depth, angle, gId) { var defs	= document.getElementById("defs"); var prevId	= ''; var id	= ''; for (var i = 1; i <= depth; i++){	prevId = (i-1) + '_' + gId;	id = i + '_' + gId; var g = SVG("g");	g.setAttributeNS(null, "id", id);	defs.appendChild(g); var use1 = SVG("use");	use1.setAttributeNS(xlinkns, "xlink:href", "#"+ prevId);	use1.setAttributeNS(null, "transform", "translate(0, -1) rotate(-"+ angle +") scale(.7)"); var use2 = SVG("use");	use2.setAttributeNS(xlinkns, "xlink:href", "#"+ prevId);	use2.setAttributeNS(null, "transform","translate (0, -1) rotate(+"+ angle +") scale(.7)"); var use3 = SVG("use");	use3.setAttributeNS(xlinkns, "xlink:href", "#stem"); g.appendChild(use1); g.appendChild(use2); g.appendChild(use3);	}
}
function growTree(depth, uId){ var i = 0; var id = '' var intervalId = window.setInterval( function(){	id = i == 0 ? i : i + '_' + uId	document.getElementById(uId).setAttributeNS(xlinkns, "xlink:href", "#"+id);	if (++i > depth) clearInterval(intervalId) }, 120);
}
function getIDs(angles){	var IDs = []	for (var i in angles)	IDs.push(angles[i]+'deg')	return IDs
}
$(document).ready(function() {	var angles = [15, 25, 35];	var IDs = getIDs(angles);	var depth = 9;	for (var i in angles){	makeTree(depth, angles[i], IDs[i]);	growTree(depth, IDs[i]);	}
});
Fractal trees <svg> - Script Codes
Fractal trees <svg> - Script Codes
Home Page Home
Developer Mirjamsk
Username alojzije
Uploaded January 26, 2023
Rating 4
Size 2,416 Kb
Views 8,096
Do you need developer help for Fractal trees <svg>?

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!

Mirjamsk (alojzije) Script Codes
Create amazing sales emails 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!