Wavy Road with Dashes
How do I make an wavy road with dashes?
How to animate a freeway from the vantage point of a bird in Two.js. What is a wavy road with dashes? How do you make a wavy road with dashes? This script and codes were developed by Jono Brandel on 09 November 2022, Wednesday.
Wavy Road with Dashes - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Wavy Road with Dashes</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='https://jonobr1.github.com/two.js/third-party/two.js'></script> <script src="js/index.js"></script>
</body>
</html>
Wavy Road with Dashes - Script Codes CSS Codes
body { background: yellowgreen;
}
Wavy Road with Dashes - Script Codes JS Codes
// Asked by @jrf0110
// https://github.com/jonobr1/two.js/issues/120
var two = new Two({ type: Two.Types.canvas, fullscreen: true, autostart: true
}).appendTo(document.body);
/** * Create the road, this is the reference for the dashed lines */
var amount = 32;
var points = [];
for (var i = 0; i < amount; i++) { var pct = i / (amount - 1); var theta = Math.PI * 2 * pct; var x = two.width / 20 * Math.cos(theta); var y = pct * two.height * 2 - two.height * 0.5; points.push(new Two.Anchor(x, y));
}
var sidewalk = two.makeCurve(points, true);
sidewalk.translation.set(two.width / 2, two.height/ 2);
sidewalk.noFill().stroke = '#ccc';
sidewalk.linewidth = two.width / 4;
var road = two.makeCurve(points, true);
road.translation.set(two.width / 2, two.height / 2);
road.noFill().stroke = '#666';
road.linewidth = two.width / 6;
/** * Create an array of lines that will be our dashed line. */
var dashes = [];
for (var j = 0; j < 10; j++) { var gutter = - 10; var length = two.height / (amount + gutter); var dash = two.makeLine(0, - length, 0, length); dash.noFill().stroke = '#fff'; dash.linewidth = 3; dash.pct = j / (10 - 1); dash.translation.copy(points[j]).addSelf(road.translation); dashes.push(dash);
}
// Cached variables to use within the animation loop.
var a = new Two.Vector(), b = new Two.Vector();
var velocity = 0.0125;
two.bind('update', function(frameCount, timeDelta) { if (!timeDelta) { return; } for (var i = 0; i < amount; i++) { // Animate the road. var v = points[i]; var pct = i / (amount - 1) var offset = pct * Math.PI * 2; var theta = offset + frameCount / 20; v.x = two.width / 20 * Math.cos(theta); var length = dashes.length; if (i > length - 1) { continue; } // Animate the dashes. var dash = dashes[i]; // Assign the calculation of the vector on the road to `a` road.getPointAt(dash.pct, a); // Get an arbitrary vector right behind `a` in order to get the // angle for the rotation of the dash. road.getPointAt(dash.pct - 0.01, b); dash.translation.copy(a).addSelf(road.translation); dash.rotation = Two.Utils.angleBetween(a, b) + Math.PI / 2; dash.pct = mod(dash.pct + velocity, 1); }
});
// Add some mouse interaction
window.addEventListener('mousemove', function(e) { var pct = (e.clientY / window.innerHeight - 0.5) * 2; velocity = pct * 0.03;
}, false);
window.addEventListener('toushmove', function(e) { var touch = e.changedTouches[1]; if (!touch) { return; } var pct = (e.pageY / window.innerHeight - 0.5) * 2; velocity = pct * 0.03;
});
function mod(v, l) { while (v < 0) { v += l; } return v % l;
}
Developer | Jono Brandel |
Username | jonobr1 |
Uploaded | November 09, 2022 |
Rating | 4 |
Size | 2,679 Kb |
Views | 8,096 |
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 |
A Pen by Jono Brandel | 43,916 Kb |
Physics Springs with Two.js | 1,917 Kb |
Dispensary | 2,409 Kb |
USA | 2,007 Kb |
Two.js Rainbow | 1,912 Kb |
9 Squares r6 | 2,206 Kb |
Starfield | 1,689 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 |
JQuery Validate checkbox group | Lunaman | 2,466 Kb |
Text Blocks Over Image, Updated | KatieK2 | 3,122 Kb |
Text Looping Transition | Agelber | 5,619 Kb |
A Bouncy Menu Toggle | Billyysea | 4,563 Kb |
Commuter Line Tokyu 8500 | Pedox | 7,031 Kb |
Basecamp 3 Document | Lachlanjc | 3,811 Kb |
Drifting Clouds | Benedikte | 2,247 Kb |
MAD9013 - Float Images with Content | Mad-d | 2,220 Kb |
Animated Vertical CSS3 Menu Black | MaCeLMp4 | 2,750 Kb |
Fun form with currentColor | Bnthor | 2,713 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!