
Automatic Pattern Design
Automatic Pattern Design
You can use Automatic Pattern Design to animate a Section, Background, etc. and create user attractive UI components.
So if you are a person who wishes to develop a website, you have to know how to create 3D animations properly. Check out our tutorial and you can learn this techniques and use it on your web development. Below sections shows how to develop this animations.
How to create Automatic Pattern Design? We are here to solve your problem. In this article we discuss how to create a hover effect animations. Before we start please read the below articles which easier you to understand the process, if you are new to development.
Step 1 – Add HTML
It’s too easy and simple. Just copy and paste below code in your HTML editor between <body> </body> tag as below.
<body>
<canvas id="fractal" width="400" height="400"></canvas>
<canvas id="circles" width="400" height="400"></canvas>
<div id="sliders">
<h1>Sizes</h1>
<div id="slider1"><input type="checkbox" id="cb1"></input></div>
<div id="slider2"><input type="checkbox" id="cb2"></input></div>
<div id="slider3"><input type="checkbox" id="cb3"></input></div>
<div id="slider4"><input type="checkbox" id="cb4"></input></div>
<div id="slider5"><input type="checkbox" id="cb5"></input></div>
<div id="slider6"><input type="checkbox" id="cb6" checked></input></div>
</div>
<div id="speeds">
<h1>Speeds</h1>
<div id="speed1"></div>
<div id="speed2"></div>
<div id="speed3"></div>
<div id="speed4"></div>
<div id="speed5"></div>
<div id="speed6"></div>
</div>
</body>
Step 2 – Add CSS
Copy and paste below code in your HTML editor between <style></style> tag as below.
<style>
body {
background: #000;
}
canvas {
position: absolute;
top: 0px;
left: 0px;
}
h1 {
font-family: Verdana;
font-size: 20px;
font-weight: bold;
color: #fff;
}
#sliders {
position: absolute;
top: 0px;
right: 0px;
bottom: 20px;
width: 24%;
}
#speeds {
position: absolute;
top: 0;
right: 25%;
bottom: 20px;
width: 24%;
}
#sliders>div {
position: relative;
height: 100%;
float: left;
}
.ui-slider {
margin: 15px;
float: left;
height: 80%;
}
input {
position: absolute;
bottom: 3px;
left: 14px;
}
</style>
At the end we will have something like this. You can change fonts, colors, backgrounds and all things that you want. Enjoy it.
Step 3 – Add JavaScript
We use some external JS links to this code. No need to worry about this, copy and paste code between <script></script> tags as below.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js" crossorigin="anonymous"></script>
Copy and paste below code in your HTML editor between <script></script> tag.
<script>
var radii = [1, 1 / 3, 1 / 3, 1 / 3, 1 / 3, 1 / 3, 1 / 3],
speeds = [
-Math.PI / 300,
(3 * Math.PI) / 300,
(9 * -Math.PI) / 300,
(27 * Math.PI) / 300,
(81 * -Math.PI) / 300,
(81 * 3 * Math.PI) / 300
],
toDraw = [0, 0, 0, 0, 0, 1];
$(function() {
$("#sliders div").each(function(ix, div) {
function onChange(ev, ui) {
radii[ix + 1] = ui.value / 100;
}
$("<div></div>")
.appendTo(div)
.slider({
orientation: "vertical",
animate: true,
value: 100 * radii[ix + 1],
slide: onChange,
change: onChange,
step: 0.01
});
$(div)
.find("input")
.on("change", function() {
toDraw[ix] = !!this.checked;
});
});
$("#speeds div").each(function(ix, div) {
function onSpeed(ev, ui) {
speeds[ix] = 5 * (ui.value / 100 - 0.5);
}
$(div).slider({
orientation: "vertical",
animate: true,
value: 50 + (100 * speeds[ix]) / 5,
slide: onSpeed,
change: onSpeed,
step: 0.01
});
});
});
var fractal = document.getElementById("fractal"),
circles = document.getElementById("circles"),
fCtx = fractal.getContext("2d"),
cCtx = circles.getContext("2d"),
width = circles.width,
height = circles.height,
rotate = [0, 0, 0, 0, 0, 0, 0],
pX = 0,
pY = 0,
rCount = 0,
r = 255,
g = 255,
b = 0,
rD = -5,
gD = -5,
bD = 5;
fCtx.strokeStyle = "#99FFFF";
fCtx.fillStyle = "rgba( 0, 0, 0, .05 )";
fCtx.lineWidth = 2;
cCtx.strokeStyle = "#FFFFFF";
cCtx.lineWidth = 2;
window.requestAnimFrame = (function() {
return (
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
}
);
})();
(function animloop() {
requestAnimFrame(animloop);
render();
})();
function render() {
var x = width / 2,
y = height / 2,
r = Math.min(width, height) / 2,
r2;
// change stroke color
b += bD;
if (!b || 255 === b) {
bD *= -1;
g += gD;
if (!g || 255 === g) {
gD *= -1;
r += rD;
if (!r || 255 === r) {
rD *= -1;
}
}
}
fCtx.strokeStyle =
"#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).substr(1);
// partially erase the line
if (!(++rCount % 20)) {
fCtx.fillRect(0, 0, width, height);
}
// clear the circles
cCtx.clearRect(0, 0, width, height);
// draw one circle
function drawCircle(ix) {
cCtx.beginPath();
cCtx.arc(x, y, r, 0, 2 * Math.PI, false);
cCtx.stroke();
if (toDraw[ix - 1]) {
fCtx.beginPath();
if (pX || pY) {
fCtx.moveTo(pX, pY);
fCtx.lineTo(x, y);
fCtx.stroke();
}
pX = x;
pY = y;
}
}
// draw the circles
for (var i = 0, l = rotate.length; i < l; i++) {
drawCircle(i);
r2 = r * radii[i + 1]; // shrink each circle
rotate[i] += 0.1 * speeds[i] * 10;
x += (r - r2) * Math.cos(rotate[i]);
y += (r - r2) * Math.sin(rotate[i]);
r = r2;
}
}
</script>
Out Put

Video Tutorial
Please watch this video to better understand this tutorial and don’t forget to subscribe to our channel.
Help others to find out about this article on Social Media sites. If you have any doubt or any problem, don’t hesitate to contact us. Thereafter we will be able to help you and also make sure you bookmark our site on your browser.