w3tweaks.com
  • Effects
    • Scroll Effects
    • Text Effects
    • Shadow
  • Essentials
    • Arrows
    • Buttons
    • Background Patterns
    • Border Examples
    • Cards
    • Color Palettes
    • Dividers
    • Link styles
    • Loaders
    • Modal Windows
    • Notifications
    • Progress bar
    • Quote styles
    • Spinner
    • Tooltips
  • Media
    • Calendars
    • Carousels
    • Clocks
    • Gallery
    • Music Players
    • Sliders
    • Slideshows
    • Tables
    • Thumbnails
  • Navigation
  • Inputs
    • Range Sliders
    • Checkboxes
    • Toggle Switches
  • Scripts
    • Angularjs
    • Backbone.js
    • bootstrap
    • jQuery
    • ReactJs
    • JavaScript
    • Syntax Highlighters
    • tryit editor
    • PHP
  • API’s
    • Facebook
    • Google
    • Indeed
    • Twitter
    • YouTube
  • Tools
w3tweaks.com
  • Effects
    • Scroll Effects
    • Text Effects
    • Shadow
  • Essentials
    • Arrows
    • Buttons
    • Background Patterns
    • Border Examples
    • Cards
    • Color Palettes
    • Dividers
    • Link styles
    • Loaders
    • Modal Windows
    • Notifications
    • Progress bar
    • Quote styles
    • Spinner
    • Tooltips
  • Media
    • Calendars
    • Carousels
    • Clocks
    • Gallery
    • Music Players
    • Sliders
    • Slideshows
    • Tables
    • Thumbnails
  • Navigation
  • Inputs
    • Range Sliders
    • Checkboxes
    • Toggle Switches
  • Scripts
    • Angularjs
    • Backbone.js
    • bootstrap
    • jQuery
    • ReactJs
    • JavaScript
    • Syntax Highlighters
    • tryit editor
    • PHP
  • API’s
    • Facebook
    • Google
    • Indeed
    • Twitter
    • YouTube
  • Tools
w3tweaks.com
Home CSS Code Demos

Moving Snakes Using HTML5 Canvas

W3TWEAKS by W3TWEAKS
September 18, 2019
in CSS Code Demos

Experiment with HTML5 Canvas Particles to create a beautiful Moving Snakes effects with Particle Trails.

Demo Download

AuthorNitish Khagwal
Official Page:Go to website
CreatedAUGUST 23, 2018
LicenseOpen
Compatible browsersChrome, Firefox, Opera, Safari

HTML Snippet

You might also like

CSS Shapes Forest Collection Spring Summer 2020

CSS Shapes Forest Collection Spring Summer 2020

October 11, 2020
CSS Button Concept for Remove and Success

CSS Button Concept for Remove and Success

August 21, 2019
<h1><span>W3</span> <span>Tweaks</span></h1>

CSS Code

