incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [17/50] [abbrv] Merging+Moving Windows7 specifics
Date Wed, 17 Oct 2012 23:27:00 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/www/accel_game.html
----------------------------------------------------------------------
diff --git a/windows7/Cordova/www/accel_game.html b/windows7/Cordova/www/accel_game.html
new file mode 100644
index 0000000..e11fa7b
--- /dev/null
+++ b/windows7/Cordova/www/accel_game.html
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML>
+<html>
+	<head>
+		<title>Accelerometer Game</title>
+		<script type='text/javascript' charset='utf-8' src='cordova.win7.js'></script>
+		<script src='accel_game.js'></script>
+		<link rel='stylesheet' href='accel_game.css' />
+	</head>
+	<body>
+		<h1>Accelerometer Game</h1>
+		
+		<div id='box'>
+				<canvas id='game_area' width='500' height='500'>
+				HTML Canvas unsupported!
+				</canvas>
+		</div>
+		
+		<div id='valueX'></div>
+		<div id='valueY'></div>
+		<div id='valueZ'></div>
+		
+		<div id='valueL'></div>
+		<div id='valueR'></div>
+		<div id='valueU'></div>
+		<div id='valueD'></div>
+	</body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/www/accel_game.js
----------------------------------------------------------------------
diff --git a/windows7/Cordova/www/accel_game.js b/windows7/Cordova/www/accel_game.js
new file mode 100644
index 0000000..633d4cb
--- /dev/null
+++ b/windows7/Cordova/www/accel_game.js
@@ -0,0 +1,165 @@
+document.addEventListener('deviceready', onDeviceReady, false);
+
+// Values read from the accelerometer
+var valueX;
+var valueY;
+var valueZ;
+    		
+// Game variables
+var x_speed=0;
+var y_speed=0;
+var y=250;
+var x=250;
+var left=false;
+var right=false;
+var up=false;
+var down=false;
+var friction = 0.95;
+var context;
+ 
+// Bind vars & start acquisition
+
+function onDeviceReady() {
+	
+	valueX = document.getElementById('valueX');
+	valueY = document.getElementById('valueY');
+	valueZ = document.getElementById('valueZ');
+
+	left = document.getElementById('valueL');
+	right = document.getElementById('valueR');
+	up = document.getElementById('valueU');
+	down = document.getElementById('valueD');
+		    		
+	startWatch();
+}
+    		
+function startWatch() {
+
+	var options = { frequency: 50 }; 
+		    		
+	// Start machinery
+	navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
+}
+			
+		
+// Got sample
+		
+function onSuccess(acceleration) {
+			
+	valueX.innerHTML = 'X: ' + acceleration.x;
+	valueY.innerHTML = 'Y: ' + acceleration.y;
+	valueZ.innerHTML = 'Z: ' + acceleration.z;
+			
+	if (acceleration.x < -0.2) {
+		right = false;
+		left = true;
+	}
+		
+	else if (acceleration.x > 0.2) {
+		right = true;
+		left = false;
+	}
+			
+	else if (acceleration.x < 0.2 && acceleration.x > -0.2) {
+		left = true;
+		right = true;
+	}
+				
+	if (acceleration.y < -0.2) {
+		up = false;
+		down = true;
+	}
+			
+	else if (acceleration.y > 0.2) {
+		up = true;
+		down = false;
+	}
+			
+	else if(acceleration.y < 0.2 && acceleration.y > -0.2) {
+		up = true;
+		down = true;
+	}
+				
+	valueR.innerHTML = 'Right :' + right;
+	valueL.innerHTML = 'Left :' + left;
+	valueU.innerHTML = 'Up :' + up;
+	valueD.innerHTML = 'Down :' + down;
+}
+
+// Trouble acquiring samples
+function onError() {
+	alert('Error!');
+}
+
+function on_enter_frame() {
+
+    if (left) {
+        x_speed--;
+    }
+
+    if (right) {
+        x_speed++;
+    }
+
+    if (up) {
+        y_speed--;
+    }
+
+    if (down) {
+        y_speed++;
+    }
+
+    context.clearRect(0, 0, 500, 500); // Redraw
+    context.beginPath();
+    context.fillStyle = '#000000';
+    context.arc(x, y, 30, 0, Math.PI * 2, true);
+    context.closePath();
+    context.fill();
+
+    x += (x_speed / 3); // Compute new X for ball 
+
+    // X clipping
+    if (x > (game_area.width - 30)) {
+        x = game_area.width - 30;
+    }
+  
+    if (x < 30) {
+        x = 30;
+    }
+
+    y += (y_speed / 3); // Compute new Y for ball
+
+    // Y clipping
+    if (y > (game_area.height - 30)) {
+        y = game_area.height - 30;
+    }
+ 
+    if (y < 30) {
+        y = 30;
+    }
+
+    // Reduce speed as a way to simulate friction
+    x_speed *= friction;
+    y_speed *= friction;
+}	
+
+			
+window.onload = function()
+{	
+	var game_area = document.getElementById('game_area'); // Get access to the canvas
+    
+    if (!game_area) {
+        alert("Can't connect to canvas!");
+        return;
+    }	
+        	
+    context = game_area.getContext('2d'); // Get canvas context
+
+	if (!context) {
+		alert("Can't get canvas context!");
+		return;
+	}
+			
+	setInterval(on_enter_frame, 20); // Frame interval
+}	
+

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/www/capture.html
----------------------------------------------------------------------
diff --git a/windows7/Cordova/www/capture.html b/windows7/Cordova/www/capture.html
new file mode 100644
index 0000000..fe11f49
--- /dev/null
+++ b/windows7/Cordova/www/capture.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<title>Video & Photo Recording Test</title>
+    
+        <script type='text/javascript' charset='utf-8' src='cordova.win7.js'></script>
+    
+        <script language='javascript'>
+            function got_video(media_array) {
+                var video = document.getElementById('video');
+                video.src = media_array[0].fullPath;
+            }
+            function got_photo(media_array) {
+                var photo = document.getElementById('photo');
+                photo.src = media_array[0].fullPath;
+            }
+            function get_video() {
+                navigator.device.capture.captureVideo(got_video);
+		    }
+		    function get_photo() {
+		        navigator.device.capture.captureImage(got_photo);
+		    }
+         </script>
+	</head>
+	<body>
+        <input type='button' onclick='get_video()' value='Get Video'/> 
+        <video width=640 controls='controls' id='video'>
+        <source src='' type='video/mp4'/>
+        </video>
+        <br>
+        <input type='button' onclick='get_photo()' value='Get Photo'/> 
+        <img src='' id='photo' width=640/>
+    </body>
+</html>


Mime
View raw message