Canvas Hero Prototype

Developer
Size
3,070 Kb
Views
20,240

How do I make an canvas hero prototype?

Cool canvas animation as the background for a hero image.. What is a canvas hero prototype? How do you make a canvas hero prototype? This script and codes were developed by Eli Fitch on 28 October 2022, Friday.

Canvas Hero Prototype Previews

Canvas Hero Prototype - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Canvas Hero Prototype</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="site-header">
<!-- <h1>We Know Amazing</h1> -->
</div>
<!-- <article>Content</article>
<article>Content</article>
<article>Content</article> --> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Canvas Hero Prototype - Script Codes CSS Codes

@import url(https://fonts.googleapis.com/css?family=Roboto:300,100);
body,html{ background: whitesmoke; height:100%; font-family: 'Roboto'; padding: 0; margin: 0;
}
.site-header{ height:100%; min-height: 400px; width: 100%; position: relative; overflow: hidden;
}
h1 {
margin: 0;
padding: 0;
line-height: 1;
font-size: 4em;
text-transform: uppercase;
font-weight: 100;
position: absolute;
top: 40%;
width: 9.2em;
text-align: center;
/* background-color: whitesmoke; */
z-index: 5;
left: 50%;
-webkit-transform: translateX(-50%);
}
canvas { /* -webkit-animation: float 8s ease-in-out forwards; */ position: absolute; left: 50%; -webkit-transform: translateX(-50%)translateZ(0); height: 50%;
}
@-webkit-keyframes float { 0% { -webkit-transform: translateX(-50%)translateZ(0)translateY(100%); } 100% { -webkit-transform: translateX(-50%)translateZ(0)translateY(50%); }
}
article { width: 100%; text-align: center; line-height: 400px; font-size: 2em; text-transform: uppercase;
}d6d6d6
article:nth-child(even){ background-color: #212121; color: white;
}
article:nth-child(even){ background-color: #d6d6d6; color: #212121;
}

Canvas Hero Prototype - Script Codes JS Codes

// Dots and lines
var header = $('.site-header'), canvas = $('<canvas></canvas>').appendTo(header)[0], ctx = canvas.getContext('2d'), //ctx = canvas.getContext('2d').scale(2,2), color = '#35BF26', idle = null, mousePosition; ctx.scale(2,2);
canvas.width = window.innerWidth * 2;
canvas.height = header.outerHeight() * 2;
canvas.style.width = window.innerWidth+"px";
canvas.style.height = header.outerHeight()+"px";
canvas.style.display = 'block';
ctx.fillStyle = color;
//ctx.lineWidth = .5;
ctx.lineWidth = 1.5;
ctx.strokeStyle = color;
var dotNum = Math.min((window.innerWidth/2),600);
console.log(dotNum)
var mousePosition = { x: 30 * canvas.width / 100, y: 30 * canvas.height / 100 }, //dots = { nb: 600, distance: 80, d_radius: 3000, array: [] };
dots = { nb: dotNum, distance: 80, d_radius: 3000, array: [] };
function Dot(){ this.x = Math.random() * canvas.width; this.y = Math.random() * canvas.height; this.vx = -.5 + Math.random(); this.vy = -.5 + Math.random(); this.radius = Math.random();
}
Dot.prototype = { create: function(){ ctx.beginPath(); ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false); ctx.fill(); }, animate: function(){ for(var i = 0, dot=false; i < dots.nb; i++){ dot = dots.array[i]; if(dot.y < 0 || dot.y > canvas.height){ dot.vx = dot.vx; dot.vy = - dot.vy; }else if(dot.x < 0 || dot.x > canvas.width){ dot.vx = - dot.vx; dot.vy = dot.vy; } dot.x += dot.vx; dot.y += dot.vy; } }, line: function(){ for(var i = 0; i < dots.nb; i++){ for(var j = 0; j < dots.nb; j++){ i_dot = dots.array[i]; j_dot = dots.array[j]; if((i_dot.x - j_dot.x) < dots.distance && (i_dot.y - j_dot.y) < dots.distance && (i_dot.x - j_dot.x) > - dots.distance && (i_dot.y - j_dot.y) > - dots.distance){ if((i_dot.x - mousePosition.x) < dots.d_radius && (i_dot.y - mousePosition.y) < dots.d_radius && (i_dot.x - mousePosition.x) > - dots.d_radius && (i_dot.y - mousePosition.y) > - dots.d_radius){ ctx.beginPath(); ctx.moveTo(i_dot.x, i_dot.y); ctx.lineTo(j_dot.x, j_dot.y); ctx.stroke(); ctx.closePath(); } } } } }
};
function createDots(){ ctx.clearRect(0, 0, canvas.width, canvas.height); for(var i = 0; i < dots.nb; i++){ dots.array.push(new Dot()); dot = dots.array[i]; dot.create(); } dot.line(); dot.animate();
}
idle = setInterval(createDots, 1000/30);
/*$(canvas).on('mousemove mouseleave', function(e){ if(e.type == 'mousemove'){ mousePosition.x = e.pageX; mousePosition.y = e.pageY; } if(e.type == 'mouseleave'){ mousePosition.x = canvas.width / 2; mousePosition.y = canvas.height / 2; }
});*/
//dat.gui library
Canvas Hero Prototype - Script Codes
Canvas Hero Prototype - Script Codes
Home Page Home
Developer Eli Fitch
Username elifitch
Uploaded October 28, 2022
Rating 3.5
Size 3,070 Kb
Views 20,240
Do you need developer help for Canvas Hero Prototype?

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!

Eli Fitch (elifitch) Script Codes
Create amazing art & images 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!