Device motion experiment
How do I make an device motion experiment?
Playing around with device motion events. Using angular and charts for graphing.. What is a device motion experiment? How do you make a device motion experiment? This script and codes were developed by Edward R Haase on 13 January 2023, Friday.
Device motion experiment - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Device motion experiment</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel='stylesheet prefetch' href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> div(ng-cloak, ng-app='app', ng-controller='MyCtrl') P This demo is unlikely to work on desktop browsers, even if device motion support is found. div(ng-hide='deviceMotion') Device motion is not supported. div(ng-show='deviceMotion') Device motion is supported! table tr td: strong Acceleration td {{evt.acceleration}} tr td: strong AccelerationIncludingGravity td {{evt.accelerationIncludingGravity}} tr td: strong bubbles td {{evt.bubbles}} {{points.length}} div.chart( ac-chart="'line'", ac-data='ad', ac-config='config') div.chart( ac-chart="'line'", ac-data='adig', ac-config='configInclG') <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.js'></script>
<script src='http://cdn.jsdelivr.net/angular.charts/0.2.0/angular-charts.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Device motion experiment - Script Codes CSS Codes
.chart { width:100%; height: 200px;
}
Device motion experiment - Script Codes JS Codes
var app = angular.module('app', ['angularCharts']);
app.controller('MyCtrl', function($scope, $interval) { $scope.deviceMotion = window.DeviceMotionEvent?true:false; $scope.points = { ac:[], acig:[] }; function resetMaxValues() { $scope.maxAccel = {x:0,y:0,z:0}; $scope.maxAccelWithGravity = {x:0,y:0,z:0}; } resetMaxValues(); var _x = 0; $interval(function() { $scope.points.ac.push( { x:(_x++), y:[$scope.maxAccel.x, $scope.maxAccel.y, $scope.maxAccel.z ] }); $scope.points.acig.push( { x:_x, y:[$scope.maxAccelWithGravity.x, $scope.maxAccelWithGravity.y, $scope.maxAccelWithGravity.z]}); if($scope.points.ac.length > 5) { $scope.points.ac.splice(0,1); $scope.points.acig.splice(0,1); } resetMaxValues(); }, 1000) function deviceMotionHandler(evt) { $scope.$apply(function() { // console.log(evt); $scope.evt = evt; $scope.maxAccel.x = Math.max($scope.maxAccel.x, evt.acceleration.x); $scope.maxAccel.y = Math.max($scope.maxAccel.y, evt.acceleration.y); $scope.maxAccel.z = Math.max($scope.maxAccel.z, evt.acceleration.z); $scope.maxAccelWithGravity.x = Math.max ($scope.maxAccelWithGravity.x, evt.accelerationIncludingGravity.x); $scope.maxAccelWithGravity.y = Math.max ($scope.maxAccelWithGravity.y, evt.accelerationIncludingGravity.y); $scope.maxAccelWithGravity.z= Math.max ($scope.maxAccelWithGravity.z, evt.accelerationIncludingGravity.z); }); }; if (window.DeviceMotionEvent) { window.addEventListener("devicemotion", deviceMotionHandler); } $scope.config = { title: 'Acceleration', tooltips: true, // labels: true, legend: {display: true, position: 'left', htmlEnabled: true}, lineLegend: 'lineEnd', isAnimate: false }; $scope.configInclG = { title: 'Acceleration including gravity', tooltips: true, // labels: true, legend: {display: true, position: 'left', htmlEnabled: true}, lineLegend: 'lineEnd', isAnimate: true }; $scope.ad = { series: ['X', 'Y', 'Z', 'Xgrav', 'Ygrav', 'Zgrav'], data: $scope.points.ac }; $scope.adig = { series: ['Xgrav', 'Ygrav', 'Zgrav'], data: $scope.points.acig };
});
Developer | Edward R Haase |
Username | ehaase |
Uploaded | January 13, 2023 |
Rating | 3 |
Size | 3,106 Kb |
Views | 6,072 |
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 |
OMDB Async Typeahead search with Angular | 2,360 Kb |
AngularJS Animated Todo List | 2,975 Kb |
Breakout Clone | 3,170 Kb |
AngularJS search filter examples | 2,325 Kb |
Angular Accordian Demo | 2,175 Kb |
AngularJS routing demo | 2,821 Kb |
BST in flat array | 2,290 Kb |
Font awesome toggle button with Angular | 2,327 Kb |
Sortable panels with Angular | 2,840 Kb |
OMDB Formatting with Angular | 2,923 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 |
Subtle site navigation with description | Necks | 3,206 Kb |
Z-index demo | Kblh | 1,534 Kb |
Scroll to view if element partially out of view port height | ChrisMaki | 2,104 Kb |
NgEasyModal | Lorenzodianni | 4,159 Kb |
Prism | Pyrografix | 2,843 Kb |
Rainbow Drops | Csbarnes | 2,365 Kb |
Intake Form Page 2 | Ijantje | 4,983 Kb |
CSS3 Button Examples | Volusion | 3,377 Kb |
Fullscreen Parallax | Bassta | 3,313 Kb |
Horizontal Navigation with Floats | Gymratpacks | 5,403 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!