Newton's Cradle
How do I make an newton's cradle?
First attempt at working with the Matter.js physics engine. What is a newton's cradle? How do you make a newton's cradle? This script and codes were developed by Dave Alger on 11 August 2022, Thursday.
Newton's Cradle - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Newton's Cradle</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div style="text-align:center"><div id="stage"></div></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.5.0-alpha/matter.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Newton's Cradle - Script Codes CSS Codes
*{ padding: 0; margin: 0; font-family: sans-serif; }
body { background: #222;
}
canvas:active { cursor: pointer; cursor: -webkit-grabbing;
}
#stage { margin: 12px; width: 100%;
}
Newton's Cradle - Script Codes JS Codes
(function() { this.Cradle = {}; var Engine = Matter.Engine, Gui = Matter.Gui, World = Matter.World, Bodies = Matter.Bodies, Body = Matter.Body, Composite = Matter.Composite, Composites = Matter.Composites, Common = Matter.Common, Constraint = Matter.Constraint; var _engine; Cradle.init = function() { var container = document.getElementById('stage'); // engine options - these are the defaults var options = { positionIterations: 5, velocityIterations: 3, enableSleeping: false, timeScale: 1 }; _engine = Engine.create(container, options); Engine.run(_engine); var _world = _engine.world; World.clear(_world); Engine.clear(_engine); _engine.enabled = true; _engine.enableSleeping = false; _engine.world.gravity.y = 1; var renderOptions = _engine.render.options; renderOptions.wireframes = true; renderOptions.showAxes = true; renderOptions.showPositions = true; var cradle = Composites.newtonsCradle(240, 10, 6, 30, 200); World.addComposite(_world, cradle); Body.translate(cradle.bodies[0], { x: -180, y: -100 }); }; if (window.addEventListener) { window.addEventListener('load', Cradle.init); } else if (window.attachEvent) { window.attachEvent('load', Cradle.init); }
})();
Developer | Dave Alger |
Username | run-time |
Uploaded | August 11, 2022 |
Rating | 4.5 |
Size | 2,236 Kb |
Views | 66,792 |
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 |
Fireflies | 2,940 Kb |
Simple Yin Yang | 5,396 Kb |
Chat Room Demo | 3,277 Kb |
ASCII Tree Logo | 4,202 Kb |
Catapult Game | 3,109 Kb |
Download Speed Calculator | 3,412 Kb |
Editable Fire Text | 3,997 Kb |
A Pen by Dave Alger | 272,032 Kb |
Basic FAQ | 2,365 Kb |
Color Picker | 3,410 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 |
AngularJS Datalist Directive | M-e-conroy | 2,366 Kb |
SVG Scalable Text | Said_FD | 1,451 Kb |
A Pen by Matt Popovich | Mpopv | 3,349 Kb |
BSP Dungeon Generation | Xgundam05 | 5,326 Kb |
Flat design iframe | Damienpm | 1,819 Kb |
AngularJS Animated Todo List | Ehaase | 2,975 Kb |
Starting out with Ember.JS | Cfleschhut | 4,808 Kb |
Barber Shop | Bhlaird | 6,270 Kb |
Social Profiles | Lachlanjc | 1,939 Kb |
Scroll to top button | DominicFrancois | 3,743 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!