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 |
Time is Money | 4,736 Kb |
Tape Cassette Icon - CSS Only | 6,789 Kb |
Mouse Trailing | 3,268 Kb |
CubeTronic | 3,716 Kb |
Logo Slider | 3,508 Kb |
Lego style loading text | 5,209 Kb |
Diagonal CSS Pattern | 1,790 Kb |
A Pen by John Urbank | 2,984 Kb |
Simple jQuery Slider | 2,874 Kb |
Traveling through Tron - Best viewed in Webkit | 3,195 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 |
Background-blend-mode Test | 0x04 | 4,744 Kb |
Animated Vertical CSS3 Menu Black | MaCeLMp4 | 2,750 Kb |
Image grid with captions | Mchernin34 | 2,222 Kb |
TigerWoods Freecodecamp Page | Baileytj | 2,869 Kb |
Button fills | Zubfatal | 5,205 Kb |
Dragonball Dragon Radar | DouglasGlover | 2,157 Kb |
Flexbox Grid - equal height | DaveOrDead | 2,855 Kb |
Weather App 2 | MightyJoeW | 2,877 Kb |
Mobile Nav Menu | AliKlein | 4,745 Kb |
C.Rowe Button | Brownerd | 2,473 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!