@@ -526,6 +526,55 @@ <h2 id="installation" class="lang" data-en="Installation and Getting Started" da
526
526
}
527
527
528
528
typeMainCommands ( ) ;
529
+
530
+ // Check if DeviceMotion is supported
531
+ if ( window . DeviceMotionEvent ) {
532
+ console . log ( "DeviceMotion is supported on this device." ) ;
533
+
534
+ // Add an event listener for device motion
535
+ window . addEventListener ( 'devicemotion' , function ( event ) {
536
+ const acceleration = event . accelerationIncludingGravity ;
537
+
538
+ if ( acceleration ) {
539
+ const x = acceleration . x || 0 ;
540
+ const y = acceleration . y || 0 ;
541
+ const z = acceleration . z || 0 ;
542
+
543
+ // Normalize the acceleration values
544
+ const red = Math . min ( Math . abs ( x * 20 ) , 255 ) ;
545
+ const green = Math . min ( Math . abs ( y * 20 ) , 255 ) ;
546
+ const blue = Math . min ( Math . abs ( z * 20 ) , 255 ) ;
547
+
548
+ // Create a dynamic RGB color
549
+ const backgroundColor = `rgb(${ Math . floor ( red ) } , ${ Math . floor ( green ) } , ${ Math . floor ( blue ) } )` ;
550
+
551
+ // Apply the color to the website background
552
+ document . body . style . backgroundColor = backgroundColor ;
553
+
554
+ // Optionally, display the RGB values on the page
555
+ if ( ! document . getElementById ( 'motionInfo' ) ) {
556
+ const infoDiv = document . createElement ( 'div' ) ;
557
+ infoDiv . id = 'motionInfo' ;
558
+ infoDiv . style . position = 'fixed' ;
559
+ infoDiv . style . bottom = '10px' ;
560
+ infoDiv . style . left = '10px' ;
561
+ infoDiv . style . padding = '5px' ;
562
+ infoDiv . style . backgroundColor = 'rgba(255, 255, 255, 0.7)' ;
563
+ infoDiv . style . borderRadius = '5px' ;
564
+ infoDiv . style . fontFamily = 'Arial, sans-serif' ;
565
+ infoDiv . style . color = '#000' ;
566
+ document . body . appendChild ( infoDiv ) ;
567
+ }
568
+
569
+ const infoDiv = document . getElementById ( 'motionInfo' ) ;
570
+ infoDiv . textContent = `R: ${ Math . floor ( red ) } G: ${ Math . floor ( green ) } B: ${ Math . floor ( blue ) } ` ;
571
+ }
572
+ } ) ;
573
+ } else {
574
+ console . log ( "DeviceMotion is not supported on this device." ) ;
575
+ alert ( "Your device does not support DeviceMotion." ) ;
576
+ }
577
+
529
578
</ script >
530
579
</ body >
531
580
</ html >
0 commit comments