Canvas rotate

Developer
Size
1,880 Kb
Views
6,072

How do I make an canvas rotate?

What is a canvas rotate? How do you make a canvas rotate? This script and codes were developed by Anna on 01 December 2022, Thursday.

Canvas rotate Previews

Canvas rotate - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>canvas rotate</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id='canvas' width='500' height='500'></canvas> <script src="js/index.js"></script>
</body>
</html>

Canvas rotate - Script Codes CSS Codes

canvas { background: #ccc;
}

Canvas rotate - Script Codes JS Codes

window.onload = function(){ var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); // ctx.fillRect(0,0,100,100); // fillRect繪製後會自動加入beginPath ctx.rect(50,50,100,100); ctx.fill(); var num = 0; canvas.onclick = function(e){ var mx = e.layerX; var my = e.layerY; if( ctx.isPointInPath(mx,my) ) { setInterval(function(){ ctx.clearRect(0,0,500,500); num++; ctx.save(); ctx.beginPath(); ctx.translate(100,100); ctx.scale(Math.sin(num*Math.PI/180), Math.sin(num*Math.PI/180)); ctx.rotate(num*Math.PI/180); //繞著自己旋轉 ctx.translate(-50,-50); ctx.rect(0,0,100,100); ctx.fill(); ctx.restore(); },50) } }
}
Canvas rotate - Script Codes
Canvas rotate - Script Codes
Home Page Home
Developer Anna
Username AnnaLiu
Uploaded December 01, 2022
Rating 3
Size 1,880 Kb
Views 6,072
Do you need developer help for Canvas rotate?

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!

Anna (AnnaLiu) Script Codes
Name
Clock
Canvas bezia
Canvas
A Pen by Anna
Slider demo
Drag and drop
Canvas text
Pixi
Canvas animate
Demo
Create amazing video scripts 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!