::selection {   background-color: #ffffff;   color: #000000; } body {   margin: 0;   font-family: "Righteous", sans-serif;   background-color: #06094a; } h1 {   color: #ffffff;   text-transform: uppercase;   font-size: 72px;   text-align: center;   position: fixed;   z-index: 500;   left: 0;   right: 0;   top: 50%;   margin: -36px 0 0 0;   padding: 0;   line-height: 0.9;   mix-blend-mode: exclusion; } h1 span:nth-child(1) {   color: #ff3939; } h1 span:nth-child(2) {   color: #badcff; } @media screen and (max-width: 568px) {   h1 {     margin: -64px 0 0 0;   } }

JavaScript

//Globals var vWidth = window.innerWidth; var vHeight = window.innerHeight; var cns = document.createElement("canvas"); cns.width = vWidth; cns.height = vHeight; document.body.appendChild(cns); var ctx = cns.getContext("2d"); ctx.fillStyle = "rgba(6,9,74,1)"; ctx.fillRect(0, 0, vWidth, vHeight);  //Particles var particles = new Array(); var Particle = function() {   this.x =     Math.round(Math.random() * vWidth) - Math.round(Math.random() * vWidth);   this.y =     Math.round(Math.random() * vHeight) - Math.round(Math.random() * vHeight);   this.hue =     "#" +     Math.random()       .toString(16)       .substr(2, 6);   this.directionX = "left";   this.directionY = "bottom"; }; for (var i = 0; i < 1000; i++) {   particles[i] = new Particle(); }  //Paint var paint = param => {   ctx.beginPath();   ctx.lineWidth = "2";   ctx.strokeStyle = particles[param].hue;   ctx.moveTo(particles[param].x, particles[param].y);   if (particles[param].directionY == "bottom") {     particles[param].y = particles[param].y + Math.round(Math.random() * 2);     if (particles[param].y > vHeight) {       particles[param].directionY = "top";     }   }   if (particles[param].directionY == "top") {     particles[param].y = particles[param].y - Math.round(Math.random() * 2);     if (particles[param].y < 0) {       particles[param].directionY = "bottom";     }   }    if (particles[param].directionX == "left") {     particles[param].x = particles[param].x + Math.round(Math.random() * 2);     if (particles[param].x > vWidth) {       particles[param].directionX = "right";     }   }   if (particles[param].directionX == "right") {     particles[param].x = particles[param].x - Math.round(Math.random() * 2);     if (particles[param].x < 0) {       particles[param].directionX = "left";     }   }    ctx.lineTo(particles[param].x, particles[param].y);   ctx.closePath;   ctx.stroke(); };  // Frames var frame = () => {   ctx.fillStyle = "rgba(6,9,74,.20)";   ctx.fillRect(0, 0, vWidth, vHeight);   for (var j = 0; j < 1000; j++) {     paint(j);   }   window.requestAnimationFrame(frame); }; window.requestAnimationFrame(frame);

Preview

See the Pen Moving Snakes by Nitish Khagwal (@nitishkmrk) on CodePen.

Tags: animationanimation examplesbackgroundCanvaseffectshtml5MovingSnakes
Previous Post

Fancy Checkboxes and Radio Buttons with Font Awesome

Next Post

Triangle Loading Animation

W3TWEAKS

W3TWEAKS

Since I've had a strong background in front-end development, I took the initiative to start my own website (w3tweaks.com) to share my knowledge with the world.

Related Stories

CSS Shapes Forest Collection Spring Summer 2020

CSS Shapes Forest Collection Spring Summer 2020

by W3TWEAKS
October 11, 2020

Paulina Hetman crafts a forest full of one-div CSS shapes. Click the button to assemble them into a scene! See...

CSS Button Concept for Remove and Success

CSS Button Concept for Remove and Success

by W3TWEAKS
August 21, 2019

A cool little css Button concept for delete success with hover animation with close/delete icon and developed using CSS, HTML...

Three Pure different CSS Button effects

Three Pure different CSS Button effects

by W3TWEAKS
September 25, 2019

Three Pure CSS Button effects like tap, hover and click effects developed using CSS and HTML. Demo and Download available....

Easy customizable simple CSS buttons

Easy customizable simple CSS buttons

by W3TWEAKS
September 8, 2019

A series of simple CSS buttons. They are easy to customize and use. Can easily be integrated with Font-Awesome or...

Next Post
Triangle Loading Animation

Triangle Loading Animation

Discussion about this post

Popular Posts

100 Creative CSS Cards

41 Multi step HTML forms

13 Free HTML & CSS Dashboard Template Designs

20 HTML & CSS pricing tables

49 CSS Tables

14 Best CSS Dark Mode

11 CSS Shopping Cart UI/UX

42 Cool CSS Avatars For Better UI

89 Best CSS Toggle Switches

55 Useful handpicked CSS Buttons with examples and demos

w3tweaks

We bring you the best frontend collections that will fix perfect for news, magazine, personal blog, etc. Check our landing page for details.

  • Effects
    • Scroll Effects
    • Text Effects
    • Shadow
  • Essentials
    • Arrows
    • Buttons
    • Background Patterns
    • Border Examples
    • Cards
    • Color Palettes
    • Dividers
    • Link styles
    • Loaders
    • Modal Windows
    • Notifications
    • Progress bar
    • Quote styles
    • Spinner
    • Tooltips
  • Media
    • Calendars
    • Carousels
    • Clocks
    • Gallery
    • Music Players
    • Sliders
    • Slideshows
    • Tables
    • Thumbnails
  • Navigation
  • Inputs
    • Range Sliders
    • Checkboxes
    • Toggle Switches
  • Scripts
    • Angularjs
    • Backbone.js
    • bootstrap
    • jQuery
    • ReactJs
    • JavaScript
    • Syntax Highlighters
    • tryit editor
    • PHP
  • API’s
    • Facebook
    • Google
    • Indeed
    • Twitter
    • YouTube
  • Tools