Basic motion with JavaScript
How do I make an basic motion with javascript?
The is an example of basic motion with JavaScript using Canvas. What is a basic motion with javascript? How do you make a basic motion with javascript? This script and codes were developed by John Urbank on 08 July 2022, Friday.
Basic motion with JavaScript - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Basic motion with JavaScript</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ canvas { background-color: #ccc; /* centers canvas element */ margin: 0 auto; display: block;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <canvas id="canvas"></canvas> <script src="js/index.js"></script>
</body>
</html>
Basic motion with JavaScript - Script Codes CSS Codes
canvas { background-color: #ccc; /* centers canvas element */ margin: 0 auto; display: block;
}
Basic motion with JavaScript - Script Codes JS Codes
/* SETUP CANVAS
----------------------------- */
var canvasElement = document.getElementById('canvas');
var c = canvasElement.getContext('2d');
canvasElement.width = 500;
canvasElement.height = 500;
/* DEFINE SQUARE
----------------------------- */
function square(x, y, size) { c.clearRect(0, 0, 500, 500); // Repaint each frame c.fillStyle = 'black'; c.fillRect(x, y, size, size); // x, y, height, width
}
/* RESETS SQUARE PAST CANVAS WIDTH
----------------------------- */
function checkEdges () { if (i > 500) { i = 0; }
};
/* DRAW (EACH FRAME)
----------------------------- */
var i = 0; // Incrementing value (represents time)
function draw() { checkEdges(i); square(i, 100, 50); i++;
}
/* SETUP ANIMATION
----------------------------- */
function run() { window.requestAnimationFrame(run); draw();
}
/* RUN ANIMATION
----------------------------- */
run();
Developer | John Urbank |
Username | jurbank |
Uploaded | July 08, 2022 |
Rating | 3 |
Size | 2,202 Kb |
Views | 36,432 |
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!
Name | Size |
Traveling through Tron - Best viewed in Webkit | 3,195 Kb |
Mouse Trailing | 3,268 Kb |
Simple jQuery Slider | 2,874 Kb |
Navicon - responsive nav pattern | 3,469 Kb |
CSS Loading Animation | 3,495 Kb |
String permutation | 2,875 Kb |
WebGL Minimalism | 2,940 Kb |
Canvas Geometry | 2,242 Kb |
Tape Cassette Icon - CSS Only | 6,789 Kb |
Diagonal CSS Pattern | 1,790 Kb |
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!
Name | Username | Size |
Out of the blue | Giaco | 2,537 Kb |
Client-side Email Validation | Collizo4sky | 1,538 Kb |
Responsive Table-less Shopping Cart | Alex_rodrigues | 6,637 Kb |
Expert Help | SinceSidSlid | 4,064 Kb |
A Pen by Mike Otis | Mikeotis | 3,185 Kb |
Slim Grid SASS SCSS v3.2 | Thesturs | 4,709 Kb |
FontAwesome icons with animation | Nicotinell | 2,083 Kb |
After America | Jonathangarner | 2,686 Kb |
Filter inputs | Rowinf | 1,721 Kb |
Bootstrap 3 Price Table | Honglio | 2,655 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!