Device motion experiment

Size
3,106 Kb
Views
6,072

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 Previews

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 };
});
Device motion experiment - Script Codes
Device motion experiment - Script Codes
Home Page Home
Developer Edward R Haase
Username ehaase
Uploaded January 13, 2023
Rating 3
Size 3,106 Kb
Views 6,072
Do you need developer help for Device motion experiment?

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!

Edward R Haase (ehaase) Script Codes
Create amazing sales emails with AI!

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!