Phone Case Pattern Animation

Size
2,774 Kb
Views
26,312

How do I make an phone case pattern animation?

This animation is inspired by the phone case I bought today:. What is a phone case pattern animation? How do you make a phone case pattern animation? This script and codes were developed by Johan Karlsson on 30 October 2022, Sunday.

Phone Case Pattern Animation Previews

Phone Case Pattern Animation - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Phone Case Pattern Animation</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id="canvas"></canvas> <script src="js/index.js"></script>
</body>
</html>

Phone Case Pattern Animation - Script Codes CSS Codes

html, body { margin: 0;
}
canvas { display: block;
}

Phone Case Pattern Animation - Script Codes JS Codes

"use strict";
/* Johan Karlsson (DonKarlssonSan)
*/
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var width = canvas.width = window.innerWidth;
var height = canvas.height = window.innerHeight;
ctx.lineCap = "round";
ctx.lineWidth = 2;
var phi = 0;
var tick = 0;
function drawSection(x, y, angle, color) { ctx.save(); ctx.fillStyle = color; ctx.translate(x, y); ctx.rotate(angle + phi); ctx.beginPath(); ctx.moveTo(0, 0); ctx.lineTo(100, -57.8); ctx.lineTo(50, -87); ctx.lineTo(0, -58); ctx.lineTo(-50, -87); ctx.lineTo(-100, -57.8); ctx.lineTo(0, 0); ctx.stroke(); ctx.fill(); ctx.restore();
}
function drawOne(x, y) { drawSection(x, y, 0, "palegreen"); drawSection(x, y, 2 * Math.PI / 3, "pink"); drawSection(x, y, 4 * Math.PI / 3, "white");
}
function draw() { ctx.clearRect(0, 0, width, height); requestAnimationFrame(draw); var col = width / 300; var row = height / 150; for (var x = 0; x < col; x++) { for (var y = 0; y < row; y++) { drawOne(x * 300, y * 174); drawOne(x * 300 + 150, y * 174 + 88); } } phi = Math.cos(tick) * 1.051 * 3 + Math.PI; tick += 0.004;
}
draw();
Phone Case Pattern Animation - Script Codes
Phone Case Pattern Animation - Script Codes
Home Page Home
Developer Johan Karlsson
Username DonKarlssonSan
Uploaded October 30, 2022
Rating 4
Size 2,774 Kb
Views 26,312
Do you need developer help for Phone Case Pattern Animation?

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!

Johan Karlsson (DonKarlssonSan) Script Codes
Create amazing blog posts 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!